socket.io-adapter
Advanced tools
Comparing version 2.0.3 to 2.1.0
@@ -0,1 +1,10 @@ | ||
# [2.1.0](https://github.com/socketio/socket.io-adapter/compare/2.0.3...2.1.0) (2021-01-15) | ||
### Features | ||
* add room events ([155fa63](https://github.com/socketio/socket.io-adapter/commit/155fa6333a504036e99a33667dc0397f6aede25e)) | ||
* make rooms and sids public ([313c5a9](https://github.com/socketio/socket.io-adapter/commit/313c5a9fb60d913cd3a866001d67516399d8ee2f)) | ||
## [2.0.3](https://github.com/socketio/socket.io-adapter/compare/1.1.2...2.0.3) (2020-11-05) | ||
@@ -2,0 +11,0 @@ |
@@ -19,4 +19,4 @@ /// <reference types="node" /> | ||
readonly nsp: any; | ||
protected rooms: Map<Room, Set<SocketId>>; | ||
protected sids: Map<SocketId, Set<Room>>; | ||
rooms: Map<Room, Set<SocketId>>; | ||
sids: Map<SocketId, Set<Room>>; | ||
private readonly encoder; | ||
@@ -52,2 +52,3 @@ /** | ||
del(id: SocketId, room: Room): Promise<void> | void; | ||
private _del; | ||
/** | ||
@@ -54,0 +55,0 @@ * Removes a socket from all rooms it's joined. |
@@ -34,11 +34,15 @@ "use strict"; | ||
addAll(id, rooms) { | ||
if (!this.sids.has(id)) { | ||
this.sids.set(id, new Set()); | ||
} | ||
for (const room of rooms) { | ||
if (!this.sids.has(id)) { | ||
this.sids.set(id, new Set()); | ||
} | ||
this.sids.get(id).add(room); | ||
if (!this.rooms.has(room)) { | ||
this.rooms.set(room, new Set()); | ||
this.emit("create-room", room); | ||
} | ||
this.rooms.get(room).add(id); | ||
if (!this.rooms.get(room).has(id)) { | ||
this.rooms.get(room).add(id); | ||
this.emit("join-room", room, id); | ||
} | ||
} | ||
@@ -56,6 +60,14 @@ } | ||
} | ||
this._del(room, id); | ||
} | ||
_del(room, id) { | ||
if (this.rooms.has(room)) { | ||
this.rooms.get(room).delete(id); | ||
if (this.rooms.get(room).size === 0) | ||
const deleted = this.rooms.get(room).delete(id); | ||
if (deleted) { | ||
this.emit("leave-room", room, id); | ||
} | ||
if (this.rooms.get(room).size === 0) { | ||
this.rooms.delete(room); | ||
this.emit("delete-room", room); | ||
} | ||
} | ||
@@ -73,7 +85,3 @@ } | ||
for (const room of this.sids.get(id)) { | ||
if (this.rooms.has(room)) { | ||
this.rooms.get(room).delete(id); | ||
if (this.rooms.get(room).size === 0) | ||
this.rooms.delete(room); | ||
} | ||
this._del(room, id); | ||
} | ||
@@ -80,0 +88,0 @@ this.sids.delete(id); |
{ | ||
"name": "socket.io-adapter", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "repository": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11521
254