UNPKG

@sevenqi/nodechannel

Version:
59 lines 2.65 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.WebSocketServer = void 0; var appServer_1 = require("../../appServer"); var webSocketClient_1 = require("./webSocketClient"); var webSocketChannel_1 = require("./webSocketChannel"); var ws_1 = require("ws"); var webSocketDuplex_1 = require("../webSocketDuplex"); var WebSocketServer = /** @class */ (function (_super) { __extends(WebSocketServer, _super); function WebSocketServer(option, filter) { var _this = _super.call(this, webSocketClient_1.WebSocketClient, webSocketChannel_1.WebSocketChannel) || this; _this.option = option; _this.filter = filter; return _this; } WebSocketServer.prototype.error = function (error) { var _a; console.log(error.message); (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close(); }; WebSocketServer.prototype.listen = function () { var _this = this; this.socket = new ws_1.WebSocketServer(this.option); this.socket.on("connection", function (socket, request) { _this.connection(new webSocketDuplex_1.WebSocketDuplex(socket), new _this.filter()); }); // this.tcp.on("ready",this.onData) // this.tcp.on("timeout",this.onData) // this.tcp.on("end",this.onData) // this.tcp.on("close",this.onData) // this.tcp.on("data",this.onData.bind(this)) this.socket.on("error", this.error.bind(this)); // this.tcp.on("lookup",this.onData) // this.tcp.on("drain",this.onData) }; WebSocketServer.prototype.disListen = function () { var _a; (_a = this.socket) === null || _a === void 0 ? void 0 : _a.close(); }; return WebSocketServer; }(appServer_1.BaseAppServer)); exports.WebSocketServer = WebSocketServer; //# sourceMappingURL=webSocketServer.js.map