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

Method setSocket

lib/websocket.js:213–259  ·  view source on GitHub ↗

* Set up the socket and the internal resources. * * @param {Duplex} socket The network socket between the server and client * @param {Buffer} head The first packet of the upgraded stream * @param {Object} options Options object * @param {Boolean} [options.allowSynchronousEvents=false]

(socket, head, options)

Source from the content-addressed store, hash-verified

211 * @private
212 */
213 setSocket(socket, head, options) {
214 const receiver = new Receiver({
215 allowSynchronousEvents: options.allowSynchronousEvents,
216 binaryType: this.binaryType,
217 extensions: this._extensions,
218 isServer: this._isServer,
219 maxBufferedChunks: options.maxBufferedChunks,
220 maxFragments: options.maxFragments,
221 maxPayload: options.maxPayload,
222 skipUTF8Validation: options.skipUTF8Validation
223 });
224
225 const sender = new Sender(socket, this._extensions, options.generateMask);
226
227 this._receiver = receiver;
228 this._sender = sender;
229 this._socket = socket;
230
231 receiver[kWebSocket] = this;
232 sender[kWebSocket] = this;
233 socket[kWebSocket] = this;
234
235 receiver.on('conclude', receiverOnConclude);
236 receiver.on('drain', receiverOnDrain);
237 receiver.on('error', receiverOnError);
238 receiver.on('message', receiverOnMessage);
239 receiver.on('ping', receiverOnPing);
240 receiver.on('pong', receiverOnPong);
241
242 sender.onerror = senderOnError;
243
244 //
245 // These methods may not be available if `socket` is just a `Duplex`.
246 //
247 if (socket.setTimeout) socket.setTimeout(0);
248 if (socket.setNoDelay) socket.setNoDelay();
249
250 if (head.length > 0) socket.unshift(head);
251
252 socket.on('close', socketOnClose);
253 socket.on('data', socketOnData);
254 socket.on('end', socketOnEnd);
255 socket.on('error', socketOnError);
256
257 this._readyState = WebSocket.OPEN;
258 this.emit('open');
259 }
260
261 /**
262 * Emit the `'close'` event.

Callers 2

completeUpgradeMethod · 0.95
initAsClientFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected