Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: socketio/socket.io-adapter
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2.5.3
Choose a base ref
...
head repository: socketio/socket.io-adapter
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 2.5.4
Choose a head ref
  • 7 commits
  • 8 files changed
  • 1 contributor

Commits on Feb 22, 2024

  1. fix(types): ensure compatibility with TypeScript < 4.5

    "import { type ... }" was added in TypeScript 4.5.
    
    Reference: https://devblogs.microsoft.com/typescript/announcing-typescript-4-5/
    
    Related:
    
    - #86
    - socketio/socket.io#3891
    darrachequesne committed Feb 22, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    ca397f3 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    9d4c4a7 View commit details
  3. refactor: break circular dependency (1)

    This will be done in two steps, in order to preserve the history of the
    index.ts file.
    darrachequesne committed Feb 22, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    abc93a9 View commit details
  4. refactor: break circular dependency (2)

    darrachequesne committed Feb 22, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    207c0db View commit details
  5. fix: ensure the order of the commands

    Before this change, the broadcast() method would send the BROADCAST
    command and then apply it locally (which is required to retrieve the
    offset of the message, when connection state recovery is enabled),
    while the other commands like disconnectSockets() would first apply it
    locally and then send the command to the other nodes.
    
    So, for example:
    
    ```js
    io.emit("bye");
    io.disconnectSockets();
    ```
    
    In that case, the clients connected to the io instance would not receive
    the "bye" event, while the clients connected to the other server
    instances would receive it before being disconnected.
    
    Related:
    
    - socketio/socket.io-redis-streams-adapter#13
    - socketio/socket.io-postgres-adapter#12
    darrachequesne committed Feb 22, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    a13f35f View commit details
  6. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    005d546 View commit details
  7. chore(release): 2.5.4

    darrachequesne committed Feb 22, 2024

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    darrachequesne Damien Arrachequesne
    Copy the full SHA
    5eae5a0 View commit details
Showing with 618 additions and 551 deletions.
  1. +7 −0 .github/workflows/ci.yml
  2. +11 −0 CHANGELOG.md
  3. +51 −42 lib/cluster-adapter.ts
  4. +507 −0 lib/in-memory-adapter.ts
  5. +12 −507 lib/index.ts
  6. +1 −1 package.json
  7. +25 −1 test/cluster-adapter.ts
  8. +4 −0 test/util.ts
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@ jobs:
strategy:
matrix:
node-version:
- 14
- 20

steps:
@@ -31,5 +32,11 @@ jobs:
- name: Install dependencies
run: npm ci

# the "override" keyword was added in typescript@4.5.0
# else, users can go down to typescript@3.8.x ("import type")
- name: Install TypeScript 4.5
run: npm i typescript@4.5
if: ${{ matrix.node-version == '14' }}

- name: Run tests
run: npm test
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# History

- [2.5.4](#254-2024-02-22) (Feb 2024)
- [2.5.3](#253-2024-02-21) (Feb 2024)
- [2.5.2](#252-2023-01-12) (Jan 2023)
- [2.5.1](#251-2023-01-06) (Jan 2023)
@@ -20,6 +21,16 @@

# Release notes

## [2.5.4](https://github.com/socketio/socket.io-adapter/compare/2.5.3...2.5.4) (2024-02-22)


### Bug Fixes

* ensure the order of the commands ([a13f35f](https://github.com/socketio/socket.io-adapter/commit/a13f35f0e6b85bbba07f99ee2440e914f1429d83))
* **types:** ensure compatibility with TypeScript < 4.5 ([ca397f3](https://github.com/socketio/socket.io-adapter/commit/ca397f3afe06ed9390db52b70a506a9721e091d8))



## [2.5.3](https://github.com/socketio/socket.io-adapter/compare/2.5.2...2.5.3) (2024-02-21)

Two abstract classes were imported from the [Redis adapter repository](https://github.com/socketio/socket.io-redis-adapter/blob/bd32763043a2eb79a21dffd8820f20e598348adf/lib/cluster-adapter.ts):
93 changes: 51 additions & 42 deletions lib/cluster-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
Adapter,
type BroadcastFlags,
type BroadcastOptions,
type Room,
} from "./index";
import { Adapter } from "./in-memory-adapter";
import type {
BroadcastFlags,
BroadcastOptions,
Room,
} from "./in-memory-adapter";
import { debug as debugModule } from "debug";
import { randomBytes } from "crypto";

@@ -503,55 +503,64 @@ export abstract class ClusterAdapter extends Adapter {
super.broadcastWithAck(packet, opts, clientCountCallback, ack);
}

override addSockets(opts: BroadcastOptions, rooms: Room[]) {
super.addSockets(opts, rooms);

override async addSockets(opts: BroadcastOptions, rooms: Room[]) {
const onlyLocal = opts.flags?.local;
if (onlyLocal) {
return;

if (!onlyLocal) {
try {
await this.publishAndReturnOffset({
type: MessageType.SOCKETS_JOIN,
data: {
opts: encodeOptions(opts),
rooms,
},
});
} catch (e) {
debug("[%s] error while publishing message: %s", this.uid, e.message);
}
}

this.publish({
type: MessageType.SOCKETS_JOIN,
data: {
opts: encodeOptions(opts),
rooms,
},
});
super.addSockets(opts, rooms);
}

override delSockets(opts: BroadcastOptions, rooms: Room[]) {
super.delSockets(opts, rooms);

override async delSockets(opts: BroadcastOptions, rooms: Room[]) {
const onlyLocal = opts.flags?.local;
if (onlyLocal) {
return;

if (!onlyLocal) {
try {
await this.publishAndReturnOffset({
type: MessageType.SOCKETS_LEAVE,
data: {
opts: encodeOptions(opts),
rooms,
},
});
} catch (e) {
debug("[%s] error while publishing message: %s", this.uid, e.message);
}
}

this.publish({
type: MessageType.SOCKETS_LEAVE,
data: {
opts: encodeOptions(opts),
rooms,
},
});
super.delSockets(opts, rooms);
}

override disconnectSockets(opts: BroadcastOptions, close: boolean) {
super.disconnectSockets(opts, close);

override async disconnectSockets(opts: BroadcastOptions, close: boolean) {
const onlyLocal = opts.flags?.local;
if (onlyLocal) {
return;

if (!onlyLocal) {
try {
await this.publishAndReturnOffset({
type: MessageType.DISCONNECT_SOCKETS,
data: {
opts: encodeOptions(opts),
close,
},
});
} catch (e) {
debug("[%s] error while publishing message: %s", this.uid, e.message);
}
}

this.publish({
type: MessageType.DISCONNECT_SOCKETS,
data: {
opts: encodeOptions(opts),
close,
},
});
super.disconnectSockets(opts, close);
}

async fetchSockets(opts: BroadcastOptions): Promise<any[]> {
Loading