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

Class Socket

packages/socket.io-client/lib/socket.ts:147–1147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145 * });
146 */
147export class Socket<
148 ListenEvents extends EventsMap = DefaultEventsMap,
149 EmitEvents extends EventsMap = ListenEvents,
150> extends Emitter<ListenEvents, EmitEvents, SocketReservedEvents> {
151 public readonly io: Manager<ListenEvents, EmitEvents>;
152
153 /**
154 * A unique identifier for the session. `undefined` when the socket is not connected.
155 *
156 * @example
157 * const socket = io();
158 *
159 * console.log(socket.id); // undefined
160 *
161 * socket.on("connect", () => {
162 * console.log(socket.id); // "G5p5..."
163 * });
164 */
165 public id: string | undefined;
166
167 /**
168 * The session ID used for connection state recovery, which must not be shared (unlike {@link id}).
169 *
170 * @private
171 */
172 private _pid: string;
173
174 /**
175 * The offset of the last received packet, which will be sent upon reconnection to allow for the recovery of the connection state.
176 *
177 * @private
178 */
179 private _lastOffset: string;
180
181 /**
182 * Whether the socket is currently connected to the server.
183 *
184 * @example
185 * const socket = io();
186 *
187 * socket.on("connect", () => {
188 * console.log(socket.connected); // true
189 * });
190 *
191 * socket.on("disconnect", () => {
192 * console.log(socket.connected); // false
193 * });
194 */
195 public connected: boolean = false;
196 /**
197 * Whether the connection state was recovered after a temporary disconnection. In that case, any missed packets will
198 * be transmitted by the server.
199 */
200 public recovered: boolean = false;
201 /**
202 * Credentials that are sent when accessing a namespace.
203 *
204 * @example

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…