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

Method constructor

packages/socket.io/lib/socket.ts:158–194  ·  view source on GitHub ↗

* Interface to a `Client` for a given `Namespace`. * * @param {Namespace} nsp * @param {Client} client * @param {Object} auth * @package

(
    readonly nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>,
    readonly client: Client<ListenEvents, EmitEvents, ServerSideEvents>,
    auth: Record<string, unknown>,
    previousSession?: Session,
  )

Source from the content-addressed store, hash-verified

156 * @package
157 */
158 constructor(
159 readonly nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>,
160 readonly client: Client<ListenEvents, EmitEvents, ServerSideEvents>,
161 auth: Record<string, unknown>,
162 previousSession?: Session,
163 ) {
164 super();
165 this.server = nsp.server;
166 this.adapter = nsp.adapter;
167 if (previousSession) {
168 this.id = previousSession.sid;
169 this.pid = previousSession.pid;
170 previousSession.rooms.forEach((room) => this.join(room));
171 this.data = previousSession.data as SocketData;
172 previousSession.missedPackets.forEach((packet) => {
173 this.packet({
174 type: PacketType.EVENT,
175 data: packet,
176 });
177 });
178 this.recovered = true;
179 } else {
180 if (client.conn.protocol === 3) {
181 // @ts-ignore
182 this.id = nsp.name !== "/" ? nsp.name + "#" + client.id : client.id;
183 } else {
184 this.id = base64id.generateId(); // don't reuse the Engine.IO id because it's sensitive information
185 }
186 if (this.server._opts.connectionStateRecovery) {
187 this.pid = base64id.generateId();
188 }
189 }
190 this.handshake = this.buildHandshake(auth);
191
192 // prevents crash when the socket receives an "error" event without listener
193 this.on("error", noop);
194 }
195
196 /**
197 * Builds the `handshake` BC object

Callers

nothing calls this directly

Calls 4

joinMethod · 0.95
packetMethod · 0.95
buildHandshakeMethod · 0.95
onMethod · 0.45

Tested by

no test coverage detected