MCPcopy Index your code
hub / github.com/websockets/ws / constructor

Method constructor

lib/websocket-server.js:66–142  ·  view source on GitHub ↗

* Create a `WebSocketServer` instance. * * @param {Object} options Configuration options * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted * multiple times in the same tick * @pa

(options, callback)

Source from the content-addressed store, hash-verified

64 * @param {Function} [callback] A listener for the `listening` event
65 */
66 constructor(options, callback) {
67 super();
68
69 options = {
70 allowSynchronousEvents: true,
71 autoPong: true,
72 maxBufferedChunks: 1024 * 1024,
73 maxFragments: 128 * 1024,
74 maxPayload: 100 * 1024 * 1024,
75 skipUTF8Validation: false,
76 perMessageDeflate: false,
77 handleProtocols: null,
78 clientTracking: true,
79 closeTimeout: CLOSE_TIMEOUT,
80 verifyClient: null,
81 noServer: false,
82 backlog: null, // use default (511 as implemented in net.js)
83 server: null,
84 host: null,
85 path: null,
86 port: null,
87 WebSocket,
88 ...options
89 };
90
91 if (
92 (options.port == null && !options.server && !options.noServer) ||
93 (options.port != null && (options.server || options.noServer)) ||
94 (options.server && options.noServer)
95 ) {
96 throw new TypeError(
97 'One and only one of the "port", "server", or "noServer" options ' +
98 'must be specified'
99 );
100 }
101
102 if (options.port != null) {
103 this._server = http.createServer((req, res) => {
104 const body = http.STATUS_CODES[426];
105
106 res.writeHead(426, {
107 'Content-Length': body.length,
108 'Content-Type': 'text/plain'
109 });
110 res.end(body);
111 });
112 this._server.listen(
113 options.port,
114 options.host,
115 options.backlog,
116 callback
117 );
118 } else if (options.server) {
119 this._server = options.server;
120 }
121
122 if (this._server) {
123 const emitConnection = this.emit.bind(this, 'connection');

Callers

nothing calls this directly

Calls 2

handleUpgradeMethod · 0.95
addListenersFunction · 0.85

Tested by

no test coverage detected