Commit Graph

96 Commits

Author SHA1 Message Date
Shrikant Sharat Kandula
912e13ad30 fix: fix race condition when leaving rooms (#74)
This should fix the related issue:

```
TypeError: Cannot read property 'size' of undefined
    at Adapter._del (/app/node_modules/socket.io-adapter/dist/index.js:67:37)
    at Adapter.delAll (/app/node_modules/socket.io-adapter/dist/index.js:83:18)
    at Socket.leaveAll (/app/node_modules/socket.io/dist/socket.js:190:22)
    at Socket._onclose (/app/node_modules/socket.io/dist/socket.js:334:14)
    at Client.onclose (/app/node_modules/socket.io/dist/client.js:245:20)
    at Socket.emit (events.js:412:35)
    at Socket.onClose (/app/node_modules/engine.io/lib/socket.js:348:12)
    at Object.onceWrapper (events.js:519:28)
    at WebSocket.emit (events.js:400:28)
    at WebSocket.onClose (/app/node_modules/engine.io/lib/transport.js:106:10)
```

A test case was added, which reproduces the issue by adding a listener
to the "leave-room" event. This does not seem to be the case for the
user reporting the issue though, which may indicate that the root cause
is elsewhere.
2021-08-28 07:51:31 +02:00
Damien Arrachequesne
0667d826f6 chore(release): 2.3.1
Diff: https://github.com/socketio/socket.io-adapter/compare/2.3.0...2.3.1
2021-05-20 00:47:01 +02:00
Damien Arrachequesne
a33e42bb7b fix: restore compatibility with binary parsers
Related: 5579d40c24
2021-05-20 00:46:19 +02:00
dependabot[bot]
36d0acfd7e chore(deps): bump lodash from 4.17.20 to 4.17.21 (#69)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.20 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.20...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-20 00:22:52 +02:00
Damien Arrachequesne
03bda43550 chore(release): 2.3.0
Diff: https://github.com/socketio/socket.io-adapter/compare/2.2.0...2.3.0
2021-05-10 10:36:22 +02:00
Damien Arrachequesne
c4cbd4ba2d feat: add a serverSideEmit empty function
This function will be overriden in the Redis adapter, for inter-server
communication.
2021-05-10 10:35:42 +02:00
Damien Arrachequesne
5579d40c24 feat: add support for the "wsPreEncoded" writing option
A few notes:

- only the first element is pre-encoded, because the other elements are
buffers and will be sent as is over the WebSocket connection

- using `socket.packet()` was unexpectedly working, we will now use
`socket.client.writeToEngine()` (see [1])

See also: 7706b123df

[1]: https://github.com/socketio/socket.io/issues/3775
2021-05-10 10:09:54 +02:00
Damien Arrachequesne
c679e62236 chore(release): 2.2.0
Diff: https://github.com/socketio/socket.io-adapter/compare/2.1.0...2.2.0
2021-02-27 02:08:54 +01:00
Damien Arrachequesne
1c9827ec11 feat: add some utility methods
This commit adds the following methods:

- fetchSockets: return the matching socket instances
- addSockets: make the matching socket instances join the specified rooms
- delSockets: make the matching socket instances leave the specified rooms
- disconnectSockets: disconnect the matching socket instances

Those methods will then be exposed by the Socket.IO server:

```js
// clear room
io.socketsLeave("room1");

// disconnect all sockets in room
io.in("room2").disconnectSockets();

// fetch socket instances in room
io.in("room3").fetchSockets();
```

This feature will also be extended in the Redis adapter to handle
multiple Socket.IO servers.
2021-02-27 01:37:53 +01:00
Sebastiaan Marynissen
985bb41fa2 feat: allow excluding all sockets in a room (#66) 2021-02-26 15:32:45 +01:00
Damien Arrachequesne
c95ab42aef chore(release): 2.1.0
Diff: https://github.com/socketio/socket.io-adapter/compare/2.0.3...2.1.0
2021-01-15 01:30:02 +01:00
Damien Arrachequesne
155fa6333a feat: add room events
The adapter will now emit the following events:

- create-room (arg: room)
- delete-room (arg: room)
- join-room (args: room, sid)
- leave-room (args: room, sid)

Related: https://github.com/socketio/socket.io/issues/2897
2021-01-15 01:22:49 +01:00
Damien Arrachequesne
313c5a9fb6 feat: make rooms and sids public
Related: https://github.com/socketio/socket.io-adapter/issues/63
2021-01-14 23:56:30 +01:00
Dante Calderón
4111013bc7 refactor: validate socket id before loop in addAll (#64) 2021-01-02 23:24:15 +01:00
Damien Arrachequesne
788d95ad1c ci: init GitHub actions
Reference: https://docs.github.com/en/free-pro-team@latest/actions/guides/building-and-testing-nodejs
2021-01-02 23:23:01 +01:00
Damien Arrachequesne
e73271e652 chore(release): 2.0.3
Diff: https://github.com/socketio/socket.io-adapter/compare/1.1.2...2.0.3
2020-11-05 16:19:45 +01:00
Damien Arrachequesne
d5ceef94ed chore(release): 2.0.3-rc2
Diff: https://github.com/socketio/socket.io-adapter/compare/2.0.3-rc1...2.0.3-rc2
2020-10-20 14:27:38 +02:00
Damien Arrachequesne
f7c6eca48c docs: add compatibility table 2020-10-20 14:22:57 +02:00
Damien Arrachequesne
2e023bf2b6 feat: add init() and close() methods
These extension points may be used by another adapter, in order to open
or close a connection to a database for example.

In Socket.IO v2, the join() method did accept a callback:

```js
socket.join("room1", () => {
  io.to("room1").emit("hello");
});
```

Depending on the adapter, it may now return a promise:

```js
await socket.join("room1");
io.to("room1").emit("hello");
```

Related: https://github.com/socketio/socket.io/issues/3662
2020-10-20 14:18:57 +02:00
Damien Arrachequesne
5f417d256b chore(release): 2.0.3-rc1
Diff: https://github.com/socketio/socket.io-adapter/compare/2.0.2...2.0.3-rc1
2020-10-15 12:18:09 +02:00
Damien Arrachequesne
0a9762cac2 refactor: use Namespace#sockets to broadcast 2020-10-15 12:15:32 +02:00
Damien Arrachequesne
5d81b13431 chore(release): 2.0.2
Diff: https://github.com/socketio/socket.io-adapter/compare/2.0.1...2.0.2
2020-09-28 15:32:41 +02:00
Damien Arrachequesne
e57f528944 chore(release): 2.0.1
Diff: https://github.com/socketio/socket.io-adapter/compare/2.0.0...2.0.1
2020-09-28 15:14:58 +02:00
Damien Arrachequesne
c043650f1c fix: Adapter#encode() is now synchronous
See https://github.com/socketio/socket.io-parser/releases/tag/4.0.0
2020-09-28 15:11:56 +02:00
Damien Arrachequesne
7216d7adfb chore(release): 2.0.0
Diff: https://github.com/socketio/socket.io-adapter/compare/1.1.2...2.0.0
2020-09-25 23:09:21 +02:00
Damien Arrachequesne
b52b4ef49e refactor: migrate to TypeScript 2020-09-25 23:01:42 +02:00
Damien Arrachequesne
130f28a43c refactor: rename clients and clientRooms methods
In Socket.IO glossary:

- a Client manages the low-level connection and can be associated with several Sockets
- a Socket belongs to a given Namespace
2020-09-16 22:27:27 +02:00
Damien Arrachequesne
53ed3f4099 feat: use ES6 Sets and Maps
The sids and the rooms objects are now Map<string, Set<string>>:

sids => Map<SocketId, Set<Room>>
rooms => Map<Room, Set<SocketId>>

Breaking changes: the clients() and clientRooms() methods will now
return a Set instead of an array.

Also, the rooms argument in the broadcast() method will now be a Set
too.

Besides, the callbacks were removed from all function signatures, as
every operation is synchronous. Regarding the Redis adapter, the
clients() method is the only operation which will now return a promise.

This change allows us to remove the Room class, which was used to have
an external length attribute (instead of computing Object.keys()
everytime).
2020-09-16 22:19:56 +02:00
Damien Arrachequesne
ae23c7ef4c [chore] release 1.1.2 2019-11-25 13:19:48 +01:00
Joway
b9074fa36f [fix] fix memory leak when leave a room after socket close (#58) 2019-11-25 13:14:47 +01:00
Darío Hereñú
f7ab50cc59 [docs] Remove duplicate word (#57) 2019-11-25 13:13:53 +01:00
Damien Arrachequesne
6874ea4952 [chore] release 1.1.1 2017-08-02 14:01:58 +02:00
Sam Roberts
bdb015a6c1 [chore] remove unused 'debug' dependency (#52) 2017-08-02 13:51:58 +02:00
Damien Arrachequesne
c6f7baec3b [chore] Release 1.1.0 (#50) 2017-02-26 08:38:04 +01:00
Damien Arrachequesne
f627cd2db1 [feat] Add addAll method (#49)
That will allow to efficiently join a list of rooms.
2017-02-26 08:22:54 +01:00
Damien Arrachequesne
b983377969 [chore] Release 1.0.0 (#48) 2017-02-16 22:26:40 +01:00
Damien Arrachequesne
40764bb806 [feat] Remove the socket.io-parser dependency (#47)
That will allow to use a custom parser (see https://github.com/socketio/socket.io/pull/2829).
2017-02-16 22:16:21 +01:00
Gatsbill
fd086d757e [refactor] Remove useless self var (#45) 2017-02-16 13:36:19 +01:00
Damien Arrachequesne
9a621ec592 [chore] Release 0.5.0 (#44) 2016-11-20 01:57:13 +01:00
Damien Arrachequesne
ffadfa600f [feature] Add clientRooms method (#41)
That method returns the list of rooms a given socket has joined. It is
intended to be used by other adapters, without them needing to access
the innards of the adapter.
2016-11-20 01:52:21 +01:00
Damien Arrachequesne
915af31c2c [chore] Bump debug to version 2.3.3 (#42) 2016-11-20 01:51:03 +01:00
Damien Arrachequesne
35987a5c0f [chore] Bump socket.io-parser to version 2.3.1 (#43) 2016-11-20 01:48:52 +01:00
tatellos
97bdbab37c [docs] Fix typo in Readme.md (#37) 2016-10-18 03:58:00 +02:00
Guillermo Rauch
efd6141dbd Release 0.4.0 2015-12-03 10:12:35 -08:00
Guillermo Rauch
d16e46df36 Merge pull request #30 from manubb/master-patched
Use a Room class to efficiently track room size.
2015-12-03 09:41:32 -08:00
Guillermo Rauch
6e0ecb4d3a package: bump debug 2015-11-19 09:44:13 -08:00
Manuel Baclet
bac5b0ec32 Simplify and clarify. 2015-06-11 11:37:24 +02:00
Manuel Baclet
55274af45a Small fix. 2015-06-11 11:36:06 +02:00
Manuel Baclet
1a5b6d4485 Comments on Room methods. 2015-06-11 10:58:40 +02:00
Manuel Baclet
f7e7c07fae Remove some spaces. 2015-06-11 10:58:20 +02:00