MCPcopy Index your code
hub / github.com/socketio/socket.io / constructor

Method constructor

lib/socket.ts:251–287  ·  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

249 * @package
250 */
251 constructor(
252 readonly nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>,
253 readonly client: Client<ListenEvents, EmitEvents, ServerSideEvents>,
254 auth: Record<string, unknown>,
255 previousSession?: Session
256 ) {
257 super();
258 this.server = nsp.server;
259 this.adapter = this.nsp.adapter;
260 if (previousSession) {
261 this.id = previousSession.sid;
262 this.pid = previousSession.pid;
263 previousSession.rooms.forEach((room) => this.join(room));
264 this.data = previousSession.data as SocketData;
265 previousSession.missedPackets.forEach((packet) => {
266 this.packet({
267 type: PacketType.EVENT,
268 data: packet,
269 });
270 });
271 this.recovered = true;
272 } else {
273 if (client.conn.protocol === 3) {
274 // @ts-ignore
275 this.id = nsp.name !== "/" ? nsp.name + "#" + client.id : client.id;
276 } else {
277 this.id = base64id.generateId(); // don't reuse the Engine.IO id because it's sensitive information
278 }
279 if (this.server._opts.connectionStateRecovery) {
280 this.pid = base64id.generateId();
281 }
282 }
283 this.handshake = this.buildHandshake(auth);
284
285 // prevents crash when the socket receives an "error" event without listener
286 this.on("error", noop);
287 }
288
289 /**
290 * 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