Changeset e29cc2e for trip-planner-front/node_modules/socket.io/dist
- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- Location:
- trip-planner-front/node_modules/socket.io/dist
- Files:
-
- 6 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/socket.io/dist/client.d.ts
r59329aa re29cc2e 3 3 import type { IncomingMessage } from "http"; 4 4 import type { Server } from "./index"; 5 import type { EventsMap } from "./typed-events"; 5 6 import type { Socket } from "./socket"; 6 export declare class Client { 7 readonly conn: any; 7 import type { Socket as RawSocket } from "engine.io"; 8 interface WriteOptions { 9 compress?: boolean; 10 volatile?: boolean; 11 preEncoded?: boolean; 12 wsPreEncoded?: string; 13 } 14 export declare class Client<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap, SocketData = any> { 15 readonly conn: RawSocket; 8 16 private readonly id; 9 17 private readonly server; … … 20 28 * @package 21 29 */ 22 constructor(server: Server , conn: Socket);30 constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, conn: any); 23 31 /** 24 32 * @return the reference to the request that originated the Engine.IO connection … … 61 69 * @private 62 70 */ 63 _remove(socket: Socket ): void;71 _remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>): void; 64 72 /** 65 73 * Closes the underlying connection. … … 75 83 * @private 76 84 */ 77 _packet(packet: Packet, opts?: any): void; 85 _packet(packet: Packet | any[], opts?: WriteOptions): void; 86 private writeToEngine; 78 87 /** 79 88 * Called with incoming transport data. … … 108 117 private destroy; 109 118 } 119 export {}; -
trip-planner-front/node_modules/socket.io/dist/client.js
r59329aa re29cc2e 71 71 this.server._checkNamespace(name, auth, (dynamicNspName) => { 72 72 if (dynamicNspName) { 73 debug("dynamic namespace %s was created", dynamicNspName);74 73 this.doConnect(name, auth); 75 74 } … … 151 150 * @private 152 151 */ 153 _packet(packet, opts) { 154 opts = opts || {}; 155 const self = this; 156 // this writes to the actual connection 157 function writeToEngine(encodedPackets) { 158 // TODO clarify this. 159 if (opts.volatile && !self.conn.transport.writable) 160 return; 161 for (let i = 0; i < encodedPackets.length; i++) { 162 self.conn.write(encodedPackets[i], { compress: opts.compress }); 163 } 164 } 165 if ("open" === this.conn.readyState) { 166 debug("writing packet %j", packet); 167 if (!opts.preEncoded) { 168 // not broadcasting, need to encode 169 writeToEngine(this.encoder.encode(packet)); // encode, then write results to engine 170 } 171 else { 172 // a broadcast pre-encodes a packet 173 writeToEngine(packet); 174 } 175 } 176 else { 152 _packet(packet, opts = {}) { 153 if (this.conn.readyState !== "open") { 177 154 debug("ignoring packet write %j", packet); 155 return; 156 } 157 const encodedPackets = opts.preEncoded 158 ? packet // previous versions of the adapter incorrectly used socket.packet() instead of writeToEngine() 159 : this.encoder.encode(packet); 160 this.writeToEngine(encodedPackets, opts); 161 } 162 writeToEngine(encodedPackets, opts) { 163 if (opts.volatile && !this.conn.transport.writable) { 164 debug("volatile packet is discarded since the transport is not currently writable"); 165 return; 166 } 167 const packets = Array.isArray(encodedPackets) 168 ? encodedPackets 169 : [encodedPackets]; 170 for (const encodedPacket of packets) { 171 this.conn.write(encodedPacket, opts); 178 172 } 179 173 } -
trip-planner-front/node_modules/socket.io/dist/index.d.ts
r59329aa re29cc2e 1 1 /// <reference types="node" /> 2 2 import http = require("http"); 3 import { EventEmitter } from "events";4 import { ExtendedError, Namespace } from "./namespace";3 import { ServerOptions as EngineOptions, AttachOptions } from "engine.io"; 4 import { ExtendedError, Namespace, ServerReservedEventsMap } from "./namespace"; 5 5 import { Adapter, Room, SocketId } from "socket.io-adapter"; 6 6 import * as parser from "socket.io-parser"; 7 7 import type { Encoder } from "socket.io-parser"; 8 8 import { Socket } from "./socket"; 9 import type { CookieSerializeOptions } from "cookie"; 10 import type { CorsOptions } from "cors"; 11 declare type Transport = "polling" | "websocket"; 9 import type { BroadcastOperator, RemoteSocket } from "./broadcast-operator"; 10 import { EventsMap, DefaultEventsMap, EventParams, StrictEventEmitter, EventNames } from "./typed-events"; 12 11 declare type ParentNspNameMatchFn = (name: string, auth: { 13 12 [key: string]: any; 14 13 }, fn: (err: Error | null, success: boolean) => void) => void; 15 interface EngineOptions { 16 /** 17 * how many ms without a pong packet to consider the connection closed 18 * @default 5000 19 */ 20 pingTimeout: number; 21 /** 22 * how many ms before sending a new ping packet 23 * @default 25000 24 */ 25 pingInterval: number; 26 /** 27 * how many ms before an uncompleted transport upgrade is cancelled 28 * @default 10000 29 */ 30 upgradeTimeout: number; 31 /** 32 * how many bytes or characters a message can be, before closing the session (to avoid DoS). 33 * @default 1e5 (100 KB) 34 */ 35 maxHttpBufferSize: number; 36 /** 37 * A function that receives a given handshake or upgrade request as its first parameter, 38 * and can decide whether to continue or not. The second argument is a function that needs 39 * to be called with the decided information: fn(err, success), where success is a boolean 40 * value where false means that the request is rejected, and err is an error code. 41 */ 42 allowRequest: (req: http.IncomingMessage, fn: (err: string | null | undefined, success: boolean) => void) => void; 43 /** 44 * the low-level transports that are enabled 45 * @default ["polling", "websocket"] 46 */ 47 transports: Transport[]; 48 /** 49 * whether to allow transport upgrades 50 * @default true 51 */ 52 allowUpgrades: boolean; 53 /** 54 * parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable. 55 * @default false 56 */ 57 perMessageDeflate: boolean | object; 58 /** 59 * parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable. 60 * @default true 61 */ 62 httpCompression: boolean | object; 63 /** 64 * what WebSocket server implementation to use. Specified module must 65 * conform to the ws interface (see ws module api docs). Default value is ws. 66 * An alternative c++ addon is also available by installing uws module. 67 */ 68 wsEngine: string; 69 /** 70 * an optional packet which will be concatenated to the handshake packet emitted by Engine.IO. 71 */ 72 initialPacket: any; 73 /** 74 * configuration of the cookie that contains the client sid to send as part of handshake response headers. This cookie 75 * might be used for sticky-session. Defaults to not sending any cookie. 76 * @default false 77 */ 78 cookie: CookieSerializeOptions | boolean; 79 /** 80 * the options that will be forwarded to the cors module 81 */ 82 cors: CorsOptions; 83 /** 84 * whether to enable compatibility with Socket.IO v2 clients 85 * @default false 86 */ 87 allowEIO3: boolean; 88 } 89 interface AttachOptions { 90 /** 91 * name of the path to capture 92 * @default "/engine.io" 93 */ 94 path: string; 95 /** 96 * destroy unhandled upgrade requests 97 * @default true 98 */ 99 destroyUpgrade: boolean; 100 /** 101 * milliseconds after which unhandled requests are ended 102 * @default 1000 103 */ 104 destroyUpgradeTimeout: number; 105 } 106 interface EngineAttachOptions extends EngineOptions, AttachOptions { 107 } 108 interface ServerOptions extends EngineAttachOptions { 14 declare type AdapterConstructor = typeof Adapter | ((nsp: Namespace) => Adapter); 15 interface ServerOptions extends EngineOptions, AttachOptions { 109 16 /** 110 17 * name of the path to capture … … 121 28 * @default the in-memory adapter (https://github.com/socketio/socket.io-adapter) 122 29 */ 123 adapter: any;30 adapter: AdapterConstructor; 124 31 /** 125 32 * the parser to use … … 133 40 connectTimeout: number; 134 41 } 135 export declare class Server extends EventEmitter { 136 readonly sockets: Namespace; 42 export declare class Server<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends StrictEventEmitter<ServerSideEvents, EmitEvents, ServerReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData>> { 43 readonly sockets: Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>; 44 /** 45 * A reference to the underlying Engine.IO server. 46 * 47 * Example: 48 * 49 * <code> 50 * const clientsCount = io.engine.clientsCount; 51 * </code> 52 * 53 */ 54 engine: any; 137 55 /** @private */ 138 56 readonly _parser: typeof parser; … … 142 60 * @private 143 61 */ 144 _nsps: Map<string, Namespace >;62 _nsps: Map<string, Namespace<ListenEvents, EmitEvents, ServerSideEvents>>; 145 63 private parentNsps; 146 64 private _adapter?; … … 148 66 private opts; 149 67 private eio; 150 private engine;151 68 private _path; 152 69 private clientPathRegex; … … 187 104 _checkNamespace(name: string, auth: { 188 105 [key: string]: any; 189 }, fn: (nsp: Namespace | false) => void): void;106 }, fn: (nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents> | false) => void): void; 190 107 /** 191 108 * Sets the client serving path. … … 213 130 * @public 214 131 */ 215 adapter(): typeof Adapter | undefined; 216 adapter(v: typeof Adapter): this; 217 adapter(v?: typeof Adapter): typeof Adapter | undefined | this; 132 adapter(): AdapterConstructor | undefined; 133 adapter(v: AdapterConstructor): this; 218 134 /** 219 135 * Attaches socket.io to a server or port. … … 234 150 */ 235 151 attach(srv: http.Server | number, opts?: Partial<ServerOptions>): this; 152 attachApp(app: any, opts?: Partial<ServerOptions>): void; 236 153 /** 237 154 * Initialize engine … … 287 204 * @public 288 205 */ 289 of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: Socket ) => void): Namespace;206 of(name: string | RegExp | ParentNspNameMatchFn, fn?: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void): Namespace<ListenEvents, EmitEvents, ServerSideEvents>; 290 207 /** 291 208 * Closes server connection … … 301 218 * @public 302 219 */ 303 use(fn: (socket: Socket , next: (err?: ExtendedError) => void) => void): this;220 use(fn: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, next: (err?: ExtendedError) => void) => void): this; 304 221 /** 305 222 * Targets a room when emitting. 306 223 * 224 * @param room 225 * @return self 226 * @public 227 */ 228 to(room: Room | Room[]): BroadcastOperator<EmitEvents>; 229 /** 230 * Targets a room when emitting. 231 * 232 * @param room 233 * @return self 234 * @public 235 */ 236 in(room: Room | Room[]): BroadcastOperator<EmitEvents>; 237 /** 238 * Excludes a room when emitting. 239 * 307 240 * @param name 308 241 * @return self 309 242 * @public 310 243 */ 311 to(name: Room): this; 312 /** 313 * Targets a room when emitting. 314 * 315 * @param name 316 * @return self 317 * @public 318 */ 319 in(name: Room): this; 244 except(name: Room | Room[]): BroadcastOperator<EmitEvents>; 320 245 /** 321 246 * Sends a `message` event to all clients. … … 324 249 * @public 325 250 */ 326 send(...args: readonly any[]): this;251 send(...args: EventParams<EmitEvents, "message">): this; 327 252 /** 328 253 * Sends a `message` event to all clients. … … 331 256 * @public 332 257 */ 333 write(...args: readonly any[]): this; 258 write(...args: EventParams<EmitEvents, "message">): this; 259 /** 260 * Emit a packet to other Socket.IO servers 261 * 262 * @param ev - the event name 263 * @param args - an array of arguments, which may include an acknowledgement callback at the end 264 * @public 265 */ 266 serverSideEmit<Ev extends EventNames<ServerSideEvents>>(ev: Ev, ...args: EventParams<ServerSideEvents, Ev>): boolean; 334 267 /** 335 268 * Gets a list of socket ids. … … 345 278 * @public 346 279 */ 347 compress(compress: boolean): this;280 compress(compress: boolean): BroadcastOperator<EmitEvents>; 348 281 /** 349 282 * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to … … 354 287 * @public 355 288 */ 356 get volatile(): this;289 get volatile(): BroadcastOperator<EmitEvents>; 357 290 /** 358 291 * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node. … … 361 294 * @public 362 295 */ 363 get local(): this; 296 get local(): BroadcastOperator<EmitEvents>; 297 /** 298 * Returns the matching socket instances 299 * 300 * @public 301 */ 302 fetchSockets(): Promise<RemoteSocket<EmitEvents>[]>; 303 /** 304 * Makes the matching socket instances join the specified rooms 305 * 306 * @param room 307 * @public 308 */ 309 socketsJoin(room: Room | Room[]): void; 310 /** 311 * Makes the matching socket instances leave the specified rooms 312 * 313 * @param room 314 * @public 315 */ 316 socketsLeave(room: Room | Room[]): void; 317 /** 318 * Makes the matching socket instances disconnect 319 * 320 * @param close - whether to close the underlying connection 321 * @public 322 */ 323 disconnectSockets(close?: boolean): void; 364 324 } 365 export { Socket, ServerOptions, Namespace };325 export { Socket, ServerOptions, Namespace, BroadcastOperator, RemoteSocket }; -
trip-planner-front/node_modules/socket.io/dist/index.js
r59329aa re29cc2e 30 30 const stream_1 = require("stream"); 31 31 const path = require("path"); 32 const engine = require("engine.io");32 const engine_io_1 = require("engine.io"); 33 33 const client_1 = require("./client"); 34 34 const events_1 = require("events"); … … 41 41 const socket_1 = require("./socket"); 42 42 Object.defineProperty(exports, "Socket", { enumerable: true, get: function () { return socket_1.Socket; } }); 43 const debug = debug_1.default("socket.io:server"); 43 const typed_events_1 = require("./typed-events"); 44 const uws_js_1 = require("./uws.js"); 45 const debug = (0, debug_1.default)("socket.io:server"); 44 46 const clientVersion = require("../package.json").version; 45 47 const dotMapRegex = /\.map/; 46 class Server extends events_1.EventEmitter {48 class Server extends typed_events_1.StrictEventEmitter { 47 49 constructor(srv, opts = {}) { 48 50 super(); … … 66 68 this.sockets = this.of("/"); 67 69 this.opts = opts; 68 if (srv )70 if (srv || typeof srv == "number") 69 71 this.attach(srv); 70 72 } … … 95 97 nextFn.value(name, auth, (err, allow) => { 96 98 if (err || !allow) { 97 r un();99 return run(); 98 100 } 99 else { 100 fn(this.parentNsps.get(nextFn.value).createChild(name)); 101 if (this._nsps.has(name)) { 102 // the namespace was created in the meantime 103 debug("dynamic namespace %s already exists", name); 104 return fn(this._nsps.get(name)); 101 105 } 106 const namespace = this.parentNsps.get(nextFn.value).createChild(name); 107 debug("dynamic namespace %s was created", name); 108 // @ts-ignore 109 this.sockets.emitReserved("new_namespace", namespace); 110 fn(namespace); 102 111 }); 103 112 }; … … 111 120 this.clientPathRegex = new RegExp("^" + 112 121 escapedPath + 113 "/socket\\.io(\\.m in|\\.msgpack\\.min)?\\.js(\\.map)?$");122 "/socket\\.io(\\.msgpack|\\.esm)?(\\.min)?\\.js(\\.map)?(?:\\?|$)"); 114 123 return this; 115 124 } … … 174 183 return this; 175 184 } 185 attachApp(app /*: TemplatedApp */, opts = {}) { 186 // merge the options passed to the Socket.IO server 187 Object.assign(opts, this.opts); 188 // set engine.io path to `/socket.io` 189 opts.path = opts.path || this._path; 190 // initialize engine 191 debug("creating uWebSockets.js-based engine with opts %j", opts); 192 const engine = new engine_io_1.uServer(opts); 193 engine.attach(app, opts); 194 // bind to engine events 195 this.bind(engine); 196 if (this._serveClient) { 197 // attach static file serving 198 app.get(`${this._path}/*`, (res, req) => { 199 if (!this.clientPathRegex.test(req.getUrl())) { 200 req.setYield(true); 201 return; 202 } 203 const filename = req 204 .getUrl() 205 .replace(this._path, "") 206 .replace(/\?.*$/, "") 207 .replace(/^\//, ""); 208 const isMap = dotMapRegex.test(filename); 209 const type = isMap ? "map" : "source"; 210 // Per the standard, ETags must be quoted: 211 // https://tools.ietf.org/html/rfc7232#section-2.3 212 const expectedEtag = '"' + clientVersion + '"'; 213 const weakEtag = "W/" + expectedEtag; 214 const etag = req.getHeader("if-none-match"); 215 if (etag) { 216 if (expectedEtag === etag || weakEtag === etag) { 217 debug("serve client %s 304", type); 218 res.writeStatus("304 Not Modified"); 219 res.end(); 220 return; 221 } 222 } 223 debug("serve client %s", type); 224 res.writeHeader("cache-control", "public, max-age=0"); 225 res.writeHeader("content-type", "application/" + (isMap ? "json" : "javascript")); 226 res.writeHeader("etag", expectedEtag); 227 const filepath = path.join(__dirname, "../client-dist/", filename); 228 (0, uws_js_1.serveFile)(res, filepath); 229 }); 230 } 231 (0, uws_js_1.patchAdapter)(app); 232 } 176 233 /** 177 234 * Initialize engine … … 184 241 // initialize engine 185 242 debug("creating engine.io instance with opts %j", opts); 186 this.eio = engine.attach(srv, opts);243 this.eio = (0, engine_io_1.attach)(srv, opts); 187 244 // attach static file serving 188 245 if (this._serveClient) … … 222 279 */ 223 280 serve(req, res) { 224 const filename = req.url.replace(this._path, "") ;281 const filename = req.url.replace(this._path, "").replace(/\?.*$/, ""); 225 282 const isMap = dotMapRegex.test(filename); 226 283 const type = isMap ? "map" : "source"; … … 242 299 res.setHeader("Content-Type", "application/" + (isMap ? "json" : "javascript")); 243 300 res.setHeader("ETag", expectedEtag); 244 if (!isMap) {245 res.setHeader("X-SourceMap", filename.substring(1) + ".map");246 }247 301 Server.sendFile(filename, req, res); 248 302 } … … 254 308 */ 255 309 static sendFile(filename, req, res) { 256 const readStream = fs_1.createReadStream(path.join(__dirname, "../client-dist/", filename));310 const readStream = (0, fs_1.createReadStream)(path.join(__dirname, "../client-dist/", filename)); 257 311 const encoding = accepts(req).encodings(["br", "gzip", "deflate"]); 258 312 const onError = (err) => { … … 264 318 case "br": 265 319 res.writeHead(200, { "content-encoding": "br" }); 266 readStream.pipe( zlib_1.createBrotliCompress()).pipe(res);267 stream_1.pipeline(readStream, zlib_1.createBrotliCompress(), res, onError);320 readStream.pipe((0, zlib_1.createBrotliCompress)()).pipe(res); 321 (0, stream_1.pipeline)(readStream, (0, zlib_1.createBrotliCompress)(), res, onError); 268 322 break; 269 323 case "gzip": 270 324 res.writeHead(200, { "content-encoding": "gzip" }); 271 stream_1.pipeline(readStream, zlib_1.createGzip(), res, onError);325 (0, stream_1.pipeline)(readStream, (0, zlib_1.createGzip)(), res, onError); 272 326 break; 273 327 case "deflate": 274 328 res.writeHead(200, { "content-encoding": "deflate" }); 275 stream_1.pipeline(readStream, zlib_1.createDeflate(), res, onError);329 (0, stream_1.pipeline)(readStream, (0, zlib_1.createDeflate)(), res, onError); 276 330 break; 277 331 default: 278 332 res.writeHead(200); 279 stream_1.pipeline(readStream, res, onError);333 (0, stream_1.pipeline)(readStream, res, onError); 280 334 } 281 335 } … … 338 392 nsp = new namespace_1.Namespace(this, name); 339 393 this._nsps.set(name, nsp); 394 if (name !== "/") { 395 // @ts-ignore 396 this.sockets.emitReserved("new_namespace", nsp); 397 } 340 398 } 341 399 if (fn) … … 354 412 } 355 413 this.engine.close(); 414 // restore the Adapter prototype 415 (0, uws_js_1.restoreAdapter)(); 356 416 if (this.httpServer) { 357 417 this.httpServer.close(fn); … … 374 434 * Targets a room when emitting. 375 435 * 436 * @param room 437 * @return self 438 * @public 439 */ 440 to(room) { 441 return this.sockets.to(room); 442 } 443 /** 444 * Targets a room when emitting. 445 * 446 * @param room 447 * @return self 448 * @public 449 */ 450 in(room) { 451 return this.sockets.in(room); 452 } 453 /** 454 * Excludes a room when emitting. 455 * 376 456 * @param name 377 457 * @return self 378 458 * @public 379 459 */ 380 to(name) { 381 this.sockets.to(name); 382 return this; 383 } 384 /** 385 * Targets a room when emitting. 386 * 387 * @param name 388 * @return self 389 * @public 390 */ 391 in(name) { 392 this.sockets.in(name); 393 return this; 460 except(name) { 461 return this.sockets.except(name); 394 462 } 395 463 /** … … 414 482 } 415 483 /** 484 * Emit a packet to other Socket.IO servers 485 * 486 * @param ev - the event name 487 * @param args - an array of arguments, which may include an acknowledgement callback at the end 488 * @public 489 */ 490 serverSideEmit(ev, ...args) { 491 return this.sockets.serverSideEmit(ev, ...args); 492 } 493 /** 416 494 * Gets a list of socket ids. 417 495 * … … 429 507 */ 430 508 compress(compress) { 431 this.sockets.compress(compress); 432 return this; 509 return this.sockets.compress(compress); 433 510 } 434 511 /** … … 441 518 */ 442 519 get volatile() { 443 this.sockets.volatile; 444 return this; 520 return this.sockets.volatile; 445 521 } 446 522 /** … … 451 527 */ 452 528 get local() { 453 this.sockets.local; 454 return this; 529 return this.sockets.local; 530 } 531 /** 532 * Returns the matching socket instances 533 * 534 * @public 535 */ 536 fetchSockets() { 537 return this.sockets.fetchSockets(); 538 } 539 /** 540 * Makes the matching socket instances join the specified rooms 541 * 542 * @param room 543 * @public 544 */ 545 socketsJoin(room) { 546 return this.sockets.socketsJoin(room); 547 } 548 /** 549 * Makes the matching socket instances leave the specified rooms 550 * 551 * @param room 552 * @public 553 */ 554 socketsLeave(room) { 555 return this.sockets.socketsLeave(room); 556 } 557 /** 558 * Makes the matching socket instances disconnect 559 * 560 * @param close - whether to close the underlying connection 561 * @public 562 */ 563 disconnectSockets(close = false) { 564 return this.sockets.disconnectSockets(close); 455 565 } 456 566 } … … 469 579 module.exports = (srv, opts) => new Server(srv, opts); 470 580 module.exports.Server = Server; 581 module.exports.Namespace = namespace_1.Namespace; 582 module.exports.Socket = socket_1.Socket; -
trip-planner-front/node_modules/socket.io/dist/namespace.d.ts
r59329aa re29cc2e 1 /// <reference types="node" />2 1 import { Socket } from "./socket"; 3 2 import type { Server } from "./index"; 3 import { EventParams, EventNames, EventsMap, StrictEventEmitter, DefaultEventsMap } from "./typed-events"; 4 4 import type { Client } from "./client"; 5 import { EventEmitter } from "events";6 5 import type { Adapter, Room, SocketId } from "socket.io-adapter"; 6 import { BroadcastOperator, RemoteSocket } from "./broadcast-operator"; 7 7 export interface ExtendedError extends Error { 8 8 data?: any; 9 9 } 10 export declare class Namespace extends EventEmitter { 10 export interface NamespaceReservedEventsMap<ListenEvents extends EventsMap, EmitEvents extends EventsMap, ServerSideEvents extends EventsMap, SocketData> { 11 connect: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void; 12 connection: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void; 13 } 14 export interface ServerReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData> extends NamespaceReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData> { 15 new_namespace: (namespace: Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>) => void; 16 } 17 export declare const RESERVED_EVENTS: ReadonlySet<string | Symbol>; 18 export declare class Namespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends StrictEventEmitter<ServerSideEvents, EmitEvents, NamespaceReservedEventsMap<ListenEvents, EmitEvents, ServerSideEvents, SocketData>> { 11 19 readonly name: string; 12 readonly sockets: Map<SocketId, Socket >;20 readonly sockets: Map<SocketId, Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>>; 13 21 adapter: Adapter; 14 22 /** @private */ 15 readonly server: Server ;23 readonly server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>; 16 24 /** @private */ 17 _fns: Array<(socket: Socket, next: (err?: ExtendedError) => void) => void>; 18 /** @private */ 19 _rooms: Set<Room>; 20 /** @private */ 21 _flags: any; 25 _fns: Array<(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, next: (err?: ExtendedError) => void) => void>; 22 26 /** @private */ 23 27 _ids: number; … … 28 32 * @param name 29 33 */ 30 constructor(server: Server , name: string);34 constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, name: string); 31 35 /** 32 36 * Initializes the `Adapter` for this nsp. … … 43 47 * @public 44 48 */ 45 use(fn: (socket: Socket , next: (err?: ExtendedError) => void) => void): this;49 use(fn: (socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>, next: (err?: ExtendedError) => void) => void): this; 46 50 /** 47 51 * Executes the middleware for an incoming client. … … 55 59 * Targets a room when emitting. 56 60 * 57 * @param name61 * @param room 58 62 * @return self 59 63 * @public 60 64 */ 61 to( name: Room): this;65 to(room: Room | Room[]): BroadcastOperator<EmitEvents>; 62 66 /** 63 67 * Targets a room when emitting. 64 68 * 65 * @param name69 * @param room 66 70 * @return self 67 71 * @public 68 72 */ 69 in(name: Room): this; 73 in(room: Room | Room[]): BroadcastOperator<EmitEvents>; 74 /** 75 * Excludes a room when emitting. 76 * 77 * @param room 78 * @return self 79 * @public 80 */ 81 except(room: Room | Room[]): BroadcastOperator<EmitEvents>; 70 82 /** 71 83 * Adds a new client. … … 74 86 * @private 75 87 */ 76 _add(client: Client , query: any, fn?: () => void): Socket;88 _add(client: Client<ListenEvents, EmitEvents, ServerSideEvents>, query: any, fn?: () => void): Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>; 77 89 /** 78 90 * Removes a client. Called by each `Socket`. … … 80 92 * @private 81 93 */ 82 _remove(socket: Socket ): void;94 _remove(socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>): void; 83 95 /** 84 96 * Emits to all clients. … … 87 99 * @public 88 100 */ 89 emit (ev: string | Symbol, ...args: any[]): true;101 emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean; 90 102 /** 91 103 * Sends a `message` event to all clients. … … 94 106 * @public 95 107 */ 96 send(...args: readonly any[]): this;108 send(...args: EventParams<EmitEvents, "message">): this; 97 109 /** 98 110 * Sends a `message` event to all clients. … … 101 113 * @public 102 114 */ 103 write(...args: readonly any[]): this; 115 write(...args: EventParams<EmitEvents, "message">): this; 116 /** 117 * Emit a packet to other Socket.IO servers 118 * 119 * @param ev - the event name 120 * @param args - an array of arguments, which may include an acknowledgement callback at the end 121 * @public 122 */ 123 serverSideEmit<Ev extends EventNames<ServerSideEvents>>(ev: Ev, ...args: EventParams<ServerSideEvents, Ev>): boolean; 124 /** 125 * Called when a packet is received from another Socket.IO server 126 * 127 * @param args - an array of arguments, which may include an acknowledgement callback at the end 128 * 129 * @private 130 */ 131 _onServerSideEmit(args: [string, ...any[]]): void; 104 132 /** 105 133 * Gets a list of clients. … … 116 144 * @public 117 145 */ 118 compress(compress: boolean): this;146 compress(compress: boolean): BroadcastOperator<EmitEvents>; 119 147 /** 120 148 * Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to … … 125 153 * @public 126 154 */ 127 get volatile(): this;155 get volatile(): BroadcastOperator<EmitEvents>; 128 156 /** 129 157 * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node. … … 132 160 * @public 133 161 */ 134 get local(): this; 162 get local(): BroadcastOperator<EmitEvents>; 163 /** 164 * Returns the matching socket instances 165 * 166 * @public 167 */ 168 fetchSockets(): Promise<RemoteSocket<EmitEvents>[]>; 169 /** 170 * Makes the matching socket instances join the specified rooms 171 * 172 * @param room 173 * @public 174 */ 175 socketsJoin(room: Room | Room[]): void; 176 /** 177 * Makes the matching socket instances leave the specified rooms 178 * 179 * @param room 180 * @public 181 */ 182 socketsLeave(room: Room | Room[]): void; 183 /** 184 * Makes the matching socket instances disconnect 185 * 186 * @param close - whether to close the underlying connection 187 * @public 188 */ 189 disconnectSockets(close?: boolean): void; 135 190 } -
trip-planner-front/node_modules/socket.io/dist/namespace.js
r59329aa re29cc2e 4 4 }; 5 5 Object.defineProperty(exports, "__esModule", { value: true }); 6 exports.Namespace = void 0;6 exports.Namespace = exports.RESERVED_EVENTS = void 0; 7 7 const socket_1 = require("./socket"); 8 const events_1 = require("events"); 9 const socket_io_parser_1 = require("socket.io-parser"); 8 const typed_events_1 = require("./typed-events"); 10 9 const debug_1 = __importDefault(require("debug")); 11 const debug = debug_1.default("socket.io:namespace"); 12 class Namespace extends events_1.EventEmitter { 10 const broadcast_operator_1 = require("./broadcast-operator"); 11 const debug = (0, debug_1.default)("socket.io:namespace"); 12 exports.RESERVED_EVENTS = new Set(["connect", "connection", "new_namespace"]); 13 class Namespace extends typed_events_1.StrictEventEmitter { 13 14 /** 14 15 * Namespace constructor. … … 23 24 this._fns = []; 24 25 /** @private */ 25 this._rooms = new Set();26 /** @private */27 this._flags = {};28 /** @private */29 26 this._ids = 0; 30 27 this.server = server; … … 40 37 */ 41 38 _initAdapter() { 39 // @ts-ignore 42 40 this.adapter = new (this.server.adapter())(this); 43 41 } … … 80 78 * Targets a room when emitting. 81 79 * 82 * @param name 83 * @return self 84 * @public 85 */ 86 to(name) { 87 this._rooms.add(name); 88 return this; 80 * @param room 81 * @return self 82 * @public 83 */ 84 to(room) { 85 return new broadcast_operator_1.BroadcastOperator(this.adapter).to(room); 89 86 } 90 87 /** 91 88 * Targets a room when emitting. 92 89 * 93 * @param name 94 * @return self 95 * @public 96 */ 97 in(name) { 98 this._rooms.add(name); 99 return this; 90 * @param room 91 * @return self 92 * @public 93 */ 94 in(room) { 95 return new broadcast_operator_1.BroadcastOperator(this.adapter).in(room); 96 } 97 /** 98 * Excludes a room when emitting. 99 * 100 * @param room 101 * @return self 102 * @public 103 */ 104 except(room) { 105 return new broadcast_operator_1.BroadcastOperator(this.adapter).except(room); 100 106 } 101 107 /** … … 132 138 fn(); 133 139 // fire user-set events 134 super.emit("connect", socket);135 super.emit("connection", socket);140 this.emitReserved("connect", socket); 141 this.emitReserved("connection", socket); 136 142 } 137 143 else { … … 162 168 */ 163 169 emit(ev, ...args) { 164 if (socket_1.RESERVED_EVENTS.has(ev)) { 165 throw new Error(`"${ev}" is a reserved event name`); 166 } 167 // set up packet object 168 args.unshift(ev); 169 const packet = { 170 type: socket_io_parser_1.PacketType.EVENT, 171 data: args, 172 }; 173 if ("function" == typeof args[args.length - 1]) { 174 throw new Error("Callbacks are not supported when broadcasting"); 175 } 176 const rooms = new Set(this._rooms); 177 const flags = Object.assign({}, this._flags); 178 // reset flags 179 this._rooms.clear(); 180 this._flags = {}; 181 this.adapter.broadcast(packet, { 182 rooms: rooms, 183 flags: flags, 184 }); 185 return true; 170 return new broadcast_operator_1.BroadcastOperator(this.adapter).emit(ev, ...args); 186 171 } 187 172 /** … … 206 191 } 207 192 /** 193 * Emit a packet to other Socket.IO servers 194 * 195 * @param ev - the event name 196 * @param args - an array of arguments, which may include an acknowledgement callback at the end 197 * @public 198 */ 199 serverSideEmit(ev, ...args) { 200 if (exports.RESERVED_EVENTS.has(ev)) { 201 throw new Error(`"${ev}" is a reserved event name`); 202 } 203 args.unshift(ev); 204 this.adapter.serverSideEmit(args); 205 return true; 206 } 207 /** 208 * Called when a packet is received from another Socket.IO server 209 * 210 * @param args - an array of arguments, which may include an acknowledgement callback at the end 211 * 212 * @private 213 */ 214 _onServerSideEmit(args) { 215 super.emitUntyped.apply(this, args); 216 } 217 /** 208 218 * Gets a list of clients. 209 219 * … … 212 222 */ 213 223 allSockets() { 214 if (!this.adapter) { 215 throw new Error("No adapter for this namespace, are you trying to get the list of clients of a dynamic namespace?"); 216 } 217 const rooms = new Set(this._rooms); 218 this._rooms.clear(); 219 return this.adapter.sockets(rooms); 224 return new broadcast_operator_1.BroadcastOperator(this.adapter).allSockets(); 220 225 } 221 226 /** … … 227 232 */ 228 233 compress(compress) { 229 this._flags.compress = compress; 230 return this; 234 return new broadcast_operator_1.BroadcastOperator(this.adapter).compress(compress); 231 235 } 232 236 /** … … 239 243 */ 240 244 get volatile() { 241 this._flags.volatile = true; 242 return this; 245 return new broadcast_operator_1.BroadcastOperator(this.adapter).volatile; 243 246 } 244 247 /** … … 249 252 */ 250 253 get local() { 251 this._flags.local = true; 252 return this; 254 return new broadcast_operator_1.BroadcastOperator(this.adapter).local; 255 } 256 /** 257 * Returns the matching socket instances 258 * 259 * @public 260 */ 261 fetchSockets() { 262 return new broadcast_operator_1.BroadcastOperator(this.adapter).fetchSockets(); 263 } 264 /** 265 * Makes the matching socket instances join the specified rooms 266 * 267 * @param room 268 * @public 269 */ 270 socketsJoin(room) { 271 return new broadcast_operator_1.BroadcastOperator(this.adapter).socketsJoin(room); 272 } 273 /** 274 * Makes the matching socket instances leave the specified rooms 275 * 276 * @param room 277 * @public 278 */ 279 socketsLeave(room) { 280 return new broadcast_operator_1.BroadcastOperator(this.adapter).socketsLeave(room); 281 } 282 /** 283 * Makes the matching socket instances disconnect 284 * 285 * @param close - whether to close the underlying connection 286 * @public 287 */ 288 disconnectSockets(close = false) { 289 return new broadcast_operator_1.BroadcastOperator(this.adapter).disconnectSockets(close); 253 290 } 254 291 } -
trip-planner-front/node_modules/socket.io/dist/parent-namespace.d.ts
r59329aa re29cc2e 1 1 import { Namespace } from "./namespace"; 2 2 import type { Server } from "./index"; 3 export declare class ParentNamespace extends Namespace { 3 import type { EventParams, EventNames, EventsMap, DefaultEventsMap } from "./typed-events"; 4 export declare class ParentNamespace<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData> { 4 5 private static count; 5 6 private children; 6 constructor(server: Server );7 constructor(server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>); 7 8 /** 8 9 * @private 9 10 */ 10 11 _initAdapter(): void; 11 emit (ev: string | Symbol, ...args: [...any]): true;12 createChild(name: string): Namespace ;12 emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean; 13 createChild(name: string): Namespace<ListenEvents, EmitEvents, ServerSideEvents, SocketData>; 13 14 } -
trip-planner-front/node_modules/socket.io/dist/parent-namespace.js
r59329aa re29cc2e 12 12 */ 13 13 _initAdapter() { 14 /* no-op */ 14 const broadcast = (packet, opts) => { 15 this.children.forEach((nsp) => { 16 nsp.adapter.broadcast(packet, opts); 17 }); 18 }; 19 // @ts-ignore FIXME is there a way to declare an inner class in TypeScript? 20 this.adapter = { broadcast }; 15 21 } 16 22 emit(ev, ...args) { 17 23 this.children.forEach((nsp) => { 18 nsp._rooms = this._rooms;19 nsp._flags = this._flags;20 24 nsp.emit(ev, ...args); 21 25 }); 22 this._rooms.clear();23 this._flags = {};24 26 return true; 25 27 } -
trip-planner-front/node_modules/socket.io/dist/socket.d.ts
r59329aa re29cc2e 1 1 /// <reference types="node" /> 2 import { EventEmitter } from "events";3 2 import { Packet } from "socket.io-parser"; 3 import { EventParams, EventNames, EventsMap, StrictEventEmitter, DefaultEventsMap } from "./typed-events"; 4 4 import type { Client } from "./client"; 5 5 import type { Namespace } from "./namespace"; … … 7 7 import type { Room, SocketId } from "socket.io-adapter"; 8 8 import type { ParsedUrlQuery } from "querystring"; 9 import { BroadcastOperator } from "./broadcast-operator"; 10 export interface SocketReservedEventsMap { 11 disconnect: (reason: string) => void; 12 disconnecting: (reason: string) => void; 13 error: (err: Error) => void; 14 } 15 export interface EventEmitterReservedEventsMap { 16 newListener: (eventName: string | Symbol, listener: (...args: any[]) => void) => void; 17 removeListener: (eventName: string | Symbol, listener: (...args: any[]) => void) => void; 18 } 9 19 export declare const RESERVED_EVENTS: ReadonlySet<string | Symbol>; 10 20 /** … … 51 61 }; 52 62 } 53 export declare class Socket extends EventEmitter { 54 readonly nsp: Namespace; 55 readonly client: Client; 63 declare type Event = [eventName: string, ...args: any[]]; 64 export declare class Socket<ListenEvents extends EventsMap = DefaultEventsMap, EmitEvents extends EventsMap = ListenEvents, ServerSideEvents extends EventsMap = DefaultEventsMap, SocketData = any> extends StrictEventEmitter<ListenEvents, EmitEvents, SocketReservedEventsMap> { 65 readonly nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>; 66 readonly client: Client<ListenEvents, EmitEvents, ServerSideEvents>; 56 67 readonly id: SocketId; 57 68 readonly handshake: Handshake; 69 /** 70 * Additional information that can be attached to the Socket instance and which will be used in the fetchSockets method 71 */ 72 data: Partial<SocketData>; 58 73 connected: boolean; 59 disconnected: boolean;60 74 private readonly server; 61 75 private readonly adapter; … … 63 77 private fns; 64 78 private flags; 65 private _rooms;66 79 private _anyListeners?; 67 80 /** … … 73 86 * @package 74 87 */ 75 constructor(nsp: Namespace , client: Client, auth: object);88 constructor(nsp: Namespace<ListenEvents, EmitEvents, ServerSideEvents>, client: Client<ListenEvents, EmitEvents, ServerSideEvents>, auth: object); 76 89 /** 77 90 * Builds the `handshake` BC object … … 86 99 * @public 87 100 */ 88 emit(ev: string, ...args: any[]): boolean; 101 emit<Ev extends EventNames<EmitEvents>>(ev: Ev, ...args: EventParams<EmitEvents, Ev>): boolean; 102 /** 103 * @private 104 */ 105 private registerAckCallback; 89 106 /** 90 107 * Targets a room when broadcasting. 91 108 * 92 * @param name93 * @return self 94 * @public 95 */ 96 to( name: Room): this;109 * @param room 110 * @return self 111 * @public 112 */ 113 to(room: Room | Room[]): BroadcastOperator<EmitEvents>; 97 114 /** 98 115 * Targets a room when broadcasting. 99 116 * 100 * @param name 101 * @return self 102 * @public 103 */ 104 in(name: Room): this; 117 * @param room 118 * @return self 119 * @public 120 */ 121 in(room: Room | Room[]): BroadcastOperator<EmitEvents>; 122 /** 123 * Excludes a room when broadcasting. 124 * 125 * @param room 126 * @return self 127 * @public 128 */ 129 except(room: Room | Room[]): BroadcastOperator<EmitEvents>; 105 130 /** 106 131 * Sends a `message` event. … … 109 134 * @public 110 135 */ 111 send(...args: readonly any[]): this;136 send(...args: EventParams<EmitEvents, "message">): this; 112 137 /** 113 138 * Sends a `message` event. … … 116 141 * @public 117 142 */ 118 write(...args: readonly any[]): this;143 write(...args: EventParams<EmitEvents, "message">): this; 119 144 /** 120 145 * Writes a packet. … … 194 219 * @private 195 220 */ 196 _onerror(err: any): void;221 _onerror(err: Error): void; 197 222 /** 198 223 * Called upon closing. Called by `Client`. … … 245 270 * @public 246 271 */ 247 get broadcast(): this;272 get broadcast(): BroadcastOperator<EmitEvents>; 248 273 /** 249 274 * Sets a modifier for a subsequent event emission that the event data will only be broadcast to the current node. … … 252 277 * @public 253 278 */ 254 get local(): this; 279 get local(): BroadcastOperator<EmitEvents>; 280 /** 281 * Sets a modifier for a subsequent event emission that the callback will be called with an error when the 282 * given number of milliseconds have elapsed without an acknowledgement from the client: 283 * 284 * ``` 285 * socket.timeout(5000).emit("my-event", (err) => { 286 * if (err) { 287 * // the client did not acknowledge the event in the given delay 288 * } 289 * }); 290 * ``` 291 * 292 * @returns self 293 * @public 294 */ 295 timeout(timeout: number): this; 255 296 /** 256 297 * Dispatch incoming event to socket listeners. … … 267 308 * @public 268 309 */ 269 use(fn: (event: Array<any>, next: (err: Error) => void) => void): this;310 use(fn: (event: Event, next: (err?: Error) => void) => void): this; 270 311 /** 271 312 * Executes the middleware for an incoming event. … … 277 318 private run; 278 319 /** 320 * Whether the socket is currently disconnected 321 */ 322 get disconnected(): boolean; 323 /** 279 324 * A reference to the request that originated the underlying Engine.IO Socket. 280 325 * … … 287 332 * @public 288 333 */ 289 get conn(): any;334 get conn(): import("engine.io").Socket; 290 335 /** 291 336 * @public … … 322 367 */ 323 368 listenersAny(): ((...args: any[]) => void)[]; 369 private newBroadcastOperator; 324 370 } 371 export {}; -
trip-planner-front/node_modules/socket.io/dist/socket.js
r59329aa re29cc2e 5 5 Object.defineProperty(exports, "__esModule", { value: true }); 6 6 exports.Socket = exports.RESERVED_EVENTS = void 0; 7 const events_1 = require("events");8 7 const socket_io_parser_1 = require("socket.io-parser"); 9 const url = require("url");10 8 const debug_1 = __importDefault(require("debug")); 9 const typed_events_1 = require("./typed-events"); 11 10 const base64id_1 = __importDefault(require("base64id")); 12 const debug = debug_1.default("socket.io:socket"); 11 const broadcast_operator_1 = require("./broadcast-operator"); 12 const debug = (0, debug_1.default)("socket.io:socket"); 13 13 exports.RESERVED_EVENTS = new Set([ 14 14 "connect", … … 16 16 "disconnect", 17 17 "disconnecting", 18 // EventEmitter reserved events: https://nodejs.org/api/events.html#events_event_newlistener19 18 "newListener", 20 19 "removeListener", 21 20 ]); 22 class Socket extends events_1.EventEmitter {21 class Socket extends typed_events_1.StrictEventEmitter { 23 22 /** 24 23 * Interface to a `Client` for a given `Namespace`. … … 33 32 this.nsp = nsp; 34 33 this.client = client; 34 /** 35 * Additional information that can be attached to the Socket instance and which will be used in the fetchSockets method 36 */ 37 this.data = {}; 38 this.connected = false; 35 39 this.acks = new Map(); 36 40 this.fns = []; 37 41 this.flags = {}; 38 this._rooms = new Set();39 42 this.server = nsp.server; 40 43 this.adapter = this.nsp.adapter; … … 46 49 this.id = base64id_1.default.generateId(); // don't reuse the Engine.IO id because it's sensitive information 47 50 } 48 this.connected = true;49 this.disconnected = false;50 51 this.handshake = this.buildHandshake(auth); 51 52 } … … 65 66 issued: +new Date(), 66 67 url: this.request.url, 67 query: url.parse(this.request.url, true).query, 68 // @ts-ignore 69 query: this.request._query, 68 70 auth, 69 71 }; … … 79 81 throw new Error(`"${ev}" is a reserved event name`); 80 82 } 81 args.unshift(ev);83 const data = [ev, ...args]; 82 84 const packet = { 83 85 type: socket_io_parser_1.PacketType.EVENT, 84 data: args,86 data: data, 85 87 }; 86 88 // access last argument to see if it's an ACK callback 87 if (typeof args[args.length - 1] === "function") { 88 if (this._rooms.size || this.flags.broadcast) { 89 throw new Error("Callbacks are not supported when broadcasting"); 90 } 91 debug("emitting packet with ack id %d", this.nsp._ids); 92 this.acks.set(this.nsp._ids, args.pop()); 93 packet.id = this.nsp._ids++; 94 } 95 const rooms = new Set(this._rooms); 89 if (typeof data[data.length - 1] === "function") { 90 const id = this.nsp._ids++; 91 debug("emitting packet with ack id %d", id); 92 this.registerAckCallback(id, data.pop()); 93 packet.id = id; 94 } 96 95 const flags = Object.assign({}, this.flags); 97 // reset flags98 this._rooms.clear();99 96 this.flags = {}; 100 if (rooms.size || flags.broadcast) { 101 this.adapter.broadcast(packet, { 102 except: new Set([this.id]), 103 rooms: rooms, 104 flags: flags, 105 }); 106 } 107 else { 108 // dispatch packet 109 this.packet(packet, flags); 110 } 97 this.packet(packet, flags); 111 98 return true; 112 99 } 113 100 /** 101 * @private 102 */ 103 registerAckCallback(id, ack) { 104 const timeout = this.flags.timeout; 105 if (timeout === undefined) { 106 this.acks.set(id, ack); 107 return; 108 } 109 const timer = setTimeout(() => { 110 debug("event with ack id %d has timed out after %d ms", id, timeout); 111 this.acks.delete(id); 112 ack.call(this, new Error("operation has timed out")); 113 }, timeout); 114 this.acks.set(id, (...args) => { 115 clearTimeout(timer); 116 ack.apply(this, [null, ...args]); 117 }); 118 } 119 /** 114 120 * Targets a room when broadcasting. 115 121 * 116 * @param name122 * @param room 117 123 * @return self 118 124 * @public 119 125 */ 120 to(name) { 121 this._rooms.add(name); 122 return this; 126 to(room) { 127 return this.newBroadcastOperator().to(room); 123 128 } 124 129 /** 125 130 * Targets a room when broadcasting. 126 131 * 127 * @param name132 * @param room 128 133 * @return self 129 134 * @public 130 135 */ 131 in(name) { 132 this._rooms.add(name); 133 return this; 136 in(room) { 137 return this.newBroadcastOperator().in(room); 138 } 139 /** 140 * Excludes a room when broadcasting. 141 * 142 * @param room 143 * @return self 144 * @public 145 */ 146 except(room) { 147 return this.newBroadcastOperator().except(room); 134 148 } 135 149 /** … … 205 219 _onconnect() { 206 220 debug("socket connected - writing packet"); 221 this.connected = true; 207 222 this.join(this.id); 208 223 if (this.conn.protocol === 3) { … … 317 332 _onerror(err) { 318 333 if (this.listeners("error").length) { 319 super.emit("error", err);334 this.emitReserved("error", err); 320 335 } 321 336 else { … … 336 351 return this; 337 352 debug("closing socket - reason %s", reason); 338 super.emit("disconnecting", reason);353 this.emitReserved("disconnecting", reason); 339 354 this.leaveAll(); 340 355 this.nsp._remove(this); 341 356 this.client._remove(this); 342 357 this.connected = false; 343 this.disconnected = true; 344 super.emit("disconnect", reason); 358 this.emitReserved("disconnect", reason); 345 359 return; 346 360 } … … 406 420 */ 407 421 get broadcast() { 408 this.flags.broadcast = true; 409 return this; 422 return this.newBroadcastOperator(); 410 423 } 411 424 /** … … 416 429 */ 417 430 get local() { 418 this.flags.local = true; 431 return this.newBroadcastOperator().local; 432 } 433 /** 434 * Sets a modifier for a subsequent event emission that the callback will be called with an error when the 435 * given number of milliseconds have elapsed without an acknowledgement from the client: 436 * 437 * ``` 438 * socket.timeout(5000).emit("my-event", (err) => { 439 * if (err) { 440 * // the client did not acknowledge the event in the given delay 441 * } 442 * }); 443 * ``` 444 * 445 * @returns self 446 * @public 447 */ 448 timeout(timeout) { 449 this.flags.timeout = timeout; 419 450 return this; 420 451 } … … 433 464 } 434 465 if (this.connected) { 435 super.emit .apply(this, event);466 super.emitUntyped.apply(this, event); 436 467 } 437 468 else { … … 478 509 } 479 510 /** 511 * Whether the socket is currently disconnected 512 */ 513 get disconnected() { 514 return !this.connected; 515 } 516 /** 480 517 * A reference to the request that originated the underlying Engine.IO Socket. 481 518 * … … 556 593 return this._anyListeners || []; 557 594 } 595 newBroadcastOperator() { 596 const flags = Object.assign({}, this.flags); 597 this.flags = {}; 598 return new broadcast_operator_1.BroadcastOperator(this.adapter, new Set(), new Set([this.id]), flags); 599 } 558 600 } 559 601 exports.Socket = Socket;
Note:
See TracChangeset
for help on using the changeset viewer.