MCPcopy
hub / github.com/socketio/socket.io / init

Method init

packages/engine.io/lib/server.ts:715–747  ·  view source on GitHub ↗

* Initialize websocket server * * @protected

()

Source from the content-addressed store, hash-verified

713 * @protected
714 */
715 protected init() {
716 if (!~this.opts.transports.indexOf("websocket")) return;
717
718 if (this.ws) this.ws.close();
719
720 this.ws = new this.opts.wsEngine({
721 noServer: true,
722 clientTracking: false,
723 perMessageDeflate: this.opts.perMessageDeflate,
724 maxPayload: this.opts.maxHttpBufferSize,
725 });
726
727 if (typeof this.ws.on === "function") {
728 this.ws.on("headers", (headersArray, req: EngineRequest) => {
729 // note: 'ws' uses an array of headers, while Engine.IO uses an object (response.writeHead() accepts both formats)
730 // we could also try to parse the array and then sync the values, but that will be error-prone
731 const additionalHeaders = req[kResponseHeaders] || {};
732 delete req[kResponseHeaders];
733
734 const isInitialRequest = !req._query.sid;
735 if (isInitialRequest) {
736 this.emit("initial_headers", additionalHeaders, req);
737 }
738
739 this.emit("headers", additionalHeaders, req);
740
741 debug("writing headers: %j", additionalHeaders);
742 Object.keys(additionalHeaders).forEach((key) => {
743 headersArray.push(`${key}: ${additionalHeaders[key]}`);
744 });
745 });
746 }
747 }
748
749 protected cleanup() {
750 if (this.ws) {

Callers 3

constructorFunction · 0.45
constructorMethod · 0.45
app.e2e-spec.tsFile · 0.45

Calls 5

debugFunction · 0.85
keysMethod · 0.80
emitMethod · 0.65
closeMethod · 0.45
onMethod · 0.45

Tested by

no test coverage detected