- Timestamp:
- 11/25/21 22:08:24 (3 years ago)
- Branches:
- master
- Children:
- 8d391a1
- Parents:
- 59329aa
- Location:
- trip-planner-front/node_modules/socket.io-adapter/dist
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/node_modules/socket.io-adapter/dist/index.d.ts
r59329aa re29cc2e 81 81 */ 82 82 socketRooms(id: SocketId): Set<Room> | undefined; 83 /** 84 * Returns the matching socket instances 85 * 86 * @param opts - the filters to apply 87 */ 88 fetchSockets(opts: BroadcastOptions): Promise<any[]>; 89 /** 90 * Makes the matching socket instances join the specified rooms 91 * 92 * @param opts - the filters to apply 93 * @param rooms - the rooms to join 94 */ 95 addSockets(opts: BroadcastOptions, rooms: Room[]): void; 96 /** 97 * Makes the matching socket instances leave the specified rooms 98 * 99 * @param opts - the filters to apply 100 * @param rooms - the rooms to leave 101 */ 102 delSockets(opts: BroadcastOptions, rooms: Room[]): void; 103 /** 104 * Makes the matching socket instances disconnect 105 * 106 * @param opts - the filters to apply 107 * @param close - whether to close the underlying connection 108 */ 109 disconnectSockets(opts: BroadcastOptions, close: boolean): void; 110 private apply; 111 private computeExceptSids; 112 /** 113 * Send a packet to the other Socket.IO servers in the cluster 114 * @param packet - an array of arguments, which may include an acknowledgement callback at the end 115 */ 116 serverSideEmit(packet: any[]): void; 83 117 } -
trip-planner-front/node_modules/socket.io-adapter/dist/index.js
r59329aa re29cc2e 60 60 } 61 61 _del(room, id) { 62 if (this.rooms.has(room)) { 63 const deleted = this.rooms.get(room).delete(id); 62 const _room = this.rooms.get(room); 63 if (_room != null) { 64 const deleted = _room.delete(id); 64 65 if (deleted) { 65 66 this.emit("leave-room", room, id); 66 67 } 67 if (this.rooms.get(room).size === 0) { 68 this.rooms.delete(room); 68 if (_room.size === 0 && this.rooms.delete(room)) { 69 69 this.emit("delete-room", room); 70 70 } … … 98 98 */ 99 99 broadcast(packet, opts) { 100 const rooms = opts.rooms;101 const except = opts.except || new Set();102 100 const flags = opts.flags || {}; 103 101 const packetOpts = { … … 106 104 compress: flags.compress 107 105 }; 108 const ids = new Set();109 106 packet.nsp = this.nsp.name; 110 107 const encodedPackets = this.encoder.encode(packet); 108 this.apply(opts, socket => { 109 socket.client.writeToEngine(encodedPackets, packetOpts); 110 }); 111 } 112 /** 113 * Gets a list of sockets by sid. 114 * 115 * @param {Set<Room>} rooms the explicit set of rooms to check. 116 */ 117 sockets(rooms) { 118 const sids = new Set(); 119 this.apply({ rooms }, socket => { 120 sids.add(socket.id); 121 }); 122 return Promise.resolve(sids); 123 } 124 /** 125 * Gets the list of rooms a given socket has joined. 126 * 127 * @param {SocketId} id the socket id 128 */ 129 socketRooms(id) { 130 return this.sids.get(id); 131 } 132 /** 133 * Returns the matching socket instances 134 * 135 * @param opts - the filters to apply 136 */ 137 fetchSockets(opts) { 138 const sockets = []; 139 this.apply(opts, socket => { 140 sockets.push(socket); 141 }); 142 return Promise.resolve(sockets); 143 } 144 /** 145 * Makes the matching socket instances join the specified rooms 146 * 147 * @param opts - the filters to apply 148 * @param rooms - the rooms to join 149 */ 150 addSockets(opts, rooms) { 151 this.apply(opts, socket => { 152 socket.join(rooms); 153 }); 154 } 155 /** 156 * Makes the matching socket instances leave the specified rooms 157 * 158 * @param opts - the filters to apply 159 * @param rooms - the rooms to leave 160 */ 161 delSockets(opts, rooms) { 162 this.apply(opts, socket => { 163 rooms.forEach(room => socket.leave(room)); 164 }); 165 } 166 /** 167 * Makes the matching socket instances disconnect 168 * 169 * @param opts - the filters to apply 170 * @param close - whether to close the underlying connection 171 */ 172 disconnectSockets(opts, close) { 173 this.apply(opts, socket => { 174 socket.disconnect(close); 175 }); 176 } 177 apply(opts, callback) { 178 const rooms = opts.rooms; 179 const except = this.computeExceptSids(opts.except); 111 180 if (rooms.size) { 181 const ids = new Set(); 112 182 for (const room of rooms) { 113 183 if (!this.rooms.has(room)) … … 118 188 const socket = this.nsp.sockets.get(id); 119 189 if (socket) { 120 socket.packet(encodedPackets, packetOpts);190 callback(socket); 121 191 ids.add(id); 122 192 } … … 130 200 const socket = this.nsp.sockets.get(id); 131 201 if (socket) 132 socket.packet(encodedPackets, packetOpts); 133 } 134 } 135 } 136 /** 137 * Gets a list of sockets by sid. 138 * 139 * @param {Set<Room>} rooms the explicit set of rooms to check. 140 */ 141 sockets(rooms) { 142 const sids = new Set(); 143 if (rooms.size) { 144 for (const room of rooms) { 145 if (!this.rooms.has(room)) 146 continue; 147 for (const id of this.rooms.get(room)) { 148 if (this.nsp.sockets.has(id)) { 149 sids.add(id); 150 } 202 callback(socket); 203 } 204 } 205 } 206 computeExceptSids(exceptRooms) { 207 const exceptSids = new Set(); 208 if (exceptRooms && exceptRooms.size > 0) { 209 for (const room of exceptRooms) { 210 if (this.rooms.has(room)) { 211 this.rooms.get(room).forEach(sid => exceptSids.add(sid)); 151 212 } 152 213 } 153 214 } 154 else { 155 for (const [id] of this.sids) { 156 if (this.nsp.sockets.has(id)) 157 sids.add(id); 158 } 159 } 160 return Promise.resolve(sids); 161 } 162 /** 163 * Gets the list of rooms a given socket has joined. 164 * 165 * @param {SocketId} id the socket id 166 */ 167 socketRooms(id) { 168 return this.sids.get(id); 215 return exceptSids; 216 } 217 /** 218 * Send a packet to the other Socket.IO servers in the cluster 219 * @param packet - an array of arguments, which may include an acknowledgement callback at the end 220 */ 221 serverSideEmit(packet) { 222 throw new Error("this adapter does not support the serverSideEmit() functionality"); 169 223 } 170 224 }
Note:
See TracChangeset
for help on using the changeset viewer.