mirror of
https://github.com/socketio/socket.io.git
synced 2026-01-11 16:08:24 -05:00
Compare commits
67 Commits
engine.io@
...
engine.io@
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0a99ac44a2 | ||
|
|
4338f47336 | ||
|
|
9199156758 | ||
|
|
594841617d | ||
|
|
84e7253e57 | ||
|
|
30ec4a136a | ||
|
|
e08293bc37 | ||
|
|
b837949479 | ||
|
|
118ef41b94 | ||
|
|
d19928e8d8 | ||
|
|
cdae01983a | ||
|
|
39bb72039d | ||
|
|
98741e15e9 | ||
|
|
8af70195bb | ||
|
|
d88f3f4578 | ||
|
|
f5ee981ee8 | ||
|
|
76e3a72bba | ||
|
|
a7b1938d06 | ||
|
|
54743633ff | ||
|
|
7617707ed8 | ||
|
|
599001d213 | ||
|
|
1c3e4711c1 | ||
|
|
693080cac7 | ||
|
|
5080c73e1e | ||
|
|
47ff1cd04c | ||
|
|
0ae76360f9 | ||
|
|
27fd420e75 | ||
|
|
0c431243e2 | ||
|
|
4fc25d80ec | ||
|
|
1dd729b1a1 | ||
|
|
6877512f57 | ||
|
|
cf6816afcf | ||
|
|
625fd66d73 | ||
|
|
f3e1f5ebdf | ||
|
|
e97549259e | ||
|
|
1da9cddeab | ||
|
|
6f9b198bc8 | ||
|
|
ac3df9a747 | ||
|
|
21fd54ece6 | ||
|
|
96d907b9b5 | ||
|
|
32257b6cb8 | ||
|
|
c7144920e3 | ||
|
|
42480e9a7f | ||
|
|
0a8f91047c | ||
|
|
a66ed68506 | ||
|
|
3be6481d9d | ||
|
|
be13cca94c | ||
|
|
e95f6abf93 | ||
|
|
72d61dab82 | ||
|
|
5a31aaf917 | ||
|
|
56a53bceb9 | ||
|
|
683720a67d | ||
|
|
a529eb08d6 | ||
|
|
cddb78e5fa | ||
|
|
15fd56e78d | ||
|
|
e86ef45f87 | ||
|
|
fe840e2eb3 | ||
|
|
a5a1c29082 | ||
|
|
66b4079953 | ||
|
|
be0a0e3217 | ||
|
|
43f9ee8d23 | ||
|
|
055b7840d8 | ||
|
|
6397c1bdfd | ||
|
|
ff370cfc46 | ||
|
|
1f8a6c4ecb | ||
|
|
eb01ff5803 | ||
|
|
f2e3d162ab |
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@@ -20,9 +20,9 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
node-version:
|
||||
- 18
|
||||
- 20
|
||||
- 22
|
||||
- 24
|
||||
|
||||
services:
|
||||
redis:
|
||||
@@ -35,12 +35,24 @@ jobs:
|
||||
ports:
|
||||
- 6379:6379
|
||||
|
||||
postgres:
|
||||
image: postgres:14
|
||||
env:
|
||||
POSTGRES_PASSWORD: changeit
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v6
|
||||
|
||||
- name: Use Node.js ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
|
||||
10
.github/workflows/publish.yml
vendored
10
.github/workflows/publish.yml
vendored
@@ -1,4 +1,4 @@
|
||||
# reference: https://docs.npmjs.com/generating-provenance-statements
|
||||
# reference: https://docs.npmjs.com/trusted-publishers#for-github-actions
|
||||
|
||||
name: Publish
|
||||
|
||||
@@ -19,10 +19,10 @@ jobs:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Use Node.js 20
|
||||
- name: Use Node.js 24
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
node-version: 24
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
- name: Install dependencies
|
||||
@@ -32,6 +32,4 @@ jobs:
|
||||
run: npm run compile --workspaces --if-present
|
||||
|
||||
- name: Publish package
|
||||
run: npm publish --workspace=${GITHUB_REF_NAME%@*} --provenance --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: npm publish --workspace=${GITHUB_REF_NAME%@*} --access public
|
||||
|
||||
25
CHANGELOG.md
25
CHANGELOG.md
@@ -2,14 +2,17 @@
|
||||
|
||||
Here are the detailed changelogs for each package in this monorepo:
|
||||
|
||||
| Package | Changelog |
|
||||
|--------------------------------|---------------------------------------------------------|
|
||||
| `engine.io` | [link](packages/engine.io/CHANGELOG.md) |
|
||||
| `engine.io-client` | [link](packages/engine.io-client/CHANGELOG.md) |
|
||||
| `engine.io-parser` | [link](packages/engine.io-parser/CHANGELOG.md) |
|
||||
| `socket.io` | [link](packages/socket.io/CHANGELOG.md) |
|
||||
| `socket.io-adapter` | [link](packages/socket.io-adapter/CHANGELOG.md) |
|
||||
| `socket.io-client` | [link](packages/socket.io-client/CHANGELOG.md) |
|
||||
| `@socket.io/cluster-engine` | [link](packages/socket.io-cluster-engine/CHANGELOG.md) |
|
||||
| `@socket.io/component-emitter` | [link](packages/socket.io-component-emitter/History.md) |
|
||||
| `socket.io-parser` | [link](packages/socket.io-parser/CHANGELOG.md) |
|
||||
| Package | Changelog |
|
||||
|------------------------------------|----------------------------------------------------------------|
|
||||
| `engine.io` | [link](packages/engine.io/CHANGELOG.md) |
|
||||
| `engine.io-client` | [link](packages/engine.io-client/CHANGELOG.md) |
|
||||
| `engine.io-parser` | [link](packages/engine.io-parser/CHANGELOG.md) |
|
||||
| `socket.io` | [link](packages/socket.io/CHANGELOG.md) |
|
||||
| `socket.io-adapter` | [link](packages/socket.io-adapter/CHANGELOG.md) |
|
||||
| `socket.io-client` | [link](packages/socket.io-client/CHANGELOG.md) |
|
||||
| `@socket.io/cluster-adapter` | [link](packages/socket.io-cluster-adapter/CHANGELOG.md) |
|
||||
| `@socket.io/cluster-engine` | [link](packages/socket.io-cluster-engine/CHANGELOG.md) |
|
||||
| `@socket.io/component-emitter` | [link](packages/socket.io-component-emitter/History.md) |
|
||||
| `socket.io-parser` | [link](packages/socket.io-parser/CHANGELOG.md) |
|
||||
| `@socket.io/postgres-emitter` | [link](packages/socket.io-postgres-emitter/CHANGELOG.md) |
|
||||
| `@socket.io/redis-streams-emitter` | [link](/packages/socket.io-redis-streams-emitter/CHANGELOG.md) |
|
||||
|
||||
@@ -17,16 +17,35 @@ function sleep(delay) {
|
||||
return new Promise((resolve) => setTimeout(resolve, delay));
|
||||
}
|
||||
|
||||
function createWebSocket(url) {
|
||||
const socket = new WebSocket(url);
|
||||
socket._eventBuffer = {};
|
||||
socket._pendingPromises = {};
|
||||
|
||||
for (const eventType of ["open", "close", "message"]) {
|
||||
socket._eventBuffer[eventType] = [];
|
||||
socket._pendingPromises[eventType] = [];
|
||||
|
||||
socket.addEventListener(eventType, (event) => {
|
||||
if (socket._pendingPromises[eventType].length) {
|
||||
socket._pendingPromises[eventType].shift()(event);
|
||||
} else {
|
||||
socket._eventBuffer[eventType].push(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
function waitFor(socket, eventType) {
|
||||
return new Promise((resolve) => {
|
||||
socket.addEventListener(
|
||||
eventType,
|
||||
(event) => {
|
||||
resolve(event);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
});
|
||||
if (socket._eventBuffer[eventType].length) {
|
||||
return Promise.resolve(socket._eventBuffer[eventType].shift());
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
socket._pendingPromises[eventType].push(resolve);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function initLongPollingSession() {
|
||||
@@ -110,7 +129,7 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("successfully opens a session", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -137,7 +156,7 @@ describe("Engine.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("fails with an invalid 'EIO' query parameter", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?transport=websocket`
|
||||
);
|
||||
|
||||
@@ -145,9 +164,9 @@ describe("Engine.IO protocol", () => {
|
||||
socket.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket, "close");
|
||||
await waitFor(socket, "close");
|
||||
|
||||
const socket2 = new WebSocket(
|
||||
const socket2 = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=abc&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -155,19 +174,19 @@ describe("Engine.IO protocol", () => {
|
||||
socket2.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket2, "close");
|
||||
await waitFor(socket2, "close");
|
||||
});
|
||||
|
||||
it("fails with an invalid 'transport' query parameter", async () => {
|
||||
const socket = new WebSocket(`${WS_URL}/engine.io/?EIO=4`);
|
||||
const socket = createWebSocket(`${WS_URL}/engine.io/?EIO=4`);
|
||||
|
||||
if (isNodejs) {
|
||||
socket.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket, "close");
|
||||
await waitFor(socket, "close");
|
||||
|
||||
const socket2 = new WebSocket(
|
||||
const socket2 = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=abc`
|
||||
);
|
||||
|
||||
@@ -175,7 +194,7 @@ describe("Engine.IO protocol", () => {
|
||||
socket2.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket2, "close");
|
||||
await waitFor(socket2, "close");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -313,11 +332,30 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
expect(pollResponse.status).to.eql(400);
|
||||
});
|
||||
|
||||
it("closes the session upon cancelled polling request", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
const controller = new AbortController();
|
||||
|
||||
fetch(`${URL}/engine.io/?EIO=4&transport=polling&sid=${sid}`, {
|
||||
signal: controller.signal,
|
||||
}).catch(() => {});
|
||||
|
||||
await sleep(5);
|
||||
|
||||
controller.abort();
|
||||
|
||||
const pollResponse = await fetch(
|
||||
`${URL}/engine.io/?EIO=4&transport=polling&sid=${sid}`,
|
||||
);
|
||||
|
||||
expect(pollResponse.status).to.eql(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("sends and receives a plain text packet", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -335,7 +373,7 @@ describe("Engine.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("sends and receives a binary packet", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
socket.binaryType = "arraybuffer";
|
||||
@@ -352,7 +390,7 @@ describe("Engine.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("closes the session upon invalid packet format", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -412,7 +450,7 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("sends ping/pong packets", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -430,7 +468,7 @@ describe("Engine.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("closes the session upon ping timeout", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -468,7 +506,7 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("forcefully closes the session", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -485,7 +523,7 @@ describe("Engine.IO protocol", () => {
|
||||
it("successfully upgrades from HTTP long-polling to WebSocket", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
@@ -521,12 +559,13 @@ describe("Engine.IO protocol", () => {
|
||||
it("ignores HTTP requests with same sid after upgrade", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
await waitFor(socket, "open");
|
||||
socket.send("2probe");
|
||||
await waitFor(socket, "message"); // "3probe"
|
||||
socket.send("5");
|
||||
|
||||
const pollResponse = await fetch(
|
||||
@@ -545,15 +584,16 @@ describe("Engine.IO protocol", () => {
|
||||
it("ignores WebSocket connection with same sid after upgrade", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
await waitFor(socket, "open");
|
||||
socket.send("2probe");
|
||||
await waitFor(socket, "message"); // "3probe"
|
||||
socket.send("5");
|
||||
|
||||
const socket2 = new WebSocket(
|
||||
const socket2 = createWebSocket(
|
||||
`${WS_URL}/engine.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
|
||||
@@ -17,16 +17,35 @@ function sleep(delay) {
|
||||
return new Promise((resolve) => setTimeout(resolve, delay));
|
||||
}
|
||||
|
||||
function createWebSocket(url) {
|
||||
const socket = new WebSocket(url);
|
||||
socket._eventBuffer = {};
|
||||
socket._pendingPromises = {};
|
||||
|
||||
for (const eventType of ["open", "close", "message"]) {
|
||||
socket._eventBuffer[eventType] = [];
|
||||
socket._pendingPromises[eventType] = [];
|
||||
|
||||
socket.addEventListener(eventType, (event) => {
|
||||
if (socket._pendingPromises[eventType].length) {
|
||||
socket._pendingPromises[eventType].shift()(event);
|
||||
} else {
|
||||
socket._eventBuffer[eventType].push(event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
function waitFor(socket, eventType) {
|
||||
return new Promise((resolve) => {
|
||||
socket.addEventListener(
|
||||
eventType,
|
||||
(event) => {
|
||||
resolve(event);
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
});
|
||||
if (socket._eventBuffer[eventType].length) {
|
||||
return Promise.resolve(socket._eventBuffer[eventType].shift());
|
||||
} else {
|
||||
return new Promise((resolve) => {
|
||||
socket._pendingPromises[eventType].push(resolve);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function waitForPackets(socket, count) {
|
||||
@@ -55,7 +74,7 @@ async function initLongPollingSession() {
|
||||
}
|
||||
|
||||
async function initSocketIOConnection() {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
socket.binaryType = "arraybuffer";
|
||||
@@ -145,7 +164,7 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("should successfully open a session", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -172,7 +191,7 @@ describe("Engine.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should fail with an invalid 'EIO' query parameter", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?transport=websocket`
|
||||
);
|
||||
|
||||
@@ -180,9 +199,9 @@ describe("Engine.IO protocol", () => {
|
||||
socket.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket, "close");
|
||||
await waitFor(socket, "close");
|
||||
|
||||
const socket2 = new WebSocket(
|
||||
const socket2 = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=abc&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -190,19 +209,19 @@ describe("Engine.IO protocol", () => {
|
||||
socket2.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket2, "close");
|
||||
await waitFor(socket2, "close");
|
||||
});
|
||||
|
||||
it("should fail with an invalid 'transport' query parameter", async () => {
|
||||
const socket = new WebSocket(`${WS_URL}/socket.io/?EIO=4`);
|
||||
const socket = createWebSocket(`${WS_URL}/socket.io/?EIO=4`);
|
||||
|
||||
if (isNodejs) {
|
||||
socket.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket, "close");
|
||||
await waitFor(socket, "close");
|
||||
|
||||
const socket2 = new WebSocket(
|
||||
const socket2 = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=abc`
|
||||
);
|
||||
|
||||
@@ -210,7 +229,7 @@ describe("Engine.IO protocol", () => {
|
||||
socket2.on("error", () => {});
|
||||
}
|
||||
|
||||
waitFor(socket2, "close");
|
||||
await waitFor(socket2, "close");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -260,7 +279,7 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("should send ping/pong packets", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -278,7 +297,7 @@ describe("Engine.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should close the session upon ping timeout", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -316,7 +335,7 @@ describe("Engine.IO protocol", () => {
|
||||
|
||||
describe("WebSocket", () => {
|
||||
it("should forcefully close the session", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -333,7 +352,7 @@ describe("Engine.IO protocol", () => {
|
||||
it("should successfully upgrade from HTTP long-polling to WebSocket", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
@@ -353,12 +372,13 @@ describe("Engine.IO protocol", () => {
|
||||
it("should ignore HTTP requests with same sid after upgrade", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
await waitFor(socket, "open");
|
||||
socket.send("2probe");
|
||||
await waitFor(socket, "message"); // "3probe"
|
||||
socket.send("5");
|
||||
|
||||
const pollResponse = await fetch(
|
||||
@@ -371,15 +391,16 @@ describe("Engine.IO protocol", () => {
|
||||
it("should ignore WebSocket connection with same sid after upgrade", async () => {
|
||||
const sid = await initLongPollingSession();
|
||||
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
await waitFor(socket, "open");
|
||||
socket.send("2probe");
|
||||
await waitFor(socket, "message"); // "3probe"
|
||||
socket.send("5");
|
||||
|
||||
const socket2 = new WebSocket(
|
||||
const socket2 = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket&sid=${sid}`
|
||||
);
|
||||
|
||||
@@ -391,7 +412,7 @@ describe("Engine.IO protocol", () => {
|
||||
describe("Socket.IO protocol", () => {
|
||||
describe("connect", () => {
|
||||
it("should allow connection to the main namespace", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -414,7 +435,7 @@ describe("Socket.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should allow connection to the main namespace with a payload", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -437,7 +458,7 @@ describe("Socket.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should allow connection to a custom namespace", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -460,7 +481,7 @@ describe("Socket.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should allow connection to a custom namespace with a payload", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -483,7 +504,7 @@ describe("Socket.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should disallow connection to an unknown namespace", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -497,7 +518,7 @@ describe("Socket.IO protocol", () => {
|
||||
});
|
||||
|
||||
it("should disallow connection with an invalid handshake", async () => {
|
||||
const socket = new WebSocket(
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
@@ -508,10 +529,9 @@ describe("Socket.IO protocol", () => {
|
||||
await waitFor(socket, "close");
|
||||
});
|
||||
|
||||
|
||||
it("should close the connection if no handshake is received", async () => {
|
||||
const socket = new WebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
const socket = createWebSocket(
|
||||
`${WS_URL}/socket.io/?EIO=4&transport=websocket`
|
||||
);
|
||||
|
||||
await waitFor(socket, "close");
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
"prettier": "^2.8.4",
|
||||
"rollup": "^3.20.2",
|
||||
"socket.io": "^4.6.1",
|
||||
"ws": "^8.13.0"
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
"scripts": {
|
||||
"bundle": "rollup -c",
|
||||
|
||||
4800
package-lock.json
generated
4800
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
15
package.json
15
package.json
@@ -8,14 +8,17 @@
|
||||
"packages/socket.io-cluster-engine",
|
||||
"packages/engine.io-client",
|
||||
"packages/socket.io-adapter",
|
||||
"packages/socket.io-cluster-adapter",
|
||||
"packages/socket.io-parser",
|
||||
"packages/socket.io-client",
|
||||
"packages/socket.io"
|
||||
"packages/socket.io",
|
||||
"packages/socket.io-postgres-emitter",
|
||||
"packages/socket.io-redis-streams-emitter"
|
||||
],
|
||||
"overrides": {
|
||||
"@types/estree": "0.0.52",
|
||||
"@types/lodash": "4.14.189",
|
||||
"ws": "8.17.1"
|
||||
"ws": "8.18.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.24.7",
|
||||
@@ -29,10 +32,13 @@
|
||||
"@rollup/plugin-commonjs": "^26.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.2.3",
|
||||
"@sinonjs/fake-timers": "^11.2.2",
|
||||
"@socket.io/postgres-adapter": "^0.1.0",
|
||||
"@socket.io/redis-streams-adapter": "~0.2.2",
|
||||
"@types/debug": "^4.1.12",
|
||||
"@types/expect.js": "^0.3.32",
|
||||
"@types/mocha": "^10.0.7",
|
||||
"@types/node": "18.15.3",
|
||||
"@types/pg": "^8.6.0",
|
||||
"@types/sinonjs__fake-timers": "^8.1.5",
|
||||
"@wdio/cli": "^8.39.1",
|
||||
"@wdio/local-runner": "^8.39.1",
|
||||
@@ -43,6 +49,7 @@
|
||||
"base64-arraybuffer": "^1.0.2",
|
||||
"benchmark": "^2.1.4",
|
||||
"blob": "^0.1.0",
|
||||
"cookie": "~0.7.2",
|
||||
"eiows": "^7.1.0",
|
||||
"engine.io-client-v3": "npm:engine.io-client@^3.5.2",
|
||||
"expect.js": "^0.3.1",
|
||||
@@ -54,6 +61,7 @@
|
||||
"mocha": "^10.6.0",
|
||||
"node-forge": "^1.3.1",
|
||||
"nyc": "^17.0.0",
|
||||
"pg": "^8.6.0",
|
||||
"prettier": "^3.3.2",
|
||||
"redis": "^4.6.15",
|
||||
"rimraf": "^6.0.0",
|
||||
@@ -68,8 +76,9 @@
|
||||
"ts-loader": "^9.5.1",
|
||||
"ts-node": "^10.9.2",
|
||||
"tsd": "^0.31.1",
|
||||
"tsx": "~4.20.6",
|
||||
"typescript": "^5.5.3",
|
||||
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.48.0",
|
||||
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v20.56.0",
|
||||
"wdio-geckodriver-service": "^5.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +192,7 @@ export abstract class Transport extends Emitter<
|
||||
private _port() {
|
||||
if (
|
||||
this.opts.port &&
|
||||
((this.opts.secure && Number(this.opts.port !== 443)) ||
|
||||
((this.opts.secure && Number(this.opts.port) !== 443) ||
|
||||
(!this.opts.secure && Number(this.opts.port) !== 80))
|
||||
) {
|
||||
return ":" + this.opts.port;
|
||||
|
||||
@@ -53,9 +53,9 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@socket.io/component-emitter": "~3.1.0",
|
||||
"debug": "~4.3.1",
|
||||
"debug": "~4.4.1",
|
||||
"engine.io-parser": "~5.2.1",
|
||||
"ws": "~8.17.1",
|
||||
"ws": "~8.18.3",
|
||||
"xmlhttprequest-ssl": "~2.1.1"
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -116,6 +116,32 @@ describe("Transport", () => {
|
||||
expect(polling.uri()).to.contain("https://localhost/engine.io?sid=test");
|
||||
});
|
||||
|
||||
it("should generate an https uri w/o a port (string)", () => {
|
||||
const polling = new eio.transports.polling({
|
||||
path: "/engine.io",
|
||||
hostname: "localhost",
|
||||
secure: true,
|
||||
query: { sid: "test" },
|
||||
port: "443",
|
||||
timestampRequests: false,
|
||||
});
|
||||
expect(polling.uri()).to.contain("https://localhost/engine.io?sid=test");
|
||||
});
|
||||
|
||||
it("should generate an https uri with a port", () => {
|
||||
const polling = new eio.transports.polling({
|
||||
path: "/engine.io",
|
||||
hostname: "localhost",
|
||||
secure: true,
|
||||
query: { sid: "test" },
|
||||
port: 8443,
|
||||
timestampRequests: false,
|
||||
});
|
||||
expect(polling.uri()).to.contain(
|
||||
"https://localhost:8443/engine.io?sid=test",
|
||||
);
|
||||
});
|
||||
|
||||
it("should generate a timestamped uri", () => {
|
||||
const polling = new eio.transports.polling({
|
||||
path: "/engine.io",
|
||||
|
||||
@@ -53,6 +53,26 @@ async function setup(opts, cb) {
|
||||
cb({ engine, h3Server, certificate });
|
||||
}
|
||||
|
||||
function createHttpServer(port) {
|
||||
const httpServer = createServer();
|
||||
|
||||
let retryCount = 0;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
httpServer.listen(port, () => resolve(httpServer));
|
||||
|
||||
httpServer.on("error", (e) => {
|
||||
if (e.code === "EADDRINUSE" && ++retryCount <= 3) {
|
||||
console.warn("port already in use, retrying...");
|
||||
setTimeout(() => {
|
||||
httpServer.listen(port, () => resolve(httpServer));
|
||||
}, 100);
|
||||
}
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function success(engine, h3server, done) {
|
||||
engine.close();
|
||||
h3server.stopServer();
|
||||
@@ -98,10 +118,9 @@ describe("WebTransport", () => {
|
||||
{
|
||||
transports: ["polling", "webtransport"],
|
||||
},
|
||||
({ engine, h3Server, certificate }) => {
|
||||
const httpServer = createServer();
|
||||
async ({ engine, h3Server, certificate }) => {
|
||||
const httpServer = await createHttpServer(h3Server.port);
|
||||
engine.attach(httpServer);
|
||||
httpServer.listen(h3Server.port);
|
||||
|
||||
const socket = createSocket(h3Server.port, certificate, {
|
||||
transports: ["polling", "webtransport"],
|
||||
@@ -120,10 +139,9 @@ describe("WebTransport", () => {
|
||||
{
|
||||
transports: ["polling", "websocket", "webtransport"],
|
||||
},
|
||||
({ engine, h3Server, certificate }) => {
|
||||
const httpServer = createServer();
|
||||
async ({ engine, h3Server, certificate }) => {
|
||||
const httpServer = await createHttpServer(h3Server.port);
|
||||
engine.attach(httpServer);
|
||||
httpServer.listen(h3Server.port);
|
||||
|
||||
const socket = createSocket(h3Server.port, certificate, {
|
||||
transports: ["polling", "websocket", "webtransport"],
|
||||
|
||||
@@ -32,7 +32,11 @@ export type RawData = any;
|
||||
|
||||
export interface Packet {
|
||||
type: PacketType;
|
||||
options?: { compress: boolean };
|
||||
options?: {
|
||||
compress: boolean;
|
||||
wsPreEncoded?: string; // deprecated in favor of `wsPreEncodedFrame`
|
||||
wsPreEncodedFrame?: any; // computed in the socket.io-adapter package (should be typed as Buffer)
|
||||
};
|
||||
data?: RawData;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"scripts": {
|
||||
"compile": "rimraf ./build && tsc && tsc -p tsconfig.esm.json && ./postcompile.sh",
|
||||
"test": "npm run format:check && npm run compile && if test \"$BROWSERS\" = \"1\" ; then npm run test:browser; else npm run test:node; fi",
|
||||
"test:node": "nyc mocha -r ts-node/register test/index.ts",
|
||||
"test:node": "nyc mocha --import=tsx test/index.ts",
|
||||
"test:browser": "zuul test/index.ts --no-coverage",
|
||||
"format:check": "prettier --check 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"format:fix": "prettier --write 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# History
|
||||
# Changelog
|
||||
|
||||
| Version | Release date |
|
||||
|------------------------------------------------------------------------------------------------------|----------------|
|
||||
| [6.6.5](#665-2025-12-22) | December 2025 |
|
||||
| [6.6.4](#664-2025-01-28) | January 2025 |
|
||||
| [6.6.3](#663-2025-01-23) | January 2025 |
|
||||
| [6.6.2](#662-2024-10-09) | October 2024 |
|
||||
| [6.6.1](#661-2024-09-21) | September 2024 |
|
||||
@@ -46,7 +48,27 @@
|
||||
| [3.4.1](#341-2020-04-17) | April 2020 |
|
||||
|
||||
|
||||
# Release notes
|
||||
## [6.6.5](https://github.com/socketio/socket.io/compare/engine.io@6.6.4...engine.io@6.6.5) (2025-12-22)
|
||||
|
||||
The `url.parse()` function is now deprecated and has been replaced by `new URL()` (see [e08293b](https://github.com/socketio/socket.io/commit/e08293bc3735de5b824b347383e86e0b8ab9fbd5b).
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
- [`ws@~8.18.3`](https://github.com/websockets/ws/releases/tag/8.18.3) ([diff](https://github.com/websockets/ws/compare/8.17.1...8.18.3))
|
||||
|
||||
|
||||
|
||||
## [6.6.4](https://github.com/socketio/socket.io/compare/engine.io@6.6.3...engine.io@6.6.4) (2025-01-28)
|
||||
|
||||
The bump of the `cookie` dependency was reverted, as it drops support for older Node.js versions (< 14).
|
||||
|
||||
|
||||
### Dependencies
|
||||
|
||||
- [`ws@~8.17.1`](https://github.com/websockets/ws/releases/tag/8.17.1) (no change)
|
||||
|
||||
|
||||
|
||||
## [6.6.3](https://github.com/socketio/socket.io/compare/engine.io@6.6.2...engine.io@6.6.3) (2025-01-23)
|
||||
|
||||
|
||||
117
packages/engine.io/lib/contrib/types.cookie.ts
Normal file
117
packages/engine.io/lib/contrib/types.cookie.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
// imported from https://github.com/DefinitelyTyped/DefinitelyTyped/blob/b83cf9ef8b044e69f05b2a00aa7c6cb767a9acd2/types/cookie/index.d.ts (now deleted)
|
||||
/**
|
||||
* Basic HTTP cookie parser and serializer for HTTP servers.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Additional serialization options
|
||||
*/
|
||||
export interface CookieSerializeOptions {
|
||||
/**
|
||||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no
|
||||
* domain is set, and most clients will consider the cookie to apply to only
|
||||
* the current domain.
|
||||
*/
|
||||
domain?: string | undefined;
|
||||
|
||||
/**
|
||||
* Specifies a function that will be used to encode a cookie's value. Since
|
||||
* value of a cookie has a limited character set (and must be a simple
|
||||
* string), this function can be used to encode a value into a string suited
|
||||
* for a cookie's value.
|
||||
*
|
||||
* The default function is the global `encodeURIComponent`, which will
|
||||
* encode a JavaScript string into UTF-8 byte sequences and then URL-encode
|
||||
* any that fall outside of the cookie range.
|
||||
*/
|
||||
encode?(value: string): string;
|
||||
|
||||
/**
|
||||
* Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default,
|
||||
* no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete
|
||||
* it on a condition like exiting a web browser application.
|
||||
*
|
||||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
||||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
||||
* possible not all clients by obey this, so if both are set, they should
|
||||
* point to the same date and time.
|
||||
*/
|
||||
expires?: Date | undefined;
|
||||
/**
|
||||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}.
|
||||
* When truthy, the `HttpOnly` attribute is set, otherwise it is not. By
|
||||
* default, the `HttpOnly` attribute is not set.
|
||||
*
|
||||
* *Note* be careful when setting this to true, as compliant clients will
|
||||
* not allow client-side JavaScript to see the cookie in `document.cookie`.
|
||||
*/
|
||||
httpOnly?: boolean | undefined;
|
||||
/**
|
||||
* Specifies the number (in seconds) to be the value for the `Max-Age`
|
||||
* `Set-Cookie` attribute. The given number will be converted to an integer
|
||||
* by rounding down. By default, no maximum age is set.
|
||||
*
|
||||
* *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification}
|
||||
* states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is
|
||||
* possible not all clients by obey this, so if both are set, they should
|
||||
* point to the same date and time.
|
||||
*/
|
||||
maxAge?: number | undefined;
|
||||
/**
|
||||
* Specifies the `boolean` value for the [`Partitioned` `Set-Cookie`](rfc-cutler-httpbis-partitioned-cookies)
|
||||
* attribute. When truthy, the `Partitioned` attribute is set, otherwise it is not. By default, the
|
||||
* `Partitioned` attribute is not set.
|
||||
*
|
||||
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
||||
* This also means many clients may ignore this attribute until they understand it.
|
||||
*
|
||||
* More information about can be found in [the proposal](https://github.com/privacycg/CHIPS)
|
||||
*/
|
||||
partitioned?: boolean | undefined;
|
||||
/**
|
||||
* Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}.
|
||||
* By default, the path is considered the "default path".
|
||||
*/
|
||||
path?: string | undefined;
|
||||
/**
|
||||
* Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1].
|
||||
*
|
||||
* - `'low'` will set the `Priority` attribute to `Low`.
|
||||
* - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
|
||||
* - `'high'` will set the `Priority` attribute to `High`.
|
||||
*
|
||||
* More information about the different priority levels can be found in
|
||||
* [the specification][rfc-west-cookie-priority-00-4.1].
|
||||
*
|
||||
* **note** This is an attribute that has not yet been fully standardized, and may change in the future.
|
||||
* This also means many clients may ignore this attribute until they understand it.
|
||||
*/
|
||||
priority?: "low" | "medium" | "high" | undefined;
|
||||
/**
|
||||
* Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}.
|
||||
*
|
||||
* - `true` will set the `SameSite` attribute to `Strict` for strict same
|
||||
* site enforcement.
|
||||
* - `false` will not set the `SameSite` attribute.
|
||||
* - `'lax'` will set the `SameSite` attribute to Lax for lax same site
|
||||
* enforcement.
|
||||
* - `'strict'` will set the `SameSite` attribute to Strict for strict same
|
||||
* site enforcement.
|
||||
* - `'none'` will set the SameSite attribute to None for an explicit
|
||||
* cross-site cookie.
|
||||
*
|
||||
* More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}.
|
||||
*
|
||||
* *note* This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
|
||||
*/
|
||||
sameSite?: true | false | "lax" | "strict" | "none" | undefined;
|
||||
/**
|
||||
* Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the
|
||||
* `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set.
|
||||
*
|
||||
* *Note* be careful when setting this to `true`, as compliant clients will
|
||||
* not send the cookie back to the server in the future if the browser does
|
||||
* not have an HTTPS connection.
|
||||
*/
|
||||
secure?: boolean | undefined;
|
||||
}
|
||||
@@ -1,27 +1,36 @@
|
||||
import { createServer } from "http";
|
||||
import { createServer, Server as HttpServer } from "http";
|
||||
import { Server, AttachOptions, ServerOptions } from "./server";
|
||||
import transports from "./transports/index";
|
||||
import * as parser from "engine.io-parser";
|
||||
|
||||
export { Server, transports, listen, attach, parser };
|
||||
export type { AttachOptions, ServerOptions, BaseServer } from "./server";
|
||||
export type {
|
||||
AttachOptions,
|
||||
ServerOptions,
|
||||
BaseServer,
|
||||
ErrorCallback,
|
||||
} from "./server";
|
||||
export { uServer } from "./userver";
|
||||
export { Socket } from "./socket";
|
||||
export { Transport } from "./transport";
|
||||
export const protocol = parser.protocol;
|
||||
|
||||
/**
|
||||
* Creates an http.Server exclusively used for WS upgrades.
|
||||
* Creates an http.Server exclusively used for WS upgrades, and starts listening.
|
||||
*
|
||||
* @param {Number} port
|
||||
* @param {Function} callback
|
||||
* @param {Object} options
|
||||
* @return {Server} websocket.io server
|
||||
* @param port
|
||||
* @param options
|
||||
* @param listenCallback - callback for http.Server.listen()
|
||||
* @return engine.io server
|
||||
*/
|
||||
|
||||
function listen(port, options: AttachOptions & ServerOptions, fn) {
|
||||
function listen(
|
||||
port: number,
|
||||
options?: AttachOptions & ServerOptions,
|
||||
listenCallback?: () => void,
|
||||
): Server {
|
||||
if ("function" === typeof options) {
|
||||
fn = options;
|
||||
listenCallback = options;
|
||||
options = {};
|
||||
}
|
||||
|
||||
@@ -34,7 +43,7 @@ function listen(port, options: AttachOptions & ServerOptions, fn) {
|
||||
const engine = attach(server, options);
|
||||
engine.httpServer = server;
|
||||
|
||||
server.listen(port, fn);
|
||||
server.listen(port, listenCallback);
|
||||
|
||||
return engine;
|
||||
}
|
||||
@@ -42,12 +51,15 @@ function listen(port, options: AttachOptions & ServerOptions, fn) {
|
||||
/**
|
||||
* Captures upgrade requests for a http.Server.
|
||||
*
|
||||
* @param {http.Server} server
|
||||
* @param {Object} options
|
||||
* @return {Server} engine server
|
||||
* @param server
|
||||
* @param options
|
||||
* @return engine.io server
|
||||
*/
|
||||
|
||||
function attach(server, options: AttachOptions & ServerOptions) {
|
||||
function attach(
|
||||
server: HttpServer,
|
||||
options: AttachOptions & ServerOptions,
|
||||
): Server {
|
||||
const engine = new Server(options);
|
||||
engine.attach(server, options);
|
||||
return engine;
|
||||
|
||||
@@ -59,8 +59,7 @@ const EMPTY_BUFFER = Buffer.concat([]);
|
||||
*
|
||||
* @api private
|
||||
*/
|
||||
|
||||
export function encodePacket (packet, supportsBinary, utf8encode, callback) {
|
||||
export function encodePacket (packet: any, supportsBinary?: any, utf8encode?: any, callback?: any) {
|
||||
if (typeof supportsBinary === 'function') {
|
||||
callback = supportsBinary;
|
||||
supportsBinary = null;
|
||||
@@ -86,7 +85,7 @@ export function encodePacket (packet, supportsBinary, utf8encode, callback) {
|
||||
}
|
||||
|
||||
return callback('' + encoded);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode Buffer data
|
||||
@@ -120,16 +119,16 @@ export function encodeBase64Packet (packet, callback){
|
||||
/**
|
||||
* Decodes a packet. Data also available as an ArrayBuffer if requested.
|
||||
*
|
||||
* @return {Object} with `type` and `data` (if any)
|
||||
* @return {import('engine.io-parser').Packet} with `type` and `data` (if any)
|
||||
* @api private
|
||||
*/
|
||||
|
||||
export function decodePacket (data, binaryType, utf8decode) {
|
||||
export function decodePacket (data: any, binaryType?: any, utf8decode?: any): any {
|
||||
if (data === undefined) {
|
||||
return err;
|
||||
}
|
||||
|
||||
var type;
|
||||
let type: string | number;
|
||||
|
||||
// String data
|
||||
if (typeof data === 'string') {
|
||||
@@ -147,6 +146,7 @@ export function decodePacket (data, binaryType, utf8decode) {
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
if (Number(type) != type || !packetslist[type]) {
|
||||
return err;
|
||||
}
|
||||
@@ -274,7 +274,7 @@ function map(ary, each, done) {
|
||||
* @api public
|
||||
*/
|
||||
|
||||
export function decodePayload (data, binaryType, callback) {
|
||||
export function decodePayload (data: any, binaryType?: any, callback?: any) {
|
||||
if (typeof data !== 'string') {
|
||||
return decodePayloadAsBinary(data, binaryType, callback);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import * as qs from "querystring";
|
||||
import { parse } from "url";
|
||||
import * as base64id from "base64id";
|
||||
import transports from "./transports";
|
||||
import { EventEmitter } from "events";
|
||||
import { Socket } from "./socket";
|
||||
import debugModule from "debug";
|
||||
import { serialize } from "cookie";
|
||||
import type { SerializeOptions } from "cookie";
|
||||
import { Server as DEFAULT_WS_ENGINE } from "ws";
|
||||
import {
|
||||
Server as DEFAULT_WS_ENGINE,
|
||||
type Server as WsServer,
|
||||
type PerMessageDeflateOptions,
|
||||
type WebSocket as WsWebSocket,
|
||||
} from "ws";
|
||||
import type {
|
||||
IncomingMessage,
|
||||
Server as HttpServer,
|
||||
@@ -17,13 +19,19 @@ import type { CorsOptions, CorsOptionsDelegate } from "cors";
|
||||
import type { Duplex } from "stream";
|
||||
import { WebTransport } from "./transports/webtransport";
|
||||
import { createPacketDecoderStream } from "engine.io-parser";
|
||||
import type { EngineRequest } from "./transport";
|
||||
import type { EngineRequest, Transport } from "./transport";
|
||||
import type { CookieSerializeOptions } from "./contrib/types.cookie";
|
||||
|
||||
const debug = debugModule("engine");
|
||||
|
||||
const kResponseHeaders = Symbol("responseHeaders");
|
||||
|
||||
type Transport = "polling" | "websocket" | "webtransport";
|
||||
type TransportName = "polling" | "websocket" | "webtransport";
|
||||
|
||||
export type ErrorCallback = (
|
||||
errorCode?: (typeof Server.errors)[keyof typeof Server.errors],
|
||||
errorContext?: Record<string, unknown> & { name?: string; message?: string },
|
||||
) => void;
|
||||
|
||||
export interface AttachOptions {
|
||||
/**
|
||||
@@ -90,7 +98,7 @@ export interface ServerOptions {
|
||||
*
|
||||
* @default ["polling", "websocket"]
|
||||
*/
|
||||
transports?: Transport[];
|
||||
transports?: TransportName[];
|
||||
/**
|
||||
* whether to allow transport upgrades
|
||||
* @default true
|
||||
@@ -100,7 +108,7 @@ export interface ServerOptions {
|
||||
* parameters of the WebSocket permessage-deflate extension (see ws module api docs). Set to false to disable.
|
||||
* @default false
|
||||
*/
|
||||
perMessageDeflate?: boolean | object;
|
||||
perMessageDeflate?: boolean | PerMessageDeflateOptions;
|
||||
/**
|
||||
* parameters of the http compression for the polling transports (see zlib api docs). Set to false to disable.
|
||||
* @default true
|
||||
@@ -123,7 +131,7 @@ export interface ServerOptions {
|
||||
* might be used for sticky-session. Defaults to not sending any cookie.
|
||||
* @default false
|
||||
*/
|
||||
cookie?: (SerializeOptions & { name: string }) | boolean;
|
||||
cookie?: (CookieSerializeOptions & { name: string }) | boolean;
|
||||
/**
|
||||
* the options that will be forwarded to the cors module
|
||||
*/
|
||||
@@ -149,7 +157,7 @@ type Middleware = (
|
||||
next: (err?: any) => void,
|
||||
) => void;
|
||||
|
||||
function parseSessionId(data: string) {
|
||||
function parseSessionId(data: string): string | undefined {
|
||||
try {
|
||||
const parsed = JSON.parse(data);
|
||||
if (typeof parsed.sid === "string") {
|
||||
@@ -224,7 +232,7 @@ export abstract class BaseServer extends EventEmitter {
|
||||
this.init();
|
||||
}
|
||||
|
||||
protected abstract init();
|
||||
protected abstract init(): void;
|
||||
|
||||
/**
|
||||
* Compute the pathname of the requests that are handled by the server
|
||||
@@ -244,10 +252,8 @@ export abstract class BaseServer extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Returns a list of available transports for upgrade given a certain transport.
|
||||
*
|
||||
* @return {Array}
|
||||
*/
|
||||
public upgrades(transport: string) {
|
||||
public upgrades(transport: TransportName): string[] {
|
||||
if (!this.opts.allowUpgrades) return [];
|
||||
return transports[transport].upgradesTo || [];
|
||||
}
|
||||
@@ -259,17 +265,18 @@ export abstract class BaseServer extends EventEmitter {
|
||||
* @param upgrade - whether it's an upgrade request
|
||||
* @param fn
|
||||
* @protected
|
||||
* @return whether the request is valid
|
||||
*/
|
||||
protected verify(
|
||||
req: any,
|
||||
req: EngineRequest,
|
||||
upgrade: boolean,
|
||||
fn: (errorCode?: number, errorContext?: any) => void,
|
||||
) {
|
||||
fn: ErrorCallback,
|
||||
): void | boolean {
|
||||
// transport check
|
||||
const transport = req._query.transport;
|
||||
// WebTransport does not go through the verify() method, see the onWebTransportSession() method
|
||||
if (
|
||||
!~this.opts.transports.indexOf(transport) ||
|
||||
!~this.opts.transports.indexOf(transport as TransportName) ||
|
||||
transport === "webtransport"
|
||||
) {
|
||||
debug('unknown transport "%s"', transport);
|
||||
@@ -408,7 +415,7 @@ export abstract class BaseServer extends EventEmitter {
|
||||
*
|
||||
* @param {IncomingMessage} req - the request object
|
||||
*/
|
||||
public generateId(req: IncomingMessage) {
|
||||
public generateId(req: IncomingMessage): string | PromiseLike<string> {
|
||||
return base64id.generateId();
|
||||
}
|
||||
|
||||
@@ -422,9 +429,9 @@ export abstract class BaseServer extends EventEmitter {
|
||||
* @protected
|
||||
*/
|
||||
protected async handshake(
|
||||
transportName: string,
|
||||
req: any,
|
||||
closeConnection: (errorCode?: number, errorContext?: any) => void,
|
||||
transportName: TransportName,
|
||||
req: EngineRequest,
|
||||
closeConnection: ErrorCallback,
|
||||
) {
|
||||
const protocol = req._query.EIO === "4" ? 4 : 3; // 3rd revision by default
|
||||
if (protocol === 3 && !this.opts.allowEIO3) {
|
||||
@@ -600,7 +607,10 @@ export abstract class BaseServer extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract createTransport(transportName, req);
|
||||
protected abstract createTransport(
|
||||
transportName: TransportName,
|
||||
req: EngineRequest,
|
||||
);
|
||||
|
||||
/**
|
||||
* Protocol errors mappings.
|
||||
@@ -613,7 +623,7 @@ export abstract class BaseServer extends EventEmitter {
|
||||
BAD_REQUEST: 3,
|
||||
FORBIDDEN: 4,
|
||||
UNSUPPORTED_PROTOCOL_VERSION: 5,
|
||||
};
|
||||
} as const;
|
||||
|
||||
static errorMessages = {
|
||||
0: "Transport unknown",
|
||||
@@ -622,7 +632,7 @@ export abstract class BaseServer extends EventEmitter {
|
||||
3: "Bad request",
|
||||
4: "Forbidden",
|
||||
5: "Unsupported protocol version",
|
||||
};
|
||||
} as const;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -667,7 +677,7 @@ class WebSocketResponse {
|
||||
*/
|
||||
export class Server extends BaseServer {
|
||||
public httpServer?: HttpServer;
|
||||
private ws: any;
|
||||
private ws: WsServer;
|
||||
|
||||
/**
|
||||
* Initialize websocket server
|
||||
@@ -687,7 +697,7 @@ export class Server extends BaseServer {
|
||||
});
|
||||
|
||||
if (typeof this.ws.on === "function") {
|
||||
this.ws.on("headers", (headersArray, req) => {
|
||||
this.ws.on("headers", (headersArray, req: EngineRequest) => {
|
||||
// note: 'ws' uses an array of headers, while Engine.IO uses an object (response.writeHead() accepts both formats)
|
||||
// we could also try to parse the array and then sync the values, but that will be error-prone
|
||||
const additionalHeaders = req[kResponseHeaders] || {};
|
||||
@@ -724,13 +734,16 @@ export class Server extends BaseServer {
|
||||
private prepare(req: EngineRequest) {
|
||||
// try to leverage pre-existing `req._query` (e.g: from connect)
|
||||
if (!req._query) {
|
||||
req._query = (
|
||||
~req.url.indexOf("?") ? qs.parse(parse(req.url).query) : {}
|
||||
) as Record<string, string>;
|
||||
const url = new URL(req.url, "https://socket.io");
|
||||
req._query = Object.fromEntries(url.searchParams.entries());
|
||||
}
|
||||
}
|
||||
|
||||
protected createTransport(transportName: string, req: IncomingMessage) {
|
||||
protected createTransport(
|
||||
transportName: TransportName,
|
||||
req: IncomingMessage,
|
||||
): Transport {
|
||||
// @ts-expect-error 'polling' is a plain function used as constructor
|
||||
return new transports[transportName](req);
|
||||
}
|
||||
|
||||
@@ -745,7 +758,7 @@ export class Server extends BaseServer {
|
||||
this.prepare(req);
|
||||
req.res = res;
|
||||
|
||||
const callback = (errorCode, errorContext) => {
|
||||
const callback: ErrorCallback = (errorCode, errorContext) => {
|
||||
if (errorCode !== undefined) {
|
||||
this.emit("connection_error", {
|
||||
req,
|
||||
@@ -763,7 +776,11 @@ export class Server extends BaseServer {
|
||||
} else {
|
||||
const closeConnection = (errorCode, errorContext) =>
|
||||
abortRequest(res, errorCode, errorContext);
|
||||
this.handshake(req._query.transport, req, closeConnection);
|
||||
this.handshake(
|
||||
req._query.transport as TransportName,
|
||||
req,
|
||||
closeConnection,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -787,7 +804,7 @@ export class Server extends BaseServer {
|
||||
this.prepare(req);
|
||||
|
||||
const res = new WebSocketResponse(req, socket);
|
||||
const callback = (errorCode, errorContext) => {
|
||||
const callback: ErrorCallback = (errorCode, errorContext) => {
|
||||
if (errorCode !== undefined) {
|
||||
this.emit("connection_error", {
|
||||
req,
|
||||
@@ -823,11 +840,16 @@ export class Server extends BaseServer {
|
||||
|
||||
/**
|
||||
* Called upon a ws.io connection.
|
||||
*
|
||||
* @param {ws.Socket} websocket
|
||||
* @param req
|
||||
* @param socket
|
||||
* @param websocket
|
||||
* @private
|
||||
*/
|
||||
private onWebSocket(req, socket, websocket) {
|
||||
private onWebSocket(
|
||||
req: EngineRequest,
|
||||
socket: Duplex,
|
||||
websocket: WsWebSocket,
|
||||
) {
|
||||
websocket.on("error", onUpgradeError);
|
||||
|
||||
if (
|
||||
@@ -862,14 +884,22 @@ export class Server extends BaseServer {
|
||||
// transport error handling takes over
|
||||
websocket.removeListener("error", onUpgradeError);
|
||||
|
||||
const transport = this.createTransport(req._query.transport, req);
|
||||
const transport = this.createTransport(
|
||||
req._query.transport as TransportName,
|
||||
req,
|
||||
);
|
||||
// @ts-expect-error this option is only for WebSocket impl
|
||||
transport.perMessageDeflate = this.opts.perMessageDeflate;
|
||||
client._maybeUpgrade(transport);
|
||||
}
|
||||
} else {
|
||||
const closeConnection = (errorCode, errorContext) =>
|
||||
abortUpgrade(socket, errorCode, errorContext);
|
||||
this.handshake(req._query.transport, req, closeConnection);
|
||||
this.handshake(
|
||||
req._query.transport as TransportName,
|
||||
req,
|
||||
closeConnection,
|
||||
);
|
||||
}
|
||||
|
||||
function onUpgradeError() {
|
||||
@@ -947,7 +977,11 @@ export class Server extends BaseServer {
|
||||
* @private
|
||||
*/
|
||||
|
||||
function abortRequest(res, errorCode, errorContext) {
|
||||
function abortRequest(
|
||||
res: ServerResponse,
|
||||
errorCode: number,
|
||||
errorContext?: { message?: string },
|
||||
) {
|
||||
const statusCode = errorCode === Server.errors.FORBIDDEN ? 403 : 400;
|
||||
const message =
|
||||
errorContext && errorContext.message
|
||||
@@ -1030,7 +1064,7 @@ const validHdrChars = [
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // ... 255
|
||||
]
|
||||
|
||||
function checkInvalidHeaderChar(val) {
|
||||
function checkInvalidHeaderChar(val?: string) {
|
||||
val += "";
|
||||
if (val.length < 1) return false;
|
||||
if (!validHdrChars[val.charCodeAt(0)]) {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { EngineRequest, Transport } from "./transport";
|
||||
import type { BaseServer } from "./server";
|
||||
import { setTimeout, clearTimeout } from "timers";
|
||||
import type { Packet, PacketType, RawData } from "engine.io-parser";
|
||||
import type transports from "./transports";
|
||||
|
||||
const debug = debugModule("engine:socket");
|
||||
|
||||
@@ -537,9 +538,11 @@ export class Socket extends EventEmitter {
|
||||
*/
|
||||
private getAvailableUpgrades() {
|
||||
const availableUpgrades = [];
|
||||
const allUpgrades = this.server.upgrades(this.transport.name);
|
||||
const allUpgrades = this.server.upgrades(
|
||||
this.transport.name as keyof typeof transports,
|
||||
);
|
||||
for (let i = 0; i < allUpgrades.length; ++i) {
|
||||
const upg = allUpgrades[i];
|
||||
const upg = allUpgrades[i] as keyof typeof transports;
|
||||
if (this.server.opts.transports.indexOf(upg) !== -1) {
|
||||
availableUpgrades.push(upg);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import * as parser_v3 from "./parser-v3/index";
|
||||
import debugModule from "debug";
|
||||
import type { IncomingMessage, ServerResponse } from "http";
|
||||
import { Packet, RawData } from "engine.io-parser";
|
||||
import type { WebSocket } from "ws";
|
||||
|
||||
const debug = debugModule("engine:transport");
|
||||
|
||||
@@ -15,7 +16,11 @@ export type EngineRequest = IncomingMessage & {
|
||||
_query: Record<string, string>;
|
||||
res?: ServerResponse;
|
||||
cleanup?: Function;
|
||||
websocket?: any;
|
||||
websocket?: WebSocket & {
|
||||
_socket?: {
|
||||
remoteAddress: string;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export abstract class Transport extends EventEmitter {
|
||||
@@ -37,7 +42,7 @@ export abstract class Transport extends EventEmitter {
|
||||
*
|
||||
* @see https://github.com/socketio/engine.io-protocol
|
||||
*/
|
||||
public protocol: number;
|
||||
public protocol: 3 | 4;
|
||||
|
||||
/**
|
||||
* The current state of the transport.
|
||||
@@ -53,7 +58,7 @@ export abstract class Transport extends EventEmitter {
|
||||
* The parser to use (depends on the revision of the {@link Transport#protocol}.
|
||||
* @protected
|
||||
*/
|
||||
protected parser: any;
|
||||
protected parser: typeof parser_v4 | typeof parser_v3;
|
||||
/**
|
||||
* Whether the transport supports binary payloads (else it will be base64-encoded)
|
||||
* @protected
|
||||
@@ -74,6 +79,11 @@ export abstract class Transport extends EventEmitter {
|
||||
this._readyState = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of transports this transport can be upgraded to.
|
||||
*/
|
||||
static upgradesTo: string[] = [];
|
||||
|
||||
/**
|
||||
* Transport constructor.
|
||||
*
|
||||
@@ -148,7 +158,7 @@ export abstract class Transport extends EventEmitter {
|
||||
/**
|
||||
* Called with the encoded packet data.
|
||||
*
|
||||
* @param {String} data
|
||||
* @param data
|
||||
* @protected
|
||||
*/
|
||||
protected onData(data: RawData) {
|
||||
|
||||
@@ -3,6 +3,8 @@ import { createGzip, createDeflate } from "zlib";
|
||||
import * as accepts from "accepts";
|
||||
import debugModule from "debug";
|
||||
import { HttpRequest, HttpResponse } from "uWebSockets.js";
|
||||
import type * as parser_v4 from "engine.io-parser";
|
||||
import type * as parser_v3 from "../parser-v3/index";
|
||||
|
||||
const debug = debugModule("engine:polling");
|
||||
|
||||
@@ -228,9 +230,9 @@ export class Polling extends Transport {
|
||||
};
|
||||
|
||||
if (this.protocol === 3) {
|
||||
this.parser.decodePayload(data, callback);
|
||||
(this.parser as typeof parser_v3).decodePayload(data, callback);
|
||||
} else {
|
||||
this.parser.decodePayload(data).forEach(callback);
|
||||
(this.parser as typeof parser_v4).decodePayload(data).forEach(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,7 +265,7 @@ export class Polling extends Transport {
|
||||
this.shouldClose = null;
|
||||
}
|
||||
|
||||
const doWrite = (data) => {
|
||||
const doWrite = (data: string) => {
|
||||
const compress = packets.some((packet) => {
|
||||
return packet.options && packet.options.compress;
|
||||
});
|
||||
@@ -271,9 +273,13 @@ export class Polling extends Transport {
|
||||
};
|
||||
|
||||
if (this.protocol === 3) {
|
||||
this.parser.encodePayload(packets, this.supportsBinary, doWrite);
|
||||
(this.parser as typeof parser_v3).encodePayload(
|
||||
packets,
|
||||
this.supportsBinary,
|
||||
doWrite,
|
||||
);
|
||||
} else {
|
||||
this.parser.encodePayload(packets, doWrite);
|
||||
(this.parser as typeof parser_v4).encodePayload(packets, doWrite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ import { Polling as XHR } from "./polling";
|
||||
import { JSONP } from "./polling-jsonp";
|
||||
import { WebSocket } from "./websocket";
|
||||
import { WebTransport } from "./webtransport";
|
||||
import type { EngineRequest } from "../transport";
|
||||
|
||||
export default {
|
||||
polling: polling,
|
||||
polling,
|
||||
websocket: WebSocket,
|
||||
webtransport: WebTransport,
|
||||
};
|
||||
@@ -12,8 +13,7 @@ export default {
|
||||
/**
|
||||
* Polling polymorphic constructor.
|
||||
*/
|
||||
|
||||
function polling(req) {
|
||||
function polling(req: EngineRequest) {
|
||||
if ("string" === typeof req._query.j) {
|
||||
return new JSONP(req);
|
||||
} else {
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as accepts from "accepts";
|
||||
import debugModule from "debug";
|
||||
import type { IncomingMessage, ServerResponse } from "http";
|
||||
import type { Packet, RawData } from "engine.io-parser";
|
||||
import type * as parser_v4 from "engine.io-parser";
|
||||
import type * as parser_v3 from "../parser-v3/index";
|
||||
|
||||
const debug = debugModule("engine:polling");
|
||||
|
||||
@@ -196,9 +198,9 @@ export class Polling extends Transport {
|
||||
};
|
||||
|
||||
if (this.protocol === 3) {
|
||||
this.parser.decodePayload(data, callback);
|
||||
(this.parser as typeof parser_v3).decodePayload(data, callback);
|
||||
} else {
|
||||
this.parser.decodePayload(data).forEach(callback);
|
||||
(this.parser as typeof parser_v4).decodePayload(data).forEach(callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +227,7 @@ export class Polling extends Transport {
|
||||
this.shouldClose = null;
|
||||
}
|
||||
|
||||
const doWrite = (data) => {
|
||||
const doWrite = (data: string) => {
|
||||
const compress = packets.some((packet) => {
|
||||
return packet.options && packet.options.compress;
|
||||
});
|
||||
@@ -233,9 +235,13 @@ export class Polling extends Transport {
|
||||
};
|
||||
|
||||
if (this.protocol === 3) {
|
||||
this.parser.encodePayload(packets, this.supportsBinary, doWrite);
|
||||
(this.parser as typeof parser_v3).encodePayload(
|
||||
packets,
|
||||
this.supportsBinary,
|
||||
doWrite,
|
||||
);
|
||||
} else {
|
||||
this.parser.encodePayload(packets, doWrite);
|
||||
(this.parser as typeof parser_v4).encodePayload(packets, doWrite);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
import { EngineRequest, Transport } from "../transport";
|
||||
import debugModule from "debug";
|
||||
import type { Packet, RawData } from "engine.io-parser";
|
||||
import type { PerMessageDeflateOptions, WebSocket as WsWebSocket } from "ws";
|
||||
|
||||
const debug = debugModule("engine:ws");
|
||||
|
||||
export class WebSocket extends Transport {
|
||||
protected perMessageDeflate: any;
|
||||
private socket: any;
|
||||
perMessageDeflate?: boolean | PerMessageDeflateOptions;
|
||||
private socket: WsWebSocket;
|
||||
|
||||
/**
|
||||
* WebSocket transport
|
||||
@@ -51,8 +52,8 @@ export class WebSocket extends Transport {
|
||||
if (this._canSendPreEncodedFrame(packet)) {
|
||||
// the WebSocket frame was computed with WebSocket.Sender.frame()
|
||||
// see https://github.com/websockets/ws/issues/617#issuecomment-283002469
|
||||
// @ts-expect-error use of untyped member
|
||||
this.socket._sender.sendFrame(
|
||||
// @ts-ignore
|
||||
packet.options.wsPreEncodedFrame,
|
||||
isLast ? this._onSentLast : this._onSent,
|
||||
);
|
||||
@@ -74,8 +75,8 @@ export class WebSocket extends Transport {
|
||||
private _canSendPreEncodedFrame(packet: Packet) {
|
||||
return (
|
||||
!this.perMessageDeflate &&
|
||||
// @ts-expect-error use of untyped member
|
||||
typeof this.socket?._sender?.sendFrame === "function" &&
|
||||
// @ts-ignore
|
||||
packet.options?.wsPreEncodedFrame !== undefined
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import debugModule from "debug";
|
||||
import { AttachOptions, BaseServer, Server } from "./server";
|
||||
import { HttpRequest, HttpResponse, TemplatedApp } from "uWebSockets.js";
|
||||
import transports from "./transports-uws";
|
||||
import { EngineRequest } from "./transport";
|
||||
|
||||
const debug = debugModule("engine:uws");
|
||||
|
||||
@@ -36,7 +37,7 @@ export class uServer extends BaseServer {
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private prepare(req, res: HttpResponse) {
|
||||
private prepare(req: HttpRequest & EngineRequest, res: HttpResponse) {
|
||||
req.method = req.getMethod().toUpperCase();
|
||||
req.url = req.getUrl();
|
||||
|
||||
@@ -48,6 +49,7 @@ export class uServer extends BaseServer {
|
||||
req.headers[key] = value;
|
||||
});
|
||||
|
||||
// @ts-expect-error
|
||||
req.connection = {
|
||||
remoteAddress: Buffer.from(res.getRemoteAddressAsText()).toString(),
|
||||
};
|
||||
@@ -57,7 +59,7 @@ export class uServer extends BaseServer {
|
||||
});
|
||||
}
|
||||
|
||||
protected createTransport(transportName, req) {
|
||||
protected createTransport(transportName: string, req: EngineRequest) {
|
||||
return new transports[transportName](req);
|
||||
}
|
||||
|
||||
@@ -123,7 +125,7 @@ export class uServer extends BaseServer {
|
||||
req: HttpRequest & { res: any; _query: any },
|
||||
) {
|
||||
debug('handling "%s" http request "%s"', req.getMethod(), req.getUrl());
|
||||
this.prepare(req, res);
|
||||
this.prepare(req as unknown as HttpRequest & EngineRequest, res);
|
||||
|
||||
req.res = res;
|
||||
|
||||
@@ -146,7 +148,11 @@ export class uServer extends BaseServer {
|
||||
} else {
|
||||
const closeConnection = (errorCode, errorContext) =>
|
||||
this.abortRequest(res, errorCode, errorContext);
|
||||
this.handshake(req._query.transport, req, closeConnection);
|
||||
this.handshake(
|
||||
req._query.transport,
|
||||
req as unknown as EngineRequest,
|
||||
closeConnection,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -154,7 +160,11 @@ export class uServer extends BaseServer {
|
||||
if (err) {
|
||||
callback(Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" });
|
||||
} else {
|
||||
this.verify(req, false, callback);
|
||||
this.verify(
|
||||
req as unknown as HttpRequest & EngineRequest,
|
||||
false,
|
||||
callback,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -166,7 +176,7 @@ export class uServer extends BaseServer {
|
||||
) {
|
||||
debug("on upgrade");
|
||||
|
||||
this.prepare(req, res);
|
||||
this.prepare(req as unknown as HttpRequest & EngineRequest, res);
|
||||
|
||||
req.res = res;
|
||||
|
||||
@@ -198,13 +208,16 @@ export class uServer extends BaseServer {
|
||||
return res.close();
|
||||
} else {
|
||||
debug("upgrading existing transport");
|
||||
transport = this.createTransport(req._query.transport, req);
|
||||
transport = this.createTransport(
|
||||
req._query.transport,
|
||||
req as unknown as EngineRequest,
|
||||
);
|
||||
client._maybeUpgrade(transport);
|
||||
}
|
||||
} else {
|
||||
transport = await this.handshake(
|
||||
req._query.transport,
|
||||
req,
|
||||
req as unknown as EngineRequest,
|
||||
(errorCode, errorContext) =>
|
||||
this.abortRequest(res, errorCode, errorContext),
|
||||
);
|
||||
@@ -231,15 +244,15 @@ export class uServer extends BaseServer {
|
||||
if (err) {
|
||||
callback(Server.errors.BAD_REQUEST, { name: "MIDDLEWARE_FAILURE" });
|
||||
} else {
|
||||
this.verify(req, true, callback);
|
||||
this.verify(req as unknown as EngineRequest, true, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private abortRequest(
|
||||
res: HttpResponse | ResponseWrapper,
|
||||
errorCode,
|
||||
errorContext,
|
||||
errorCode: number,
|
||||
errorContext?: { message?: string },
|
||||
) {
|
||||
const statusCode =
|
||||
errorCode === Server.errors.FORBIDDEN
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "engine.io",
|
||||
"version": "6.6.3",
|
||||
"version": "6.6.5",
|
||||
"description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server",
|
||||
"type": "commonjs",
|
||||
"main": "./build/engine.io.js",
|
||||
@@ -35,11 +35,11 @@
|
||||
"@types/node": ">=10.0.0",
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "2.0.0",
|
||||
"cookie": "~1.0.2",
|
||||
"cookie": "~0.7.2",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.1",
|
||||
"debug": "~4.4.1",
|
||||
"engine.io-parser": "~5.2.1",
|
||||
"ws": "~8.17.1"
|
||||
"ws": "~8.18.3"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "rimraf ./build && tsc",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
if (process.env.EIO_CLIENT === "3" && process.versions.node.startsWith("22")) {
|
||||
// FIXME WebSocket error with engine.io-client@3
|
||||
if (process.env.EIO_CLIENT === "3") {
|
||||
// we need the WebSocket object provided by the "ws" library to test the SSL certs and HTTP headers so we hide the now built-in WebSocket constructor
|
||||
// ref: https://nodejs.org/api/globals.html#class-websocket
|
||||
global.WebSocket = null;
|
||||
}
|
||||
|
||||
|
||||
48
packages/engine.io/test/fixtures/ca.crt
vendored
48
packages/engine.io/test/fixtures/ca.crt
vendored
@@ -1,33 +1,19 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIFtTCCA52gAwIBAgIJAJKBPV3nMXjsMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
|
||||
BAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRlcm5ldCBX
|
||||
aWRnaXRzIFB0eSBMdGQwHhcNMTUxMTE4MTczODAwWhcNMjUxMTE1MTczODAwWjBF
|
||||
MQswCQYDVQQGEwJBVTETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50
|
||||
ZXJuZXQgV2lkZ2l0cyBQdHk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4n3lK6uCbemv9Gdk/U99ev8LAGg2SkZAZXBpDrdZepkA84ehUHu5u7PHlXNodE
|
||||
KL7DLKsvoaYYiQ5rLyBYieDOYqtYJxtfLOeh+tmnNa+G4chpYzkll7OCeEQhbocQ
|
||||
QLdP8novscoSibp6bPmoVsat8RRru0CK9ND1v+FvJ2R7Lz2isBIr+p9ZrkYkIXa3
|
||||
OqN3wacZ+doYfAC/a4SK64Jgv+Lz6wuzsc7XVjBGEEaa1P1zd2rh70wNm8Lgmwr/
|
||||
Oq1Lv7Lg3plXY7e/7V915p96/bxbIiVHiu1JAgMBAAGjUzBRMB0GA1UdDgQWBBRN
|
||||
SIfG8SbjQTQCuymcNnQh4R5oxDAfBgNVHSMEGDAWgBRNSIfG8SbjQTQCuymcNnQh
|
||||
4R5oxDAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQADHV/KfXlN
|
||||
ZBmjWWqQRCmJCUsFkn29C0RQQMILbxYkNl08DuSQw68+PsA2YeB4aUikmW5sRHYF
|
||||
TgLXxgZ+aaGH4WtedumD4RGodcFbxI2WLIilKD4nH0FmB4I9bkULgMyyOZ0g+Vc7
|
||||
ekynqzYtzQBgK+HLWtIWZRTM/BR5IAzt/SdAVoQwL3EHzlc57Q9rRqYeBiyse3lC
|
||||
8Ojb9ZLhwv/hihWNd+mFKeWzLAGJIB439AUzKcg96YDKB3Nwosa16g0xslwxvAL/
|
||||
cKJQ3mh7pIOX3iv9YV/uifRvdCiI/e2p00YjZiS3ggdravSGjLLypw6HFH3hFnw7
|
||||
2ZzA88NgFQXi
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
79
packages/engine.io/test/fixtures/ca.key
vendored
79
packages/engine.io/test/fixtures/ca.key
vendored
@@ -1,51 +1,28 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIJKQIBAAKCAgEAmNWKTumE1f+ptArhPTOcaUReoqBlri/ujIzm1N8Qr0hghS6B
|
||||
8eXGngASYM7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fRdPzXWN7274zosNxUpPeft9Dq44YQYX6R
|
||||
gUJ39QnmUVDwBVwFSw1ZgQjBvZJTr0sp4iBb9hEGhSLlpnrA4qZZQC28A+eKkmTu
|
||||
QR0qMPjlqiacfFISBJwCSll26wKBgQDY2ziwueYuQuNy/jJ8+lFKvIMrv34+Htp/
|
||||
ZNGxDN1Fthq9JRHUP4KL9UIVGlgIt6hwgOXIR0dw2pt7ffF1SiDST/PvBe5Allex
|
||||
uvGfTeh0kTv6T/JAPnqBS5uM3fCnQaF/bbTllw4elKHB4liysh+Gq5svU7mV7Xop
|
||||
1RmGKn6HmwKBgQC791u0uEH1mpdDOdFuvE2CKj6n30gER9e+xuMgINLAJt6xcVGn
|
||||
KsgdTQzCs7nnrcuPyIdoASdi2DP7/QYZZLWxY6JLLC0lZHYcOKDQu11WYx6slLNS
|
||||
hrfngrwhT+lBL295HrKv3GsSpFzdl3IlvKi+pTFRXP/WfDBs4qbq0F+AzwKBgDcB
|
||||
5K9veGPjs65HrKbnGBfNGbjPKka3rNUDze0LRlWYi8/Ox2b/dS3rWIfh1tLfQ2rG
|
||||
R4M2EXke+rGokMcftpOilE3dQ0I+4J/Eu+Wc7YokDQLBpMGHF6wUcbCZ26GRlFWu
|
||||
jmRunLZFHYMA1178r+KJRSQMKNdPFd3moELYJKBhAoGBALAJg2x1B1TpLvJf3iI3
|
||||
BeuASfYKpp3X3cyUy0ojxdYIEHHZ87TINojldHVd+t+80M8FG7YgQNTWtx0Wz587
|
||||
EslppRo2r8qusax9KjaZ1uf04jWxR/v88dvpspSi3IV/J3rNhf3xz1gEFdRXvtQc
|
||||
Ek+aWNHKp5nqpuY6HWUacI96
|
||||
-----END PRIVATE KEY-----
|
||||
|
||||
54
packages/engine.io/test/fixtures/ca.key.org
vendored
54
packages/engine.io/test/fixtures/ca.key.org
vendored
@@ -1,54 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-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qqfKYEGMHc984XnTUAPBAsjFoGYQ65JmhvFva
|
||||
aDMa8GeMzNMdYNTsJljhYbKlELGMhurJJ7ckkAg6UKQrpUQ7FwmBpU+zaDHKPQ6h
|
||||
8acak5aJfC/OtIpnPDYTBcC3zLNEOvs2QDtjKSVYK7/6AcD9tiYjo0Q95F1aex+M
|
||||
uqp0yoL83Oq/KxPnkGMo67ukON66Xt8hrSgVIVzL4PX5Xl1PtLSN4lleNN69S7ic
|
||||
-----END RSA PRIVATE KEY-----
|
||||
35
packages/engine.io/test/fixtures/client.crt
vendored
35
packages/engine.io/test/fixtures/client.crt
vendored
@@ -1,22 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDtTCCAZ0CFCt+tjtA9647yZp8eNZurQtNp4x+MA0GCSqGSIb3DQEBDQUAMEUx
|
||||
CzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRl
|
||||
cm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMjIxMTE4MjEyMzU4WhcNMzIxMTE1MjEy
|
||||
MzU4WjBtMQswCQYDVQQGEwJGSTETMBEGA1UECBMKU29tZS1TdGF0ZTERMA8GA1UE
|
||||
BxMISGVsc2lua2kxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDET
|
||||
MBEGA1UEAxMKRm9vIENsaWVudDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
|
||||
+ukZ/D/DvjCtd7D8SCBDB1w0WYXkS6hjZTbF82gS1pykpVflsYtTnQoprQIeGQFU
|
||||
bdSZCvZkBABncQvE0cAzEtNvhFCtR9c74e+xJOGXB1vKeQlRJudxU5jvo4S/uwUG
|
||||
F1tcov11EQb9sZt0PeSO/PeWoKazBSPB4jrvx3Yv4g0CAwEAATANBgkqhkiG9w0B
|
||||
AQ0FAAOCAgEAMgC3j2XJ5IPB1raLrnJh8vTncnqMe6OmXpaxk0ZYb42Y66B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8GZT0SiWdfd/OP+1rZVCW5WWqtV1R1O202JKH6yE/CRQ
|
||||
t73P3dbfuXBDDs4kj5CM1xO6sGsd2Ev9iHPrLNfr+3mOZnGsdIxJ1oMkZwSmVCqc
|
||||
YJ8aGq2gtbK5mZJdqjHG9Kyd4LTvcEIS5WEmVkEg9GbZkrYw5UpdyAISL2Kk0X6j
|
||||
pZcssAoClLndq1IOxb/pYUm603jJAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAER3
|
||||
QEAHfCwWE2yhCYU4gYyy8bjQgR2lf1q1g0Pw+z+0e62oyoAFKq5bK7Jqu40Z87dc
|
||||
DWT3WvZnxflpYSW29WItJ8pJhQt3g6N+AfZADHzplVfYsHyRrn82Nd6knxRDh+Yk
|
||||
l0PVTzvNdsu1+QE5sH92Hl4Ze4VUJjAlpJzEzhBkhn2Uo19AhJ5FSpI1q8KEAUsk
|
||||
fUpane+sPkp5+d/nhIdLoBERFwEgu0WIChlPrV7ahlbFUde0sdqq1H0ZxBu4yABk
|
||||
tAYqgR6TRqbufvkXvxBmCFp3uq11kFLmeNu8VtaZDuaMwJ+9YT5SG8mbhFHwVz2S
|
||||
I3jNu1mm750TEWWMhPk=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
23
packages/engine.io/test/fixtures/client.csr
vendored
23
packages/engine.io/test/fixtures/client.csr
vendored
@@ -1,12 +1,15 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIBrTCCARYCAQAwbTELMAkGA1UEBhMCRkkxEzARBgNVBAgTClNvbWUtU3RhdGUx
|
||||
ETAPBgNVBAcTCEhlbHNpbmtpMSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0
|
||||
eSBMdGQxEzARBgNVBAMTCkZvbyBDbGllbnQwgZ8wDQYJKoZIhvcNAQEBBQADgY0A
|
||||
MIGJAoGBAPrpGfw/w74wrXew/EggQwdcNFmF5EuoY2U2xfNoEtacpKVX5bGLU50K
|
||||
Ka0CHhkBVG3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wVMY8qqVwqvJDidkN7eSjZTL2yOBzgiigpk8IMe1bNrb
|
||||
dIoJVEjzFooRa08MPt+BZJ7xiuCyKZe6aVmV0XZOcnHChSc8jmSRXZdNpikGdQRX
|
||||
1BamYMxhR2x8QYX0DiJYZwpgUaG4EOHsqb8=
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
|
||||
43
packages/engine.io/test/fixtures/client.key
vendored
43
packages/engine.io/test/fixtures/client.key
vendored
@@ -1,15 +1,28 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXQIBAAKBgQD66Rn8P8O+MK13sPxIIEMHXDRZheRLqGNlNsXzaBLWnKSlV+Wx
|
||||
i1OdCimtAh4ZAVRt1JkK9mQEAGdxC8TRwDMS02+EUK1H1zvh77Ek4ZcHW8p5CVEm
|
||||
53FTmO+jhL+7BQYXW1yi/XURBv2xm3Q95I7895agprMFI8HiOu/Hdi/iDQIDAQAB
|
||||
AoGBAOFHTXd4YO1wky82Dy1LGiOPm8kNOC7d33BOv2iN9uwN9J4nzymbqNUE/OpD
|
||||
TnaxBPcfvNFk6+PT4QxUvsB8ytzDMZ3YC4xyJf5GPP/hfzyWCRjB557WZl1cx7nC
|
||||
2gA93PBZE7WT1SySXmjsiC7o/2T/0cUaawXOBczHP8oXoEkBAkEA/c1MHs13ojxh
|
||||
oOj/ibCpYpd2Zv5Hrc5tsh+otDdIrb79IAHnNw7WhMkLs6cLk1MY6jLeCvQtjlUY
|
||||
H5C/6Ez84QJBAP0VZMgWPw3FVNXPrj833OA6XjyWO+TADpnlrahuDQqWnR3C29Uc
|
||||
Iq/ApVX2pt2cNIZpiuJ4BYNc44cHjvu6vq0CQQChan1cJc9NhluNLELBfnLsOmpa
|
||||
bKSH3P8VR19TZsm5fvub7Lnx4WT7xKXFl5scEsCIyts/WjbTDDmwca4r/zLhAkB4
|
||||
wkeHbY4CnSDgsKr9AUPEPjWPBURo3vdYmY4mKvTQE5O+iqboZfdrEyoQ/ZMbdRhe
|
||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bKmc
|
||||
eKisYwzJWwyDsJiShYBBlAKZOgZ2l8U6m8SGgYUU7/OcVekwrIdm87xi7wsd52aW
|
||||
ZhifzL7E/Zc5pEFdGKmYkRWoTQKBgQD6hOITk8dV461zrwS7Ev65psmWyx2SGUmq
|
||||
EIBi0fgE5wov2CXT6jR8mjJgvDjefG4lw92rT8CLsyaguoi2fjktbtOfXLMKVCF4
|
||||
K2r9KlD/44+WLKBYLKNCffvI+ZcdQqTvUJfZUH7k44fTP25ByqMyj6FNsC0xhL5W
|
||||
h1k57W4QbQKBgQCO9LYKlVmVkfCpJ1PBHhx2GpocIfsS4X1R2WlXMxca3M8ypMVv
|
||||
6QiGFxxMnd+RaJR9xobrQDfKfayptht8FGxm4wvaVIAzz1BoS0hmq1dPX+OMcg7J
|
||||
ld0cl4vHZv8pFkeJy+FXilD1CyBsptZ9uUcIcezeIEwQnA0t3JtSmzDkAQKBgE63
|
||||
zJYcPGmXphwQparm2BWb/AIfBsaunYALuVvT4FwiAQhxoclJ8X4psaTF4BTBApdp
|
||||
SVEYOUdsXrnogybc2LiW93Y+2Z9oOjAZbH/qeRM+/RJSKXwrYo11KtXG3535H/x2
|
||||
1ZAahBUGDdrqNooD024Cxcu0jS7fKDPmSbozCf+tAoGAZ3NwWzj3LpArnfOrDr7Z
|
||||
rXiUvCmSjPUBF99vN080rU8fBILdQTdz5DdE3K0xWDEiwAk1NZbuwy4Fx02aHG9f
|
||||
5CkmGEHOsLGT6n6BHrjuSCtvbNOAGLhSBbBJJkFOf3ktJXU64P38M7OP0j11Tzkv
|
||||
VNurVfn19LNgoLisW5c9tEs=
|
||||
-----END PRIVATE KEY-----
|
||||
|
||||
18
packages/engine.io/test/fixtures/client.key.orig
vendored
18
packages/engine.io/test/fixtures/client.key.orig
vendored
@@ -1,18 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,081B123E7DBC9687
|
||||
|
||||
c8gE0LQMMtV7GhUcP7GHBotlNNAsbyG/gERB//BFlvRPjs43ALvm5xMGUkcsZkw9
|
||||
H6ljvvgyRkud06x1mGxqlZ4fLlty0/mdXf6791R9gA/9bKLakHGlwnoVUrEPIeh3
|
||||
Iu/3IF0Uz8o3uljSp9eehR8sW5V4o+Z1MszQ+GkcpCyYnDPykyN52QLTM3RcUJ0v
|
||||
2iJrgxYEAyMA14iIpYM8IsFDYIBvwVfQxyBZnQ+8dDQgVOokz56g+/9emgOsVjWj
|
||||
bdUKZ7+95RLxCq0hjJd8GnoDn7qtxIPOGVqYcdEwwNyzO43FnpjOFhNDWwsrNrgf
|
||||
vUHKhZRHB99CkuCvGg4fjVbFd/1/n3eE5VmiQuqoHzPnXH3RDIx2rZSjFo/NkzYx
|
||||
4XzZ4YOe6vOP7kR18CL+bl32WneMELoh+TPLmsSC3rIP48M8+oQINSZaBrl59Ocw
|
||||
NW36xgDNSQoia2splVNo51vtZomq1Hb3co6hD43D4xnrc6Aqucm3BsW6UCc/PVKv
|
||||
HAXLCb+3awIy5NJSYb0qRETE2rKB6LjmKfILtOrto6QYSlkJmQUxqoPXgRAWWNlw
|
||||
1Ngws84+6UjmGWDBlpZHn0hcO/B7KJAAS/xNSFYDoSu6dAbabxTI/dZCWhw1aN5c
|
||||
QeYPihCi66F6Vuq/QT89dHtZE4IMPH7R95Yp18tCcyVGxaEiphw3HJYepMxoJesQ
|
||||
YH8tWQwvD5LaADzNJIKBxMjCOK23GuXWQLJJRf4QWiXaQar69qXULxBT3iqBp/rQ
|
||||
VKsQByBwJlEo/YSEFjhhMgo0zSbqIRAY1XCDo+dgB2IB1KPAobhSCQ==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
BIN
packages/engine.io/test/fixtures/client.pfx
vendored
BIN
packages/engine.io/test/fixtures/client.pfx
vendored
Binary file not shown.
22
packages/engine.io/test/fixtures/generate_certs.sh
vendored
Executable file
22
packages/engine.io/test/fixtures/generate_certs.sh
vendored
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Generate CA private key and certificate
|
||||
openssl genrsa -out ca.key 2048
|
||||
openssl req -x509 -new -nodes -key ca.key -days 365 -out ca.crt -subj "/CN=Test CA"
|
||||
|
||||
# Generate server key and certificate request
|
||||
openssl genrsa -out server.key 2048
|
||||
openssl req -new -key server.key -out server.csr -subj "/CN=localhost"
|
||||
|
||||
# Generate client key and certificate request
|
||||
openssl genrsa -out client.key 2048
|
||||
openssl req -new -key client.key -out client.csr -subj "/CN=client"
|
||||
|
||||
# Sign server certificate with CA
|
||||
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365
|
||||
|
||||
# Sign client certificate with CA
|
||||
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365
|
||||
|
||||
# Generate client PFX files
|
||||
openssl pkcs12 -export -passout pass: -out client.pfx -inkey client.key -in client.crt -certfile ca.crt
|
||||
35
packages/engine.io/test/fixtures/server.crt
vendored
35
packages/engine.io/test/fixtures/server.crt
vendored
@@ -1,22 +1,17 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDtDCCAZwCFCt+tjtA9647yZp8eNZurQtNp4x/MA0GCSqGSIb3DQEBDQUAMEUx
|
||||
CzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpTb21lLVN0YXRlMSEwHwYDVQQKExhJbnRl
|
||||
cm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMjIxMTE4MjEyNDExWhcNMzIxMTE1MjEy
|
||||
NDExWjBsMQswCQYDVQQGEwJGSTETMBEGA1UECBMKU29tZS1TdGF0ZTERMA8GA1UE
|
||||
BxMISGVsc2lua2kxITAfBgNVBAoTGEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDES
|
||||
MBAGA1UEAxMJbG9jYWxob3N0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDA
|
||||
QLNPDILqMIulvPga6ogci69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jUxMjE1MDc0NTA3WhcNMjYxMjE1MDc0NTA3
|
||||
WjAUMRIwEAYDVQQDDAlsb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
|
||||
ggEKAoIBAQDJw97tTsSTtZrOVjd89NKW548SyaB14Ghuqpfc3KxGa5OMuaXQU9aY
|
||||
nnoUCEU/YlS76t+ShZsQB9XR5UGy7T6ACJodm2tLsMmaNt3OX8JaXUeIY+UB9qPo
|
||||
aG8dLBenHays+dud2O2QUF7QhvRvVO98NrGpVaYVpes5lEQhvzKjaiK+Nc51gndR
|
||||
daAmvCPWINIBegUwRbbsAgNQaW8UEdxYWhVF8MDa//JPR7rTlHSFq6Or8SIvR1D/
|
||||
xAtvEXyAqPlkedIjh6Or2YCEIR2Lx+9Ky0Yti5vmh3PqZG6g7lMDOhIg/fkO2NfT
|
||||
9F+z6q7QL5+yOHzJgBepC7V5nQSQMQr9AgMBAAEwDQYJKoZIhvcNAQELBQADggEB
|
||||
AJh7TfVR5lBVtWepx5ghWrWDrqEXw7nJp4ljaZ/tp+Ufb1LasMflbAnShvnhPAg4
|
||||
A5/7GkCUjZOMc5QV2MYQGIPtyRdM1rdPG6EuR8SUA/+GxIbaLo7iDpAKpcvCdFfS
|
||||
pd44wgDBbzbTtw3nRGy6RXm1vB2FyjvGWVXYL3XoE2r/xQPgaf93jeglbgo9C8Tj
|
||||
MQ2NdR4GPBtjqZNDmer6p2Jr31pkS4exT7oNysnZfoXll8F4PHos7Wc5VYo/2qQy
|
||||
uftfQqYIZLaZKzjR32Gsr6Z5yb8GlISWnRss5ebD6+wzh8sr4fat0SY/vy/3oq5V
|
||||
0lwYgNPo/OuwNMA7Eo/iNPY=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
22
packages/engine.io/test/fixtures/server.csr
vendored
22
packages/engine.io/test/fixtures/server.csr
vendored
@@ -1,11 +1,15 @@
|
||||
-----BEGIN CERTIFICATE REQUEST-----
|
||||
MIIBrDCCARUCAQAwbDEL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eZ0EkDEK/QIDAQABoAAwDQYJKoZI
|
||||
hvcNAQELBQADggEBAI9mZrnDPk8PaljHRTLYlYNtL0+gVpav+deUnAzbjA5bxdaw
|
||||
t0xRptSDg3sFYFJWJ0HaqJltxSmdjj20MxmSCrexFOVXpISNsC/uZOs2CFWsDBdp
|
||||
kL6pIDHmxJF2q3dA7kZMeElSqUohYlA5t5rHp6w8/Vb0HnHAlke4kPd+bbo0MyFt
|
||||
mL2txXAz9AU8a5sG44x05VsSahtWSWeDNFbvaX27FhNDHxBMAFCj3niRQklMpCGG
|
||||
uX+OWr42iNJLhjyR7zsJ26tf1gP6+kFoAz2kRNC9qyQyTAzXNEydg6Yff1TuZv2h
|
||||
ktXz5unhsb91xO2iGT8PSWDHcVReSZRdyhwjYrI=
|
||||
-----END CERTIFICATE REQUEST-----
|
||||
|
||||
43
packages/engine.io/test/fixtures/server.key
vendored
43
packages/engine.io/test/fixtures/server.key
vendored
@@ -1,15 +1,28 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXgIBAAKBgQDAQLNPDILqMIulvPga6ogci69xYaSp50U7Tv8Hww3m4D9w2uby
|
||||
GqR7dDW20iGJI7tTNcv/UtLqgknEiCBXkq/MDr5gdXNI0V/j+qAOqfJSVxvxxHxL
|
||||
rt7ivjpZHbO7B3K7bkWmCxAFzWAlE5U9FXX1b8VfetJv+cDEaXsYwuYfowIDAQAB
|
||||
AoGBAL7tQmXl2fmz/mu5kHhCpKwcuT6TpxEo4aN132aY+qxn1flBHAwiE2mbTmDi
|
||||
rHViq/2GNrK5UUed3p60RdJSlgwIkyqtcGxWhUJGYCR/hU60qeeLp3MhhOoOFbiV
|
||||
YTDsoC7V/SuWbX+1qG5FxnHSnTZhAIRkZXS4uTZ5WDcQm/7BAkEA+TlZ1IT9CeU/
|
||||
FpHpqc8RgR8377Ehjy8o4Z4EGFnxQlAUWASnhs6dw4isr3+c7hA1OEmqmcRClPVZ
|
||||
t1JbHAPC4QJBAMV60WSJ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8IJ6NW7/Igy6xR/Z5xRajAzl
|
||||
FsyRRSHduI5HNgDo7riv46M=
|
||||
-----END PRIVATE KEY-----
|
||||
|
||||
18
packages/engine.io/test/fixtures/server.key.orig
vendored
18
packages/engine.io/test/fixtures/server.key.orig
vendored
@@ -1,18 +0,0 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
Proc-Type: 4,ENCRYPTED
|
||||
DEK-Info: DES-EDE3-CBC,8A14F3F31BF3CDF7
|
||||
|
||||
84UpLjX5GbfCoP/+ZRLwHZHqmgKyc2cjQOQKhp2YTk+4E0JSO7KsKwJax55r5VqE
|
||||
ECGvbd8yvVZ3GRpU6bDCLelDN+Ob5ZSGhynI0f9is6Qle1/SbvaK+qL6MLf4H38l
|
||||
Y91eZxjE8hLvOMHBlbobLmy9UUzl2osBDAM1nm5d1X7pF7mN4xgY8s2G7UPq3ZZS
|
||||
NWwMsnwtb/9Ahm7WXfsJbebyKspkTSHYp/ozaOGW58fuKxkwRFd1UlyblZWU3ezP
|
||||
JCpvJQ7HS6Dfy6+GUaxcC6pyxqnoJHYccB5usJ2h4QD4Es3sT7Vw7M80JKw3vAWm
|
||||
TH7VkFX3yGfJ1p1jNzifN5687QqrjeI3/ecTs1rFhIC4TUPN9EDvw86Y6l6Mvo04
|
||||
Hl2cVzCnCrZYq0ICD0op3+7f9kuKl7bz54S/iRG2qQdICohPs7ra2yaUy+NFVDs1
|
||||
XdXyF5/xew+Rr2z7ygEd+OrvXxPV0zTFbicg9GXGeB/pIYAclmoSNXD5T3voN7y9
|
||||
5MjSGL375N3z+kqPzMNawYCnZLwQ5jYTDUkDTATYpjcIDVDQkzbl8mFp4i+Z9GhL
|
||||
H8FRAgmBbkgy3dxhFjxr/WzuaTkUCAbGhrtPd8WCPhBXJBzWdrBVR9SE8zT9n8lq
|
||||
ZwaPwkPLBrLe/XZFEQJ5cdvMVNy4QQwsyxHnCgO3VUc68UYXb39MvyM6t8+S1rSm
|
||||
SyvVAT+jB8T4VlE7tedQGuvyKMmeNIJe9znd3u4S+Aq2+vw6bOKeNYBMaupR5Gyl
|
||||
bJrscuTG1aLUe+XH9BuFBUoIwdXuBv4Ko/pDL0MYPghDAEGkp4Acmg==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
@@ -99,6 +99,26 @@ function setup(opts, cb) {
|
||||
});
|
||||
}
|
||||
|
||||
function createHttpServer(port) {
|
||||
const httpServer = createServer();
|
||||
|
||||
let retryCount = 0;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
httpServer.listen(port, () => resolve(httpServer));
|
||||
|
||||
httpServer.on("error", (e) => {
|
||||
if (e.code === "EADDRINUSE" && ++retryCount <= 3) {
|
||||
console.warn("port already in use, retrying...");
|
||||
setTimeout(() => {
|
||||
httpServer.listen(port, () => resolve(httpServer));
|
||||
}, 100);
|
||||
}
|
||||
reject(e);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe("WebTransport", () => {
|
||||
it("should allow to connect with WebTransport directly", (done) => {
|
||||
setupServer({}, async ({ engine, h3Server, certificate }) => {
|
||||
@@ -154,9 +174,8 @@ describe("WebTransport", () => {
|
||||
transports: ["polling", "websocket", "webtransport"],
|
||||
},
|
||||
async ({ engine, h3Server, certificate }) => {
|
||||
const httpServer = createServer();
|
||||
const httpServer = await createHttpServer(h3Server.port);
|
||||
engine.attach(httpServer);
|
||||
httpServer.listen(h3Server.port);
|
||||
|
||||
const partialDone = createPartialDone(() => {
|
||||
httpServer.close();
|
||||
|
||||
@@ -199,6 +199,14 @@ export abstract class ClusterAdapter extends Adapter {
|
||||
return debug("[%s] ignore message from self", this.uid);
|
||||
}
|
||||
|
||||
if (message.nsp !== this.nsp.name) {
|
||||
return debug(
|
||||
"[%s] ignore message from another namespace (%s)",
|
||||
this.uid,
|
||||
message.nsp,
|
||||
);
|
||||
}
|
||||
|
||||
debug(
|
||||
"[%s] new event of type %d from %s",
|
||||
this.uid,
|
||||
@@ -671,6 +679,8 @@ export abstract class ClusterAdapter extends Adapter {
|
||||
protected publish(
|
||||
message: DistributiveOmit<ClusterMessage, "nsp" | "uid">,
|
||||
): void {
|
||||
debug("[%s] sending message %s", this.uid, message.type);
|
||||
|
||||
this.publishAndReturnOffset(message).catch((err) => {
|
||||
debug("[%s] error while publishing message: %s", this.uid, err);
|
||||
});
|
||||
@@ -699,6 +709,14 @@ export abstract class ClusterAdapter extends Adapter {
|
||||
) {
|
||||
(response as ClusterResponse).uid = this.uid;
|
||||
(response as ClusterResponse).nsp = this.nsp.name;
|
||||
|
||||
debug(
|
||||
"[%s] sending response %s to %s",
|
||||
this.uid,
|
||||
response.type,
|
||||
requesterUid,
|
||||
);
|
||||
|
||||
this.doPublishResponse(requesterUid, response as ClusterResponse).catch(
|
||||
(err) => {
|
||||
debug("[%s] error while publishing response: %s", this.uid, err);
|
||||
@@ -790,17 +808,10 @@ export abstract class ClusterAdapterWithHeartbeat extends ClusterAdapter {
|
||||
}
|
||||
|
||||
if (message.uid && message.uid !== EMITTER_UID) {
|
||||
// we track the UID of each sender, in order to know how many servers there are in the cluster
|
||||
// we track the UID of each sender to know how many servers there are in the cluster
|
||||
this.nodesMap.set(message.uid, Date.now());
|
||||
}
|
||||
|
||||
debug(
|
||||
"[%s] new event of type %d from %s",
|
||||
this.uid,
|
||||
message.type,
|
||||
message.uid,
|
||||
);
|
||||
|
||||
switch (message.type) {
|
||||
case MessageType.INITIAL_HEARTBEAT:
|
||||
this.publish({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { EventEmitter } from "events";
|
||||
import { yeast } from "./contrib/yeast";
|
||||
import WebSocket = require("ws");
|
||||
import * as WebSocket from "ws";
|
||||
|
||||
// @ts-expect-error
|
||||
const canPreComputeFrame = typeof WebSocket?.Sender?.frame === "function";
|
||||
@@ -51,11 +51,11 @@ export class Adapter extends EventEmitter {
|
||||
/**
|
||||
* In-memory adapter constructor.
|
||||
*
|
||||
* @param {Namespace} nsp
|
||||
* @param nsp
|
||||
*/
|
||||
constructor(readonly nsp: any) {
|
||||
super();
|
||||
this.encoder = nsp.server.encoder;
|
||||
this.encoder = nsp.server.encoder; // nsp is a Namespace object
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,12 +17,12 @@
|
||||
"types": "./dist/index.d.ts",
|
||||
"description": "default socket.io in-memory adapter",
|
||||
"dependencies": {
|
||||
"debug": "~4.3.4",
|
||||
"ws": "~8.17.1"
|
||||
"debug": "~4.4.1",
|
||||
"ws": "~8.18.3"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"test": "npm run format:check && npm run compile && nyc mocha --require ts-node/register test/*.ts",
|
||||
"test": "npm run format:check && npm run compile && nyc mocha --import=tsx test/*.ts",
|
||||
"format:check": "prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"format:fix": "prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"prepack": "npm run compile"
|
||||
|
||||
@@ -67,11 +67,6 @@ describe("cluster adapter", () => {
|
||||
serverSockets.push(socket);
|
||||
servers.push(io);
|
||||
if (servers.length === NODES_COUNT) {
|
||||
// ensure all nodes know each other
|
||||
servers[0].emit("ping");
|
||||
servers[1].emit("ping");
|
||||
servers[2].emit("ping");
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
11
packages/socket.io-client/RELEASING.md
Normal file
11
packages/socket.io-client/RELEASING.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Releasing
|
||||
|
||||
1. Update the version in `package.json`
|
||||
2. Update the version in `support/package.esm.json`
|
||||
3. Update the changelog `CHANGELOG.md` with `conventional-changelog -p angular`
|
||||
4. Compile the TypeScript sources with `npm run compile`
|
||||
5. Generate the bundles with `npm run build`
|
||||
6. Commit the changes in `package.json`, `support/package.esm.json`, `CHANGELOG.md` and `dist/`
|
||||
7. Create the tag `socket.io-client@x.y.z` and push it to the GitHub repository. The workflow `.github/workflows/publish.yml` will safely publish the package to npm using trusted publishing.
|
||||
8. Create a new release at https://github.com/socketio/socket.io/releases
|
||||
9. Copy the bundles to the repository https://github.com/socketio/socket.io-cdn so that they are available at https://cdn.socket.io/
|
||||
@@ -1,6 +1,6 @@
|
||||
import { url } from "./url.js";
|
||||
import { Manager, ManagerOptions } from "./manager.js";
|
||||
import { Socket, SocketOptions } from "./socket.js";
|
||||
import { DisconnectDescription, Socket, SocketOptions } from "./socket.js";
|
||||
import debugModule from "debug"; // debug()
|
||||
|
||||
const debug = debugModule("socket.io-client"); // debug()
|
||||
@@ -91,6 +91,7 @@ export { protocol } from "socket.io-parser";
|
||||
*/
|
||||
|
||||
export {
|
||||
DisconnectDescription,
|
||||
Manager,
|
||||
ManagerOptions,
|
||||
Socket,
|
||||
|
||||
@@ -542,8 +542,7 @@ export class Socket<
|
||||
|
||||
args.push((err, ...responseArgs) => {
|
||||
if (packet !== this._queue[0]) {
|
||||
// the packet has already been acknowledged
|
||||
return;
|
||||
return debug("packet [%d] already acknowledged", packet.id);
|
||||
}
|
||||
const hasError = err !== null;
|
||||
if (hasError) {
|
||||
@@ -834,8 +833,8 @@ export class Socket<
|
||||
this._pid = pid; // defined only if connection state recovery is enabled
|
||||
this.connected = true;
|
||||
this.emitBuffered();
|
||||
this.emitReserved("connect");
|
||||
this._drainQueue(true);
|
||||
this.emitReserved("connect");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,14 +46,14 @@
|
||||
"types": "./build/esm/index.d.ts",
|
||||
"dependencies": {
|
||||
"@socket.io/component-emitter": "~3.1.0",
|
||||
"debug": "~4.3.2",
|
||||
"debug": "~4.4.1",
|
||||
"engine.io-client": "~6.6.1",
|
||||
"socket.io-parser": "~4.2.4"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "rimraf ./build && tsc && tsc -p tsconfig.esm.json && ./postcompile.sh",
|
||||
"test": "npm run format:check && npm run compile && if test \"$BROWSERS\" = \"1\" ; then npm run test:browser; else npm run test:node; fi",
|
||||
"test:node": "mocha --require ts-node/register --require test/support/hooks.ts --exit test/index.ts",
|
||||
"test:node": "mocha --import=tsx --require test/support/hooks.ts --exit test/index.ts",
|
||||
"test:browser": "ts-node test/browser-runner.ts",
|
||||
"test:types": "tsd",
|
||||
"build": "rollup -c support/rollup.config.umd.js && rollup -c support/rollup.config.esm.js && rollup -c support/rollup.config.umd.msgpack.js",
|
||||
|
||||
@@ -20,6 +20,7 @@ module.exports = {
|
||||
mangle: {
|
||||
properties: {
|
||||
regex: /^_/,
|
||||
reserved: ["_placeholder"],
|
||||
},
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -110,4 +110,40 @@ describe("retry", () => {
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not emit a packet twice in the 'connect' handler", () => {
|
||||
return wrap((done) => {
|
||||
const socket = io(BASE_URL, {
|
||||
forceNew: true,
|
||||
retries: 3,
|
||||
});
|
||||
|
||||
const received: string[] = [];
|
||||
const sent: string[] = [];
|
||||
|
||||
socket.io.engine.on("packetCreate", ({ data }) => {
|
||||
sent.push(data);
|
||||
});
|
||||
|
||||
socket.io.engine.on("packet", ({ data }) => {
|
||||
received.push(data);
|
||||
});
|
||||
|
||||
socket.on("connect", () => {
|
||||
socket.emit("echo", null);
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
expect(sent).to.eql(["0", '20["echo",null]']);
|
||||
|
||||
expect(received.length).to.eql(3);
|
||||
// 1: engine.io OPEN packet
|
||||
// 2: socket.io CONNECT packet
|
||||
// 3: ack packet
|
||||
expect(received[2]).to.eql("30[null]");
|
||||
|
||||
success(done, socket);
|
||||
}, 100);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -60,7 +60,7 @@ if (process.env.CI === "true") {
|
||||
{
|
||||
browserName: "internet explorer",
|
||||
browserVersion: "10",
|
||||
platformName: "Windows 7",
|
||||
platformName: "Windows 8",
|
||||
"sauce:options": BASE_SAUCE_OPTIONS,
|
||||
},
|
||||
{
|
||||
|
||||
60
packages/socket.io-cluster-adapter/CHANGELOG.md
Normal file
60
packages/socket.io-cluster-adapter/CHANGELOG.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Changelog
|
||||
|
||||
| Version | Release date |
|
||||
|--------------------------|--------------|
|
||||
| [0.3.0](#030-2025-10-16) | October 2025 |
|
||||
| [0.2.2](#022-2023-03-24) | March 2023 |
|
||||
| [0.2.1](#021-2022-10-13) | October 2022 |
|
||||
| [0.2.0](#020-2022-04-28) | April 2022 |
|
||||
| [0.1.0](#010-2021-06-22) | June 2021 |
|
||||
|
||||
|
||||
|
||||
## [0.3.0](https://github.com/socketio/socket.io-cluster-adapter/compare/0.2.2...0.3.0) (2025-10-16)
|
||||
|
||||
This release contains an important refactor of the adapter ([this commit](https://github.com/socketio/socket.io-cluster-adapter/commit/0c431243e28913fdd2a4a3de3e67a9f38d67a3aa)), as most of the logic has been moved in the `ClusterAdapter` class of the `socket.io-adapter` package.
|
||||
|
||||
Besides, the `@socket.io/cluster-adapter` package is now part of the `socket.io` monorepo.
|
||||
|
||||
|
||||
|
||||
## [0.2.2](https://github.com/socketio/socket.io-cluster-adapter/compare/0.2.1...0.2.2) (2023-03-24)
|
||||
|
||||
The `socket.io-adapter` package was added to the list of `peerDependencies`, in order to fix sync issues with the version imported by the socket.io package (see [15fd56e](https://github.com/socketio/socket.io-cluster-adapter/commit/15fd56e78d52aa65c5fbf412dec57ab4bdaee7cc)).
|
||||
|
||||
Support for connection state recovery (see [here](https://github.com/socketio/socket.io/releases/4.6.0)) will be added in the next release.
|
||||
|
||||
|
||||
|
||||
## [0.2.1](https://github.com/socketio/socket.io-cluster-adapter/compare/0.2.0...0.2.1) (2022-10-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* properly handle ERR_IPC_CHANNEL_CLOSED errors ([#6](https://github.com/socketio/socket.io-cluster-adapter/issues/6)) ([be0a0e3](https://github.com/socketio/socket.io-cluster-adapter/commit/be0a0e3217bd7100d569e5624194612bcc8b96ff))
|
||||
|
||||
|
||||
|
||||
## [0.2.0](https://github.com/socketio/socket.io-cluster-adapter/compare/0.1.0...0.2.0) (2022-04-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* broadcast and expect multiple acks ([055b784](https://github.com/socketio/socket.io-cluster-adapter/commit/055b7840d8cf88173d8299041ef3fafa9791c97a))
|
||||
|
||||
This feature was added in `socket.io@4.5.0`:
|
||||
|
||||
```js
|
||||
io.timeout(1000).emit("some-event", (err, responses) => {
|
||||
// ...
|
||||
});
|
||||
```
|
||||
|
||||
Thanks to this change, it will now work within a Node.js cluster.
|
||||
|
||||
|
||||
|
||||
## 0.1.0 (2021-06-22)
|
||||
|
||||
Initial commit
|
||||
|
||||
7
packages/socket.io-cluster-adapter/LICENSE
Normal file
7
packages/socket.io-cluster-adapter/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2021 Damien Arrachequesne (@darrachequesne)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
100
packages/socket.io-cluster-adapter/README.md
Normal file
100
packages/socket.io-cluster-adapter/README.md
Normal file
@@ -0,0 +1,100 @@
|
||||
# Socket.IO cluster adapter
|
||||
|
||||
The `@socket.io/cluster-adapter` package allows broadcasting packets between multiple Socket.IO servers.
|
||||
|
||||

|
||||
|
||||
It can be used in conjunction with [`@socket.io/sticky`](https://github.com/socketio/socket.io-sticky) to broadcast packets between the workers of the same Node.js [cluster](https://nodejs.org/api/cluster.html).
|
||||
|
||||
Supported features:
|
||||
|
||||
- [broadcasting](https://socket.io/docs/v4/broadcasting-events/)
|
||||
- [utility methods](https://socket.io/docs/v4/server-instance/#Utility-methods)
|
||||
- [`socketsJoin`](https://socket.io/docs/v4/server-instance/#socketsJoin)
|
||||
- [`socketsLeave`](https://socket.io/docs/v4/server-instance/#socketsLeave)
|
||||
- [`disconnectSockets`](https://socket.io/docs/v4/server-instance/#disconnectSockets)
|
||||
- [`fetchSockets`](https://socket.io/docs/v4/server-instance/#fetchSockets)
|
||||
- [`serverSideEmit`](https://socket.io/docs/v4/server-instance/#serverSideEmit)
|
||||
|
||||
Related packages:
|
||||
|
||||
- Postgres adapter: https://github.com/socketio/socket.io-postgres-adapter/
|
||||
- Redis adapter: https://github.com/socketio/socket.io-redis-adapter/
|
||||
- MongoDB adapter: https://github.com/socketio/socket.io-mongo-adapter/
|
||||
|
||||
**Table of contents**
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [License](#license)
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install @socket.io/cluster-adapter
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const cluster = require("cluster");
|
||||
const http = require("http");
|
||||
const { Server } = require("socket.io");
|
||||
const numCPUs = require("os").cpus().length;
|
||||
const { setupMaster, setupWorker } = require("@socket.io/sticky");
|
||||
const { createAdapter, setupPrimary } = require("@socket.io/cluster-adapter");
|
||||
|
||||
if (cluster.isMaster) {
|
||||
console.log(`Master ${process.pid} is running`);
|
||||
|
||||
const httpServer = http.createServer();
|
||||
|
||||
// setup sticky sessions
|
||||
setupMaster(httpServer, {
|
||||
loadBalancingMethod: "least-connection",
|
||||
});
|
||||
|
||||
// setup connections between the workers
|
||||
setupPrimary();
|
||||
|
||||
// needed for packets containing buffers (you can ignore it if you only send plaintext objects)
|
||||
// Node.js < 16.0.0
|
||||
cluster.setupMaster({
|
||||
serialization: "advanced",
|
||||
});
|
||||
// Node.js > 16.0.0
|
||||
// cluster.setupPrimary({
|
||||
// serialization: "advanced",
|
||||
// });
|
||||
|
||||
httpServer.listen(3000);
|
||||
|
||||
for (let i = 0; i < numCPUs; i++) {
|
||||
cluster.fork();
|
||||
}
|
||||
|
||||
cluster.on("exit", (worker) => {
|
||||
console.log(`Worker ${worker.process.pid} died`);
|
||||
cluster.fork();
|
||||
});
|
||||
} else {
|
||||
console.log(`Worker ${process.pid} started`);
|
||||
|
||||
const httpServer = http.createServer();
|
||||
const io = new Server(httpServer);
|
||||
|
||||
// use the cluster adapter
|
||||
io.adapter(createAdapter());
|
||||
|
||||
// setup connection with the primary process
|
||||
setupWorker(io);
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
/* ... */
|
||||
});
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
822
packages/socket.io-cluster-adapter/assets/adapter.excalidraw
Normal file
822
packages/socket.io-cluster-adapter/assets/adapter.excalidraw
Normal file
@@ -0,0 +1,822 @@
|
||||
{
|
||||
"type": "excalidraw",
|
||||
"version": 2,
|
||||
"source": "https://excalidraw.com",
|
||||
"elements": [
|
||||
{
|
||||
"type": "text",
|
||||
"version": 345,
|
||||
"versionNonce": 1782313961,
|
||||
"isDeleted": false,
|
||||
"id": "5hUB5ALUlsn26W0PzU4fM",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 777,
|
||||
"y": -89.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 78,
|
||||
"height": 26,
|
||||
"seed": 28708370,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"_wBO22vaQplcoKyBXbWRC"
|
||||
],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "worker 1",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 230,
|
||||
"versionNonce": 1587305255,
|
||||
"isDeleted": false,
|
||||
"id": "lmQ4o4New7xuXQLwavuSn",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 725,
|
||||
"y": -169,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 345.00000000000006,
|
||||
"height": 311,
|
||||
"seed": 1594950354,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"_wBO22vaQplcoKyBXbWRC",
|
||||
"BZVwnsrGk9G-X87ZHkh-6",
|
||||
"eU1gfEXnHSjxc-pEgv43A",
|
||||
"XZpY0rnxgeDlxu5b8fgRQ",
|
||||
"4mjxZzapHnLuRx7KU2JeH",
|
||||
"mV8ZNfAcYrxGLJ7b9a_kn"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 152,
|
||||
"versionNonce": 742887113,
|
||||
"isDeleted": false,
|
||||
"id": "ZQsZmj4NaTubBHMkVG2dl",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 745,
|
||||
"y": -159,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 43,
|
||||
"height": 26,
|
||||
"seed": 126533902,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "Host",
|
||||
"baseline": 18,
|
||||
"textAlign": "left",
|
||||
"verticalAlign": "top"
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 334,
|
||||
"versionNonce": 1221877319,
|
||||
"isDeleted": false,
|
||||
"id": "RRrk3Vsl-pM8Z1r8Fj3Vu",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 749.5,
|
||||
"y": -105,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 129,
|
||||
"height": 56,
|
||||
"seed": 1013161166,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"use4Bp2hbb77Fq5njtwBi",
|
||||
"U7UCkn3nVHlWGYetjII_Z"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 386,
|
||||
"versionNonce": 601673129,
|
||||
"isDeleted": false,
|
||||
"id": "qfQdcJHnwYnCMtLCV51X8",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 773,
|
||||
"y": -18.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 90,
|
||||
"height": 26,
|
||||
"seed": 1535426147,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"_wBO22vaQplcoKyBXbWRC",
|
||||
"2DIFacJXJtC5QIuMuo3pK"
|
||||
],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "worker 2",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 330,
|
||||
"versionNonce": 794754407,
|
||||
"isDeleted": false,
|
||||
"id": "IRd1nPQbv0PQdJQn_yLOs",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 749.5,
|
||||
"y": -36,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 129,
|
||||
"height": 56,
|
||||
"seed": 452398413,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"2DIFacJXJtC5QIuMuo3pK",
|
||||
"NhqDM6wVMhgbRvXrQJQge",
|
||||
"C1IueNJdiTSkqUxSTEvKe"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 374,
|
||||
"versionNonce": 942092425,
|
||||
"isDeleted": false,
|
||||
"id": "ENOSqQ4visNbCN7ZMZwxP",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 770.5,
|
||||
"y": 48.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 89,
|
||||
"height": 26,
|
||||
"seed": 1916984429,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"_wBO22vaQplcoKyBXbWRC"
|
||||
],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "worker 3",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 314,
|
||||
"versionNonce": 629717127,
|
||||
"isDeleted": false,
|
||||
"id": "IqdB8EO7s50UY1EU9TVVP",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 750.5,
|
||||
"y": 30,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 129,
|
||||
"height": 56,
|
||||
"seed": 1832463587,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"NhqDM6wVMhgbRvXrQJQge"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 115,
|
||||
"versionNonce": 997860361,
|
||||
"isDeleted": false,
|
||||
"id": "9grXh8d6z3-WENQLWSBP6",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 338,
|
||||
"y": -95,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 140,
|
||||
"height": 49,
|
||||
"seed": 1667334019,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": []
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 95,
|
||||
"versionNonce": 1806744839,
|
||||
"isDeleted": false,
|
||||
"id": "uw4DcwoucyYZxQuvW-XdC",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 383,
|
||||
"y": -83.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 50,
|
||||
"height": 26,
|
||||
"seed": 1216901411,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "client",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"id": "ZR4mzBF0WDviz0UhZ4jZM",
|
||||
"type": "diamond",
|
||||
"x": 891.5,
|
||||
"y": -87,
|
||||
"width": 35,
|
||||
"height": 18,
|
||||
"angle": 0,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 2,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"seed": 1951590473,
|
||||
"version": 87,
|
||||
"versionNonce": 232917705,
|
||||
"isDeleted": false,
|
||||
"boundElementIds": [
|
||||
"LgoBfF5uxSyzlQnWpzp21",
|
||||
"VzzoutsEZMxQbMloZdWpR",
|
||||
"OEzsLqAW3F-2LE0bnPrtx"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "tpect-oo26kMVbG_xdqoO",
|
||||
"type": "text",
|
||||
"x": 895.5,
|
||||
"y": -130,
|
||||
"width": 157,
|
||||
"height": 26,
|
||||
"angle": 0,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 2,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"seed": 294816809,
|
||||
"version": 104,
|
||||
"versionNonce": 2120602793,
|
||||
"isDeleted": false,
|
||||
"boundElementIds": null,
|
||||
"text": "cluster adapter",
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"textAlign": "left",
|
||||
"verticalAlign": "top",
|
||||
"baseline": 18
|
||||
},
|
||||
{
|
||||
"type": "diamond",
|
||||
"version": 113,
|
||||
"versionNonce": 1690814889,
|
||||
"isDeleted": false,
|
||||
"id": "ScoFMjrxukGD1efHfKiFH",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 2,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 894.5,
|
||||
"y": -20,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 35,
|
||||
"height": 18,
|
||||
"seed": 696687431,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"VzzoutsEZMxQbMloZdWpR"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "diamond",
|
||||
"version": 158,
|
||||
"versionNonce": 1317846759,
|
||||
"isDeleted": false,
|
||||
"id": "wj2HZ2scg4U6UtpfK8x3e",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 2,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 893.5,
|
||||
"y": 46,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 35,
|
||||
"height": 18,
|
||||
"seed": 1469547015,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"OEzsLqAW3F-2LE0bnPrtx"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "U7UCkn3nVHlWGYetjII_Z",
|
||||
"type": "arrow",
|
||||
"x": 734.5,
|
||||
"y": -74,
|
||||
"width": 238,
|
||||
"height": 4,
|
||||
"angle": 0,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "round",
|
||||
"seed": 1537057031,
|
||||
"version": 61,
|
||||
"versionNonce": 1166788937,
|
||||
"isDeleted": false,
|
||||
"boundElementIds": null,
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-238,
|
||||
4
|
||||
]
|
||||
],
|
||||
"lastCommittedPoint": null,
|
||||
"startBinding": {
|
||||
"elementId": "RRrk3Vsl-pM8Z1r8Fj3Vu",
|
||||
"focus": -0.05720889916209189,
|
||||
"gap": 15
|
||||
},
|
||||
"endBinding": null,
|
||||
"startArrowhead": null,
|
||||
"endArrowhead": "arrow"
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 163,
|
||||
"versionNonce": 15141831,
|
||||
"isDeleted": false,
|
||||
"id": "mv6FEWy7Oux1XBpOeYKlJ",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 337.25,
|
||||
"y": -26.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 140,
|
||||
"height": 49,
|
||||
"seed": 1927924585,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": []
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 143,
|
||||
"versionNonce": 766883881,
|
||||
"isDeleted": false,
|
||||
"id": "sBk2P5AAiZa36HbnmeRLi",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 382.25,
|
||||
"y": -15,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 50,
|
||||
"height": 26,
|
||||
"seed": 1643756455,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "client",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"type": "arrow",
|
||||
"version": 111,
|
||||
"versionNonce": 2076179175,
|
||||
"isDeleted": false,
|
||||
"id": "C1IueNJdiTSkqUxSTEvKe",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 733.75,
|
||||
"y": -5.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 238,
|
||||
"height": 4,
|
||||
"seed": 542013001,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "round",
|
||||
"boundElementIds": [],
|
||||
"startBinding": {
|
||||
"elementId": "IRd1nPQbv0PQdJQn_yLOs",
|
||||
"focus": -0.03958393527882115,
|
||||
"gap": 15.75
|
||||
},
|
||||
"endBinding": null,
|
||||
"lastCommittedPoint": null,
|
||||
"startArrowhead": null,
|
||||
"endArrowhead": "arrow",
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-238,
|
||||
4
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 138,
|
||||
"versionNonce": 478071561,
|
||||
"isDeleted": false,
|
||||
"id": "6r_-m_ehoDx3FlKI9YqbJ",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 337.25,
|
||||
"y": 40.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 140,
|
||||
"height": 49,
|
||||
"seed": 704870919,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": []
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 118,
|
||||
"versionNonce": 133039623,
|
||||
"isDeleted": false,
|
||||
"id": "EEhePeT66oko7kRekPQGo",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 382.25,
|
||||
"y": 52,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 50,
|
||||
"height": 26,
|
||||
"seed": 93212137,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "client",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"type": "arrow",
|
||||
"version": 86,
|
||||
"versionNonce": 979534313,
|
||||
"isDeleted": false,
|
||||
"id": "etOb8BtJX8fUgxXsPOX2F",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 733.75,
|
||||
"y": 61.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 238,
|
||||
"height": 4,
|
||||
"seed": 464822567,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "round",
|
||||
"boundElementIds": [],
|
||||
"startBinding": null,
|
||||
"endBinding": null,
|
||||
"lastCommittedPoint": null,
|
||||
"startArrowhead": null,
|
||||
"endArrowhead": "arrow",
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-238,
|
||||
4
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "rectangle",
|
||||
"version": 184,
|
||||
"versionNonce": 1953344807,
|
||||
"isDeleted": false,
|
||||
"id": "G6-PJf8TRngnFyuC3A0QC",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 337.25,
|
||||
"y": 105.5,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 140,
|
||||
"height": 49,
|
||||
"seed": 1627945223,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [
|
||||
"JFhaNprFAz7gl6FY48Aps"
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "text",
|
||||
"version": 163,
|
||||
"versionNonce": 342645961,
|
||||
"isDeleted": false,
|
||||
"id": "UEv3oUzBr56Mj6Mz7hG-B",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 382.25,
|
||||
"y": 117,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 50,
|
||||
"height": 26,
|
||||
"seed": 1822211817,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "sharp",
|
||||
"boundElementIds": [],
|
||||
"fontSize": 20,
|
||||
"fontFamily": 1,
|
||||
"text": "client",
|
||||
"baseline": 18,
|
||||
"textAlign": "center",
|
||||
"verticalAlign": "middle"
|
||||
},
|
||||
{
|
||||
"type": "arrow",
|
||||
"version": 135,
|
||||
"versionNonce": 2091610183,
|
||||
"isDeleted": false,
|
||||
"id": "JFhaNprFAz7gl6FY48Aps",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 731.1770639400929,
|
||||
"y": 74.303452225402,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 240.42706394009292,
|
||||
"height": 54.196547774598,
|
||||
"seed": 1203879975,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "round",
|
||||
"boundElementIds": [],
|
||||
"startBinding": null,
|
||||
"endBinding": {
|
||||
"elementId": "G6-PJf8TRngnFyuC3A0QC",
|
||||
"focus": 0.4300574064368146,
|
||||
"gap": 13.5
|
||||
},
|
||||
"lastCommittedPoint": null,
|
||||
"startArrowhead": null,
|
||||
"endArrowhead": "arrow",
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
-240.42706394009292,
|
||||
54.196547774598
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "VzzoutsEZMxQbMloZdWpR",
|
||||
"type": "arrow",
|
||||
"x": 929.5,
|
||||
"y": -70,
|
||||
"width": 17,
|
||||
"height": 53,
|
||||
"angle": 0,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "round",
|
||||
"seed": 1957283401,
|
||||
"version": 330,
|
||||
"versionNonce": 1093640775,
|
||||
"isDeleted": false,
|
||||
"boundElementIds": null,
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
16,
|
||||
23
|
||||
],
|
||||
[
|
||||
-1,
|
||||
53
|
||||
]
|
||||
],
|
||||
"lastCommittedPoint": null,
|
||||
"startBinding": {
|
||||
"elementId": "ZR4mzBF0WDviz0UhZ4jZM",
|
||||
"focus": -0.853416149068323,
|
||||
"gap": 8.48634645640746
|
||||
},
|
||||
"endBinding": {
|
||||
"elementId": "ScoFMjrxukGD1efHfKiFH",
|
||||
"focus": 0.7485714285714284,
|
||||
"gap": 4.878378801288122
|
||||
},
|
||||
"startArrowhead": null,
|
||||
"endArrowhead": "arrow"
|
||||
},
|
||||
{
|
||||
"type": "arrow",
|
||||
"version": 440,
|
||||
"versionNonce": 2038871081,
|
||||
"isDeleted": false,
|
||||
"id": "OEzsLqAW3F-2LE0bnPrtx",
|
||||
"fillStyle": "hachure",
|
||||
"strokeWidth": 1,
|
||||
"strokeStyle": "solid",
|
||||
"roughness": 1,
|
||||
"opacity": 100,
|
||||
"angle": 0,
|
||||
"x": 930.5,
|
||||
"y": -71,
|
||||
"strokeColor": "#000000",
|
||||
"backgroundColor": "transparent",
|
||||
"width": 42,
|
||||
"height": 116,
|
||||
"seed": 1990607913,
|
||||
"groupIds": [],
|
||||
"strokeSharpness": "round",
|
||||
"boundElementIds": [],
|
||||
"startBinding": {
|
||||
"elementId": "ZR4mzBF0WDviz0UhZ4jZM",
|
||||
"focus": -0.8894409937888198,
|
||||
"gap": 8.054406666710076
|
||||
},
|
||||
"endBinding": {
|
||||
"elementId": "wj2HZ2scg4U6UtpfK8x3e",
|
||||
"focus": 0.6,
|
||||
"gap": 8.435530010560711
|
||||
},
|
||||
"lastCommittedPoint": null,
|
||||
"startArrowhead": null,
|
||||
"endArrowhead": "arrow",
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
39,
|
||||
46
|
||||
],
|
||||
[
|
||||
-3,
|
||||
116
|
||||
]
|
||||
]
|
||||
}
|
||||
],
|
||||
"appState": {
|
||||
"gridSize": null,
|
||||
"viewBackgroundColor": "#ffffff"
|
||||
}
|
||||
}
|
||||
BIN
packages/socket.io-cluster-adapter/assets/adapter.png
Normal file
BIN
packages/socket.io-cluster-adapter/assets/adapter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
116
packages/socket.io-cluster-adapter/lib/index.ts
Normal file
116
packages/socket.io-cluster-adapter/lib/index.ts
Normal file
@@ -0,0 +1,116 @@
|
||||
import cluster from "node:cluster";
|
||||
import {
|
||||
ClusterAdapterWithHeartbeat,
|
||||
ClusterAdapterOptions,
|
||||
ClusterMessage,
|
||||
ServerId,
|
||||
ClusterResponse,
|
||||
MessageType,
|
||||
} from "socket.io-adapter";
|
||||
import debugModule from "debug";
|
||||
|
||||
const debug = debugModule("socket.io-cluster-adapter");
|
||||
const MESSAGE_SOURCE = "_sio_adapter";
|
||||
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
||||
|
||||
function ignoreError() {}
|
||||
|
||||
/**
|
||||
* Returns a function that will create a NodeClusterAdapter instance.
|
||||
*
|
||||
* @param opts - additional options
|
||||
*
|
||||
* @public
|
||||
* @see https://nodejs.org/api/cluster.html
|
||||
*/
|
||||
export function createAdapter(opts: Partial<ClusterAdapterOptions> = {}) {
|
||||
return function (nsp: any) {
|
||||
return new NodeClusterAdapter(nsp, opts);
|
||||
};
|
||||
}
|
||||
|
||||
export class NodeClusterAdapter extends ClusterAdapterWithHeartbeat {
|
||||
constructor(nsp: any, opts: ClusterAdapterOptions = {}) {
|
||||
super(nsp, opts);
|
||||
process.on("message", (message: any) => {
|
||||
const isValidSource = message?.source === MESSAGE_SOURCE;
|
||||
if (!isValidSource) {
|
||||
debug("[%s] ignore unknown source", this.uid);
|
||||
return;
|
||||
}
|
||||
|
||||
// note: this check should be done in the onMessage() handler
|
||||
if (message.nsp !== this.nsp.name) {
|
||||
debug("[%s] ignore other namespace", this.uid);
|
||||
return;
|
||||
}
|
||||
|
||||
this.onMessage(message);
|
||||
});
|
||||
|
||||
// until https://github.com/socketio/socket.io/commit/f3e1f5ebdf59158d0c8d1e20f8230275617fb355 is released
|
||||
this.init();
|
||||
}
|
||||
|
||||
protected override doPublish(message: ClusterMessage & { source: string }) {
|
||||
message.source = MESSAGE_SOURCE;
|
||||
|
||||
process.send(message, null, {}, ignoreError);
|
||||
|
||||
return Promise.resolve(""); // connection state recovery is not supported
|
||||
}
|
||||
|
||||
protected override doPublishResponse(
|
||||
requesterUid: ServerId,
|
||||
response: ClusterResponse & { source: string; requesterUid: string },
|
||||
) {
|
||||
response.source = MESSAGE_SOURCE;
|
||||
response.requesterUid = requesterUid;
|
||||
|
||||
process.send(response, null, {}, ignoreError);
|
||||
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
const UIDS = Symbol("uids");
|
||||
|
||||
export function setupPrimary() {
|
||||
cluster.on("message", (worker, message) => {
|
||||
const isValidSource = message?.source === MESSAGE_SOURCE;
|
||||
if (!isValidSource) {
|
||||
return;
|
||||
}
|
||||
|
||||
// store the requester's uids (one per namespace) so that the response can be sent specifically to them
|
||||
worker[UIDS] = worker[UIDS] || new Set();
|
||||
worker[UIDS].add(message.uid);
|
||||
|
||||
switch (message.type) {
|
||||
case MessageType.FETCH_SOCKETS_RESPONSE:
|
||||
case MessageType.SERVER_SIDE_EMIT_RESPONSE:
|
||||
const requesterUid = message.requesterUid;
|
||||
for (const workerId in cluster.workers) {
|
||||
if (
|
||||
hasOwnProperty.call(cluster.workers, workerId) &&
|
||||
cluster.workers[workerId][UIDS]?.has(requesterUid)
|
||||
) {
|
||||
cluster.workers[workerId].send(message, null, ignoreError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
const emitterIdAsString = String(worker.id);
|
||||
// emit to all workers but the requester
|
||||
for (const workerId in cluster.workers) {
|
||||
if (
|
||||
hasOwnProperty.call(cluster.workers, workerId) &&
|
||||
workerId !== emitterIdAsString
|
||||
) {
|
||||
cluster.workers[workerId].send(message, null, ignoreError);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
3345
packages/socket.io-cluster-adapter/package-lock.json
generated
Normal file
3345
packages/socket.io-cluster-adapter/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
40
packages/socket.io-cluster-adapter/package.json
Normal file
40
packages/socket.io-cluster-adapter/package.json
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"name": "@socket.io/cluster-adapter",
|
||||
"version": "0.3.0",
|
||||
"description": "The Socket.IO cluster adapter, allowing to broadcast events between several Socket.IO servers",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/socketio/socket.io/tree/main/packages/socket.io-cluster-adapter#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/socketio/socket.io.git"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/socketio/socket.io/issues"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"test": "npm run format:check && npm run compile && nyc mocha --import=tsx test/index.ts",
|
||||
"format:check": "prettier --check \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"format:fix": "prettier --write \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"prepack": "npm run compile"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": "~4.4.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"socket.io-adapter": "~2.5.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"keywords": [
|
||||
"socket.io",
|
||||
"cluster",
|
||||
"adapter"
|
||||
]
|
||||
}
|
||||
372
packages/socket.io-cluster-adapter/test/index.ts
Normal file
372
packages/socket.io-cluster-adapter/test/index.ts
Normal file
@@ -0,0 +1,372 @@
|
||||
import { io as ioc, Socket as ClientSocket } from "socket.io-client";
|
||||
import expect = require("expect.js");
|
||||
import { setupPrimary } from "..";
|
||||
import { times, sleep } from "./util";
|
||||
import cluster, { Worker } from "node:cluster";
|
||||
|
||||
const NODES_COUNT = 3;
|
||||
|
||||
cluster.setupMaster({
|
||||
exec: "./test/worker.js",
|
||||
// @ts-ignore
|
||||
serialization: "advanced", // needed for packets containing buffers
|
||||
});
|
||||
|
||||
setupPrimary();
|
||||
|
||||
const getRooms = (worker): Promise<Set<string>> => {
|
||||
worker.send("get rooms");
|
||||
return new Promise((resolve) => {
|
||||
worker.once("message", (content) => {
|
||||
resolve(content);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe("@socket.io/cluster-adapter", () => {
|
||||
let clientSockets: ClientSocket[], workers: Worker[];
|
||||
|
||||
beforeEach((done) => {
|
||||
clientSockets = [];
|
||||
workers = [];
|
||||
|
||||
for (let i = 1; i <= NODES_COUNT; i++) {
|
||||
const PORT = 40000 + i;
|
||||
const worker = cluster.fork({
|
||||
PORT,
|
||||
});
|
||||
|
||||
worker.on("listening", () => {
|
||||
const clientSocket = ioc(`http://localhost:${PORT}`);
|
||||
|
||||
clientSocket.on("connect", async () => {
|
||||
workers.push(worker);
|
||||
clientSockets.push(clientSocket);
|
||||
if (clientSockets.length === NODES_COUNT) {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
for (const id in cluster.workers) {
|
||||
cluster.workers[id].kill();
|
||||
}
|
||||
clientSockets.forEach((socket) => {
|
||||
socket.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("broadcast", function () {
|
||||
it("broadcasts to all clients", (done) => {
|
||||
const partialDone = times(3, done);
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
clientSocket.on("test", (arg1, arg2, arg3) => {
|
||||
expect(arg1).to.eql(1);
|
||||
expect(arg2).to.eql("2");
|
||||
expect(Buffer.isBuffer(arg3)).to.be(true);
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
|
||||
workers[0].send("broadcasts to all clients");
|
||||
});
|
||||
|
||||
it("broadcasts to all clients in a namespace", (done) => {
|
||||
const partialDone = times(3, done);
|
||||
|
||||
const onConnect = times(3, async () => {
|
||||
workers[0].send("broadcasts to all clients in a namespace");
|
||||
});
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
const socket = clientSocket.io.socket("/custom");
|
||||
socket.on("connect", onConnect);
|
||||
socket.on("test", () => {
|
||||
socket.disconnect();
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts to all clients in a room", (done) => {
|
||||
workers[1].send("join room1");
|
||||
|
||||
clientSockets[0].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
done();
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
workers[0].send("broadcasts to all clients in a room");
|
||||
});
|
||||
|
||||
it("broadcasts to all clients except in room", (done) => {
|
||||
const partialDone = times(2, done);
|
||||
workers[1].send("join room1");
|
||||
|
||||
clientSockets[0].on("test", () => {
|
||||
partialDone();
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
partialDone();
|
||||
});
|
||||
|
||||
workers[0].send("broadcasts to all clients except in room");
|
||||
});
|
||||
|
||||
it("broadcasts to local clients only", (done) => {
|
||||
clientSockets[0].on("test", () => {
|
||||
done();
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
workers[0].send("broadcasts to local clients only");
|
||||
});
|
||||
|
||||
it("broadcasts with multiple acknowledgements", (done) => {
|
||||
clientSockets[0].on("test", (cb) => {
|
||||
cb(1);
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", (cb) => {
|
||||
cb(2);
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", (cb) => {
|
||||
cb(3);
|
||||
});
|
||||
|
||||
workers[0].send("broadcasts with multiple acknowledgements");
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts with multiple acknowledgements (binary content)", (done) => {
|
||||
clientSockets[0].on("test", (cb) => {
|
||||
cb(Buffer.from([1]));
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", (cb) => {
|
||||
cb(Buffer.from([2]));
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", (cb) => {
|
||||
cb(Buffer.from([3]));
|
||||
});
|
||||
|
||||
workers[0].send(
|
||||
"broadcasts with multiple acknowledgements (binary content)",
|
||||
);
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts with multiple acknowledgements (no client)", (done) => {
|
||||
workers[0].send("broadcasts with multiple acknowledgements (no client)");
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts with multiple acknowledgements (timeout)", (done) => {
|
||||
clientSockets[0].on("test", (cb) => {
|
||||
cb(1);
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", (cb) => {
|
||||
cb(2);
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", (cb) => {
|
||||
// do nothing
|
||||
});
|
||||
|
||||
workers[0].send("broadcasts with multiple acknowledgements (timeout)");
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("socketsJoin", () => {
|
||||
it("makes all socket instances join the specified room", async () => {
|
||||
workers[0].send("makes all socket instances join the specified room");
|
||||
|
||||
await sleep(100);
|
||||
|
||||
expect((await getRooms(workers[0])).has("room1")).to.be(true);
|
||||
expect((await getRooms(workers[1])).has("room1")).to.be(true);
|
||||
expect((await getRooms(workers[2])).has("room1")).to.be(true);
|
||||
});
|
||||
|
||||
it("makes the matching socket instances join the specified room", async () => {
|
||||
workers[0].send("join room1");
|
||||
workers[2].send("join room1");
|
||||
|
||||
workers[0].send(
|
||||
"makes the matching socket instances join the specified room",
|
||||
);
|
||||
|
||||
await sleep(100);
|
||||
|
||||
expect((await getRooms(workers[0])).has("room2")).to.be(true);
|
||||
expect((await getRooms(workers[1])).has("room2")).to.be(false);
|
||||
expect((await getRooms(workers[2])).has("room2")).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("socketsLeave", () => {
|
||||
it("makes all socket instances leave the specified room", async () => {
|
||||
workers[0].send("join room1");
|
||||
workers[2].send("join room1");
|
||||
|
||||
workers[0].send("makes all socket instances leave the specified room");
|
||||
|
||||
await sleep(100);
|
||||
|
||||
expect((await getRooms(workers[0])).has("room1")).to.be(false);
|
||||
expect((await getRooms(workers[1])).has("room1")).to.be(false);
|
||||
expect((await getRooms(workers[2])).has("room1")).to.be(false);
|
||||
});
|
||||
|
||||
it("makes the matching socket instances leave the specified room", async () => {
|
||||
workers[0].send("join room1 & room2");
|
||||
workers[2].send("join room2");
|
||||
|
||||
workers[0].send(
|
||||
"makes the matching socket instances leave the specified room",
|
||||
);
|
||||
|
||||
await sleep(100);
|
||||
|
||||
expect((await getRooms(workers[0])).has("room2")).to.be(false);
|
||||
expect((await getRooms(workers[1])).has("room2")).to.be(false);
|
||||
expect((await getRooms(workers[2])).has("room2")).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("disconnectSockets", () => {
|
||||
it("makes all socket instances disconnect", (done) => {
|
||||
const partialDone = times(3, done);
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
clientSocket.on("disconnect", (reason) => {
|
||||
expect(reason).to.eql("io server disconnect");
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
|
||||
workers[0].send("makes all socket instances disconnect");
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchSockets", () => {
|
||||
it("returns all socket instances", (done) => {
|
||||
workers[0].send("returns all socket instances");
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("serverSideEmit", () => {
|
||||
it("sends an event to other server instances", (done) => {
|
||||
const partialDone = times(2, done);
|
||||
|
||||
workers[0].send("sends an event to other server instances");
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done(new Error("should not happen"));
|
||||
}
|
||||
});
|
||||
|
||||
workers[1].on("message", (result) => {
|
||||
expect(result).to.eql("ok");
|
||||
partialDone();
|
||||
});
|
||||
|
||||
workers[2].on("message", (result) => {
|
||||
expect(result).to.eql("ok");
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
|
||||
it("sends an event and receives a response from the other server instances", (done) => {
|
||||
workers[0].send(
|
||||
"sends an event and receives a response from the other server instances (1)",
|
||||
);
|
||||
workers[1].send(
|
||||
"sends an event and receives a response from the other server instances (2)",
|
||||
);
|
||||
workers[2].send(
|
||||
"sends an event and receives a response from the other server instances (3)",
|
||||
);
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("sends an event but timeout if one server does not respond", function (done) {
|
||||
this.timeout(6000); // currently not possible to configure the timeout delay
|
||||
|
||||
workers[0].send(
|
||||
"sends an event but timeout if one server does not respond (1)",
|
||||
);
|
||||
workers[1].send(
|
||||
"sends an event but timeout if one server does not respond (2)",
|
||||
);
|
||||
workers[2].send(
|
||||
"sends an event but timeout if one server does not respond (3)",
|
||||
);
|
||||
|
||||
workers[0].on("message", (result) => {
|
||||
if (result === "ok") {
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
13
packages/socket.io-cluster-adapter/test/util.ts
Normal file
13
packages/socket.io-cluster-adapter/test/util.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export function times(count: number, fn: () => void) {
|
||||
let i = 0;
|
||||
return () => {
|
||||
i++;
|
||||
if (i === count) {
|
||||
fn();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function sleep(duration: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, duration));
|
||||
}
|
||||
182
packages/socket.io-cluster-adapter/test/worker.js
Normal file
182
packages/socket.io-cluster-adapter/test/worker.js
Normal file
@@ -0,0 +1,182 @@
|
||||
const { createServer } = require("http");
|
||||
const { Server } = require("socket.io");
|
||||
const { createAdapter } = require("..");
|
||||
|
||||
const httpServer = createServer();
|
||||
const io = new Server(httpServer);
|
||||
const expect = require("expect.js");
|
||||
|
||||
io.adapter(createAdapter());
|
||||
|
||||
let serverSocket;
|
||||
|
||||
io.on("connection", (socket) => {
|
||||
serverSocket = socket;
|
||||
});
|
||||
|
||||
const customNamespace = io.of("/custom");
|
||||
|
||||
process.on("message", async (msg) => {
|
||||
switch (msg) {
|
||||
case "broadcasts to all clients":
|
||||
io.emit("test", 1, "2", Buffer.from([3, 4]));
|
||||
break;
|
||||
case "broadcasts to all clients in a namespace":
|
||||
customNamespace.emit("test");
|
||||
break;
|
||||
case "join room1":
|
||||
serverSocket.join("room1");
|
||||
break;
|
||||
case "join room1 & room2":
|
||||
serverSocket.join(["room1", "room2"]);
|
||||
break;
|
||||
case "join room2":
|
||||
serverSocket.join("room2");
|
||||
break;
|
||||
case "broadcasts to all clients in a room":
|
||||
io.to("room1").emit("test");
|
||||
break;
|
||||
case "broadcasts to all clients except in room":
|
||||
io.of("/").except("room1").emit("test");
|
||||
break;
|
||||
case "broadcasts to local clients only":
|
||||
io.local.emit("test");
|
||||
break;
|
||||
|
||||
case "broadcasts with multiple acknowledgements": {
|
||||
io.timeout(500).emit("test", (err, responses) => {
|
||||
expect(err).to.be(null);
|
||||
expect(responses).to.contain(1);
|
||||
expect(responses).to.contain(2);
|
||||
expect(responses).to.contain(3);
|
||||
|
||||
setTimeout(() => {
|
||||
expect(io.of("/").adapter.ackRequests.size).to.eql(0);
|
||||
|
||||
process.send("ok");
|
||||
}, 500);
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "broadcasts with multiple acknowledgements (binary content)": {
|
||||
io.timeout(500).emit("test", (err, responses) => {
|
||||
expect(err).to.be(null);
|
||||
responses.forEach((response) => {
|
||||
expect(Buffer.isBuffer(response)).to.be(true);
|
||||
});
|
||||
|
||||
process.send("ok");
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "broadcasts with multiple acknowledgements (no client)": {
|
||||
io
|
||||
.to("abc")
|
||||
.timeout(500)
|
||||
.emit("test", (err, responses) => {
|
||||
expect(err).to.be(null);
|
||||
expect(responses).to.eql([]);
|
||||
|
||||
process.send("ok");
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "broadcasts with multiple acknowledgements (timeout)": {
|
||||
io.timeout(500).emit("test", (err, responses) => {
|
||||
expect(err).to.be.an(Error);
|
||||
expect(responses).to.contain(1);
|
||||
expect(responses).to.contain(2);
|
||||
|
||||
process.send("ok");
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
case "get rooms":
|
||||
process.send(serverSocket.rooms);
|
||||
break;
|
||||
case "makes all socket instances join the specified room":
|
||||
io.socketsJoin("room1");
|
||||
break;
|
||||
|
||||
case "makes the matching socket instances join the specified room":
|
||||
io.in("room1").socketsJoin("room2");
|
||||
break;
|
||||
|
||||
case "makes all socket instances leave the specified room":
|
||||
io.socketsLeave("room1");
|
||||
break;
|
||||
case "makes the matching socket instances leave the specified room":
|
||||
io.in("room1").socketsLeave("room2");
|
||||
break;
|
||||
|
||||
case "makes all socket instances disconnect":
|
||||
io.disconnectSockets();
|
||||
break;
|
||||
|
||||
case "returns all socket instances":
|
||||
const sockets = await io.fetchSockets();
|
||||
|
||||
expect(sockets).to.be.an(Array);
|
||||
expect(sockets).to.have.length(3);
|
||||
expect(io.of("/").adapter.requests.size).to.eql(0); // clean up
|
||||
|
||||
process.send("ok");
|
||||
break;
|
||||
|
||||
case "sends an event to other server instances":
|
||||
io.serverSideEmit("hello", "world", 1, "2");
|
||||
break;
|
||||
case "sends an event and receives a response from the other server instances (1)":
|
||||
io.serverSideEmit("hello with ack", (err, response) => {
|
||||
expect(err).to.be(null);
|
||||
expect(response).to.be.an(Array);
|
||||
expect(response).to.contain(2);
|
||||
expect(response).to.contain("3");
|
||||
process.send("ok");
|
||||
});
|
||||
break;
|
||||
case "sends an event and receives a response from the other server instances (2)":
|
||||
io.on("hello with ack", (cb) => {
|
||||
cb(2);
|
||||
});
|
||||
break;
|
||||
case "sends an event and receives a response from the other server instances (3)":
|
||||
io.on("hello with ack", (cb) => {
|
||||
cb("3");
|
||||
});
|
||||
break;
|
||||
case "sends an event but timeout if one server does not respond (1)":
|
||||
io.serverSideEmit("hello with ack", (err, response) => {
|
||||
expect(err.message).to.be(
|
||||
"timeout reached: missing 1 responses"
|
||||
);
|
||||
expect(response).to.be.an(Array);
|
||||
expect(response).to.contain(2);
|
||||
process.send("ok");
|
||||
});
|
||||
break;
|
||||
case "sends an event but timeout if one server does not respond (2)":
|
||||
io.on("hello with ack", (cb) => {
|
||||
cb(2);
|
||||
});
|
||||
break;
|
||||
case "sends an event but timeout if one server does not respond (3)":
|
||||
io.on("hello with ack", (cb) => {
|
||||
// do nothing
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
io.on("hello", (arg1, arg2, arg3) => {
|
||||
expect(arg1).to.eql("world");
|
||||
expect(arg2).to.eql(1);
|
||||
expect(arg3).to.eql("2");
|
||||
process.send("ok");
|
||||
});
|
||||
|
||||
httpServer.listen(parseInt(process.env.PORT, 10));
|
||||
13
packages/socket.io-cluster-adapter/tsconfig.json
Normal file
13
packages/socket.io-cluster-adapter/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"allowJs": false,
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": [
|
||||
"./lib/**/*"
|
||||
]
|
||||
}
|
||||
@@ -1,4 +1,10 @@
|
||||
import { Server, type ServerOptions, Socket, type Transport } from "engine.io";
|
||||
import {
|
||||
Server,
|
||||
type ServerOptions,
|
||||
type ErrorCallback,
|
||||
Socket,
|
||||
type Transport,
|
||||
} from "engine.io";
|
||||
import { randomBytes } from "node:crypto";
|
||||
import { setTimeout, clearTimeout } from "node:timers";
|
||||
import { type IncomingMessage } from "node:http";
|
||||
@@ -392,9 +398,9 @@ export abstract class ClusterEngine extends Server {
|
||||
override verify(
|
||||
req: IncomingMessage & { _query: Record<string, string> },
|
||||
upgrade: boolean,
|
||||
fn: (errorCode?: number, context?: any) => void,
|
||||
fn: ErrorCallback,
|
||||
): void {
|
||||
super.verify(req, upgrade, (errorCode: number, errorContext: any) => {
|
||||
super.verify(req, upgrade, (errorCode, errorContext) => {
|
||||
if (errorCode !== Server.errors.UNKNOWN_SID) {
|
||||
return fn(errorCode, errorContext);
|
||||
}
|
||||
@@ -412,7 +418,7 @@ export abstract class ClusterEngine extends Server {
|
||||
req[kSenderId] = senderId;
|
||||
fn();
|
||||
} else {
|
||||
const transport = this.createTransport(transportName, req);
|
||||
const transport = this.createTransport(transportName as any, req);
|
||||
this._hookTransport(sid, transport, lockType, senderId);
|
||||
transport.onRequest(req);
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@msgpack/msgpack": "~2.8.0",
|
||||
"debug": "~4.3.3",
|
||||
"debug": "~4.4.1",
|
||||
"engine.io": "~6.6.0",
|
||||
"engine.io-parser": "~5.2.3"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"test": "npm run format:check && npm run compile && npm run test:unit",
|
||||
"test:unit": "mocha --require ts-node/register test/*.ts",
|
||||
"test:unit": "mocha --import=tsx test/*.ts",
|
||||
"format:check": "prettier --check \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"format:fix": "prettier --write \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"prepack": "npm run compile"
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@socket.io/component-emitter": "~3.1.0",
|
||||
"debug": "~4.3.1"
|
||||
"debug": "~4.4.1"
|
||||
},
|
||||
"scripts": {
|
||||
"compile": "rimraf ./build && tsc && tsc -p tsconfig.esm.json && ./postcompile.sh",
|
||||
|
||||
@@ -53,7 +53,7 @@ if (process.env.CI === "true") {
|
||||
{
|
||||
browserName: "internet explorer",
|
||||
browserVersion: "10",
|
||||
platformName: "Windows 7",
|
||||
platformName: "Windows 8",
|
||||
"sauce:options": BASE_SAUCE_OPTIONS,
|
||||
},
|
||||
{
|
||||
|
||||
19
packages/socket.io-postgres-emitter/CHANGELOG.md
Normal file
19
packages/socket.io-postgres-emitter/CHANGELOG.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# History
|
||||
|
||||
| Version | Release date |
|
||||
|--------------------------|----------------|
|
||||
| [0.1.1](#011-2025-09-05) | September 2025 |
|
||||
| [0.1.0](#010-2021-06-14) | June 2021 |
|
||||
|
||||
# Release notes
|
||||
|
||||
## 0.1.1 (2025-09-05)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* use parameterized query to send the NOTIFY command ([32257b6](https://github.com/socketio/socket.io/commit/32257b6cb89f9dac15e69e1d6ee76365ff262170))
|
||||
|
||||
|
||||
## 0.1.0 (2021-06-14)
|
||||
|
||||
Initial release!
|
||||
7
packages/socket.io-postgres-emitter/LICENSE
Normal file
7
packages/socket.io-postgres-emitter/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2021 Damien Arrachequesne (@darrachequesne)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
152
packages/socket.io-postgres-emitter/README.md
Normal file
152
packages/socket.io-postgres-emitter/README.md
Normal file
@@ -0,0 +1,152 @@
|
||||
# Socket.IO Postgres emitter
|
||||
|
||||
The `@socket.io/postgres-emitter` package allows you to easily communicate with a group of Socket.IO servers from another Node.js process (server-side).
|
||||
|
||||
<picture>
|
||||
<source media="(prefers-color-scheme: dark)" srcset="./assets/emitter_dark.png">
|
||||
<img alt="Diagram of Socket.IO packets forwarded through PostgreSQL" src="./assets/emitter.png">
|
||||
</picture>
|
||||
|
||||
It must be used in conjunction with [`@socket.io/postgres-adapter`](https://github.com/socketio/socket.io-postgres-adapter/).
|
||||
|
||||
Supported features:
|
||||
|
||||
- [broadcasting](https://socket.io/docs/v4/broadcasting-events/)
|
||||
- [utility methods](https://socket.io/docs/v4/server-instance/#Utility-methods)
|
||||
- [`socketsJoin`](https://socket.io/docs/v4/server-instance/#socketsJoin)
|
||||
- [`socketsLeave`](https://socket.io/docs/v4/server-instance/#socketsLeave)
|
||||
- [`disconnectSockets`](https://socket.io/docs/v4/server-instance/#disconnectSockets)
|
||||
- [`serverSideEmit`](https://socket.io/docs/v4/server-instance/#serverSideEmit)
|
||||
|
||||
Related packages:
|
||||
|
||||
- Postgres adapter: https://github.com/socketio/socket.io-postgres-adapter/
|
||||
- Redis adapter: https://github.com/socketio/socket.io-redis-adapter/
|
||||
- Redis emitter: https://github.com/socketio/socket.io-redis-emitter/
|
||||
- MongoDB adapter: https://github.com/socketio/socket.io-mongo-adapter/
|
||||
- MongoDB emitter: https://github.com/socketio/socket.io-mongo-emitter/
|
||||
|
||||
**Table of contents**
|
||||
|
||||
- [Installation](#installation)
|
||||
- [Usage](#usage)
|
||||
- [API](#api)
|
||||
- [Known errors](#known-errors)
|
||||
- [License](#license)
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install @socket.io/postgres-emitter pg
|
||||
```
|
||||
|
||||
For TypeScript users, you might also need `@types/pg`.
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const { Emitter } = require("@socket.io/postgres-emitter");
|
||||
const { Pool } = require("pg");
|
||||
|
||||
const pool = new Pool({
|
||||
user: "postgres",
|
||||
host: "localhost",
|
||||
database: "postgres",
|
||||
password: "changeit",
|
||||
port: 5432,
|
||||
});
|
||||
|
||||
const io = new Emitter(pool);
|
||||
|
||||
setInterval(() => {
|
||||
io.emit("ping", new Date());
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `Emitter(pool[, nsp][, opts])`
|
||||
|
||||
```js
|
||||
const io = new Emitter(pool);
|
||||
```
|
||||
|
||||
The `pool` argument is a [Pool object](https://node-postgres.com/api/pool) from the `pg` package.
|
||||
|
||||
### `Emitter#to(room:string):BroadcastOperator`
|
||||
### `Emitter#in(room:string):BroadcastOperator`
|
||||
|
||||
Specifies a specific `room` that you want to emit to.
|
||||
|
||||
```js
|
||||
io.to("room1").emit("hello");
|
||||
```
|
||||
|
||||
### `Emitter#except(room:string):BroadcastOperator`
|
||||
|
||||
Specifies a specific `room` that you want to exclude from broadcasting.
|
||||
|
||||
```js
|
||||
io.except("room2").emit("hello");
|
||||
```
|
||||
|
||||
### `Emitter#of(namespace:string):Emitter`
|
||||
|
||||
Specifies a specific namespace that you want to emit to.
|
||||
|
||||
```js
|
||||
const customNamespace = io.of("/custom");
|
||||
|
||||
customNamespace.emit("hello");
|
||||
```
|
||||
|
||||
### `Emitter#socketsJoin(rooms:string|string[])`
|
||||
|
||||
Makes the matching socket instances join the specified rooms:
|
||||
|
||||
```js
|
||||
// make all Socket instances join the "room1" room
|
||||
io.socketsJoin("room1");
|
||||
|
||||
// make all Socket instances of the "admin" namespace in the "room1" room join the "room2" room
|
||||
io.of("/admin").in("room1").socketsJoin("room2");
|
||||
```
|
||||
|
||||
### `Emitter#socketsLeave(rooms:string|string[])`
|
||||
|
||||
Makes the matching socket instances leave the specified rooms:
|
||||
|
||||
```js
|
||||
// make all Socket instances leave the "room1" room
|
||||
io.socketsLeave("room1");
|
||||
|
||||
// make all Socket instances of the "admin" namespace in the "room1" room leave the "room2" room
|
||||
io.of("/admin").in("room1").socketsLeave("room2");
|
||||
```
|
||||
|
||||
### `Emitter#disconnectSockets(close:boolean)`
|
||||
|
||||
Makes the matching socket instances disconnect:
|
||||
|
||||
```js
|
||||
// make all Socket instances disconnect
|
||||
io.disconnectSockets();
|
||||
|
||||
// make all Socket instances of the "admin" namespace in the "room1" room disconnect
|
||||
io.of("/admin").in("room1").disconnectSockets();
|
||||
|
||||
// this also works with a single socket ID
|
||||
io.of("/admin").in(theSocketId).disconnectSockets();
|
||||
```
|
||||
|
||||
### `Emitter#serverSideEmit(ev:string[,...args:any[]])`
|
||||
|
||||
Emits an event that will be received by each Socket.IO server of the cluster.
|
||||
|
||||
```js
|
||||
io.serverSideEmit("ping");
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
1380
packages/socket.io-postgres-emitter/assets/emitter.excalidraw
Normal file
1380
packages/socket.io-postgres-emitter/assets/emitter.excalidraw
Normal file
File diff suppressed because it is too large
Load Diff
BIN
packages/socket.io-postgres-emitter/assets/emitter.png
Normal file
BIN
packages/socket.io-postgres-emitter/assets/emitter.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 89 KiB |
BIN
packages/socket.io-postgres-emitter/assets/emitter_dark.png
Normal file
BIN
packages/socket.io-postgres-emitter/assets/emitter_dark.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 116 KiB |
7
packages/socket.io-postgres-emitter/compose.yaml
Normal file
7
packages/socket.io-postgres-emitter/compose.yaml
Normal file
@@ -0,0 +1,7 @@
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:14
|
||||
ports:
|
||||
- "5432:5432"
|
||||
environment:
|
||||
POSTGRES_PASSWORD: "changeit"
|
||||
536
packages/socket.io-postgres-emitter/lib/index.ts
Normal file
536
packages/socket.io-postgres-emitter/lib/index.ts
Normal file
@@ -0,0 +1,536 @@
|
||||
import debugModule from "debug";
|
||||
import type {
|
||||
DefaultEventsMap,
|
||||
EventNames,
|
||||
EventParams,
|
||||
EventsMap,
|
||||
TypedEventBroadcaster,
|
||||
} from "./typed-events";
|
||||
import { encode } from "@msgpack/msgpack";
|
||||
|
||||
const debug = debugModule("socket.io-postgres-emitter");
|
||||
const EMITTER_UID = "emitter";
|
||||
|
||||
const hasBinary = (obj: any, toJSON?: boolean): boolean => {
|
||||
if (!obj || typeof obj !== "object") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj instanceof ArrayBuffer || ArrayBuffer.isView(obj)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
for (let i = 0, l = obj.length; i < l; i++) {
|
||||
if (hasBinary(obj[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.toJSON && typeof obj.toJSON === "function" && !toJSON) {
|
||||
return hasBinary(obj.toJSON(), true);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Event types, for messages between nodes
|
||||
*/
|
||||
|
||||
enum EventType {
|
||||
INITIAL_HEARTBEAT = 1,
|
||||
HEARTBEAT,
|
||||
BROADCAST,
|
||||
SOCKETS_JOIN,
|
||||
SOCKETS_LEAVE,
|
||||
DISCONNECT_SOCKETS,
|
||||
FETCH_SOCKETS,
|
||||
FETCH_SOCKETS_RESPONSE,
|
||||
SERVER_SIDE_EMIT,
|
||||
SERVER_SIDE_EMIT_RESPONSE,
|
||||
}
|
||||
|
||||
interface BroadcastFlags {
|
||||
volatile?: boolean;
|
||||
compress?: boolean;
|
||||
}
|
||||
|
||||
export interface PostgresEmitterOptions {
|
||||
/**
|
||||
* The prefix of the notification channel
|
||||
* @default "socket.io"
|
||||
*/
|
||||
channelPrefix: string;
|
||||
/**
|
||||
* The name of the table for payloads over the 8000 bytes limit or containing binary data
|
||||
*/
|
||||
tableName: string;
|
||||
/**
|
||||
* The threshold for the payload size in bytes (see https://www.postgresql.org/docs/current/sql-notify.html)
|
||||
* @default 8000
|
||||
*/
|
||||
payloadThreshold: number;
|
||||
}
|
||||
|
||||
export class Emitter<
|
||||
EmitEvents extends EventsMap = DefaultEventsMap,
|
||||
ServerSideEvents extends EventsMap = DefaultEventsMap,
|
||||
> {
|
||||
public readonly channel: string;
|
||||
public readonly tableName: string;
|
||||
public payloadThreshold: number;
|
||||
|
||||
constructor(
|
||||
readonly pool: any,
|
||||
readonly nsp: string = "/",
|
||||
opts: Partial<PostgresEmitterOptions> = {},
|
||||
) {
|
||||
const channelPrefix = opts.channelPrefix || "socket.io";
|
||||
this.channel = `${channelPrefix}#${nsp}`;
|
||||
this.tableName = opts.tableName || "socket_io_attachments";
|
||||
this.payloadThreshold = opts.payloadThreshold || 8000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a new emitter for the given namespace.
|
||||
*
|
||||
* @param nsp - namespace
|
||||
* @public
|
||||
*/
|
||||
public of(nsp: string): Emitter {
|
||||
return new Emitter(this.pool, (nsp[0] !== "/" ? "/" : "") + nsp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits to all clients.
|
||||
*
|
||||
* @return Always true
|
||||
* @public
|
||||
*/
|
||||
public emit<Ev extends EventNames<EmitEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<EmitEvents, Ev>
|
||||
): true {
|
||||
return new BroadcastOperator<EmitEvents, ServerSideEvents>(this).emit(
|
||||
ev,
|
||||
...args,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public to(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return new BroadcastOperator(this).to(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public in(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return new BroadcastOperator(this).in(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public except(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return new BroadcastOperator(this).except(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
|
||||
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
|
||||
* and is in the middle of a request-response cycle).
|
||||
*
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public get volatile(): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return new BroadcastOperator(this).volatile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compress flag.
|
||||
*
|
||||
* @param compress - if `true`, compresses the sending data
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public compress(
|
||||
compress: boolean,
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return new BroadcastOperator(this).compress(compress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances join the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsJoin(rooms: string | string[]): void {
|
||||
return new BroadcastOperator(this).socketsJoin(rooms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances leave the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsLeave(rooms: string | string[]): void {
|
||||
return new BroadcastOperator(this).socketsLeave(rooms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances disconnect
|
||||
*
|
||||
* @param close - whether to close the underlying connection
|
||||
* @public
|
||||
*/
|
||||
public disconnectSockets(close: boolean = false): void {
|
||||
return new BroadcastOperator(this).disconnectSockets(close);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the Socket.IO servers in the cluster
|
||||
*
|
||||
* @param ev - the event name
|
||||
* @param args - any number of serializable arguments
|
||||
*/
|
||||
public serverSideEmit<Ev extends EventNames<ServerSideEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<ServerSideEvents, Ev>
|
||||
): void {
|
||||
return new BroadcastOperator<EmitEvents, ServerSideEvents>(
|
||||
this,
|
||||
).serverSideEmit(ev, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
export const RESERVED_EVENTS: ReadonlySet<string | Symbol> = new Set(<const>[
|
||||
"connect",
|
||||
"connect_error",
|
||||
"disconnect",
|
||||
"disconnecting",
|
||||
"newListener",
|
||||
"removeListener",
|
||||
]);
|
||||
|
||||
export class BroadcastOperator<
|
||||
EmitEvents extends EventsMap,
|
||||
ServerSideEvents extends EventsMap,
|
||||
> implements TypedEventBroadcaster<EmitEvents>
|
||||
{
|
||||
constructor(
|
||||
private readonly emitter: Emitter,
|
||||
private readonly rooms: Set<string> = new Set<string>(),
|
||||
private readonly exceptRooms: Set<string> = new Set<string>(),
|
||||
private readonly flags: BroadcastFlags = {},
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public to(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const rooms = new Set(this.rooms);
|
||||
if (Array.isArray(room)) {
|
||||
room.forEach((r) => rooms.add(r));
|
||||
} else {
|
||||
rooms.add(room);
|
||||
}
|
||||
return new BroadcastOperator(
|
||||
this.emitter,
|
||||
rooms,
|
||||
this.exceptRooms,
|
||||
this.flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public in(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.to(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public except(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const exceptRooms = new Set(this.exceptRooms);
|
||||
if (Array.isArray(room)) {
|
||||
room.forEach((r) => exceptRooms.add(r));
|
||||
} else {
|
||||
exceptRooms.add(room);
|
||||
}
|
||||
return new BroadcastOperator(
|
||||
this.emitter,
|
||||
this.rooms,
|
||||
exceptRooms,
|
||||
this.flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compress flag.
|
||||
*
|
||||
* @param compress - if `true`, compresses the sending data
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public compress(
|
||||
compress: boolean,
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const flags = Object.assign({}, this.flags, { compress });
|
||||
return new BroadcastOperator(
|
||||
this.emitter,
|
||||
this.rooms,
|
||||
this.exceptRooms,
|
||||
flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
|
||||
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
|
||||
* and is in the middle of a request-response cycle).
|
||||
*
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public get volatile(): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const flags = Object.assign({}, this.flags, { volatile: true });
|
||||
return new BroadcastOperator(
|
||||
this.emitter,
|
||||
this.rooms,
|
||||
this.exceptRooms,
|
||||
flags,
|
||||
);
|
||||
}
|
||||
|
||||
private async publish(document: any) {
|
||||
document.uid = EMITTER_UID;
|
||||
|
||||
try {
|
||||
if (
|
||||
[
|
||||
EventType.BROADCAST,
|
||||
EventType.SERVER_SIDE_EMIT,
|
||||
EventType.SERVER_SIDE_EMIT_RESPONSE,
|
||||
].includes(document.type) &&
|
||||
hasBinary(document)
|
||||
) {
|
||||
return await this.publishWithAttachment(document);
|
||||
}
|
||||
|
||||
const payload = JSON.stringify(document);
|
||||
if (Buffer.byteLength(payload) > this.emitter.payloadThreshold) {
|
||||
return await this.publishWithAttachment(document);
|
||||
}
|
||||
|
||||
debug(
|
||||
"sending event of type %s to channel %s",
|
||||
document.type,
|
||||
this.emitter.channel,
|
||||
);
|
||||
await this.emitter.pool.query("SELECT pg_notify($1, $2)", [
|
||||
this.emitter.channel,
|
||||
payload,
|
||||
]);
|
||||
} catch (err) {
|
||||
// @ts-ignore
|
||||
this.emit("error", err);
|
||||
}
|
||||
}
|
||||
|
||||
private async publishWithAttachment(document: any) {
|
||||
const payload = encode(document);
|
||||
|
||||
debug(
|
||||
"sending event of type %s with attachment to channel %s",
|
||||
document.type,
|
||||
this.emitter.channel,
|
||||
);
|
||||
const result = await this.emitter.pool.query(
|
||||
`INSERT INTO ${this.emitter.tableName} (payload) VALUES ($1) RETURNING id;`,
|
||||
[payload],
|
||||
);
|
||||
const attachmentId = result.rows[0].id;
|
||||
const headerPayload = JSON.stringify({
|
||||
uid: document.uid,
|
||||
type: document.type,
|
||||
attachmentId,
|
||||
});
|
||||
await this.emitter.pool.query("SELECT pg_notify($1, $2)", [
|
||||
this.emitter.channel,
|
||||
headerPayload,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits to all clients.
|
||||
*
|
||||
* @return Always true
|
||||
* @public
|
||||
*/
|
||||
public emit<Ev extends EventNames<EmitEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<EmitEvents, Ev>
|
||||
): true {
|
||||
if (RESERVED_EVENTS.has(ev)) {
|
||||
throw new Error(`"${String(ev)}" is a reserved event name`);
|
||||
}
|
||||
|
||||
// set up packet object
|
||||
const data = [ev, ...args];
|
||||
const packet = {
|
||||
type: 2, // EVENT
|
||||
data: data,
|
||||
nsp: this.emitter.nsp,
|
||||
};
|
||||
|
||||
const opts = {
|
||||
rooms: [...this.rooms],
|
||||
flags: this.flags,
|
||||
except: [...this.exceptRooms],
|
||||
};
|
||||
|
||||
this.publish({
|
||||
type: EventType.BROADCAST,
|
||||
data: {
|
||||
packet,
|
||||
opts,
|
||||
},
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances join the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsJoin(rooms: string | string[]): void {
|
||||
this.publish({
|
||||
type: EventType.SOCKETS_JOIN,
|
||||
data: {
|
||||
opts: {
|
||||
rooms: [...this.rooms],
|
||||
except: [...this.exceptRooms],
|
||||
},
|
||||
rooms: Array.isArray(rooms) ? rooms : [rooms],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances leave the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsLeave(rooms: string | string[]): void {
|
||||
this.publish({
|
||||
type: EventType.SOCKETS_LEAVE,
|
||||
data: {
|
||||
opts: {
|
||||
rooms: [...this.rooms],
|
||||
except: [...this.exceptRooms],
|
||||
},
|
||||
rooms: Array.isArray(rooms) ? rooms : [rooms],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances disconnect
|
||||
*
|
||||
* @param close - whether to close the underlying connection
|
||||
* @public
|
||||
*/
|
||||
public disconnectSockets(close: boolean = false): void {
|
||||
this.publish({
|
||||
type: EventType.DISCONNECT_SOCKETS,
|
||||
data: {
|
||||
opts: {
|
||||
rooms: [...this.rooms],
|
||||
except: [...this.exceptRooms],
|
||||
},
|
||||
close,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the Socket.IO servers in the cluster
|
||||
*
|
||||
* @param ev - the event name
|
||||
* @param args - any number of serializable arguments
|
||||
*/
|
||||
public serverSideEmit<Ev extends EventNames<ServerSideEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<ServerSideEvents, Ev>
|
||||
): void {
|
||||
const withAck = args.length && typeof args[args.length - 1] === "function";
|
||||
|
||||
if (withAck) {
|
||||
throw new Error("Acknowledgements are not supported");
|
||||
}
|
||||
|
||||
this.publish({
|
||||
type: EventType.SERVER_SIDE_EMIT,
|
||||
data: {
|
||||
packet: [ev, ...args],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
37
packages/socket.io-postgres-emitter/lib/typed-events.ts
Normal file
37
packages/socket.io-postgres-emitter/lib/typed-events.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* An events map is an interface that maps event names to their value, which
|
||||
* represents the type of the `on` listener.
|
||||
*/
|
||||
export interface EventsMap {
|
||||
[event: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default events map, used if no EventsMap is given. Using this EventsMap
|
||||
* is equivalent to accepting all event names, and any data.
|
||||
*/
|
||||
export interface DefaultEventsMap {
|
||||
[event: string]: (...args: any[]) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a union type containing all the keys of an event map.
|
||||
*/
|
||||
export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol);
|
||||
|
||||
/** The tuple type representing the parameters of an event listener */
|
||||
export type EventParams<
|
||||
Map extends EventsMap,
|
||||
Ev extends EventNames<Map>,
|
||||
> = Parameters<Map[Ev]>;
|
||||
|
||||
/**
|
||||
* Interface for classes that aren't `EventEmitter`s, but still expose a
|
||||
* strictly typed `emit` method.
|
||||
*/
|
||||
export interface TypedEventBroadcaster<EmitEvents extends EventsMap> {
|
||||
emit<Ev extends EventNames<EmitEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<EmitEvents, Ev>
|
||||
): boolean;
|
||||
}
|
||||
33
packages/socket.io-postgres-emitter/package.json
Normal file
33
packages/socket.io-postgres-emitter/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@socket.io/postgres-emitter",
|
||||
"version": "0.1.1",
|
||||
"description": "The Socket.IO Postgres emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/socketio/socket.io/tree/main/packages/socket.io-postgres-emitter#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/socketio/socket.io.git"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"test": "npm run format:check && npm run compile && nyc mocha --import=tsx --timeout 5000 test/index.ts",
|
||||
"format:check": "prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"format:fix": "prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"prepack": "npm run compile"
|
||||
},
|
||||
"dependencies": {
|
||||
"@msgpack/msgpack": "^2.7.0",
|
||||
"debug": "~4.4.1"
|
||||
},
|
||||
"keywords": [
|
||||
"socket.io",
|
||||
"postgres",
|
||||
"postgresql",
|
||||
"emitter"
|
||||
]
|
||||
}
|
||||
278
packages/socket.io-postgres-emitter/test/index.ts
Normal file
278
packages/socket.io-postgres-emitter/test/index.ts
Normal file
@@ -0,0 +1,278 @@
|
||||
import { createServer } from "http";
|
||||
import { Server, Socket as ServerSocket } from "socket.io";
|
||||
import { io as ioc, Socket as ClientSocket } from "socket.io-client";
|
||||
import expect = require("expect.js");
|
||||
import { createAdapter } from "@socket.io/postgres-adapter";
|
||||
import type { AddressInfo } from "net";
|
||||
import { Pool } from "pg";
|
||||
import { times, sleep } from "./util";
|
||||
import { Emitter } from "..";
|
||||
|
||||
const NODES_COUNT = 3;
|
||||
|
||||
describe("@socket.io/postgres-emitter", () => {
|
||||
let servers: Server[],
|
||||
serverSockets: ServerSocket[],
|
||||
clientSockets: ClientSocket[],
|
||||
pool: Pool,
|
||||
emitter: Emitter;
|
||||
|
||||
beforeEach((done) => {
|
||||
servers = [];
|
||||
serverSockets = [];
|
||||
clientSockets = [];
|
||||
pool = new Pool({
|
||||
user: "postgres",
|
||||
host: "localhost",
|
||||
database: "postgres",
|
||||
password: "changeit",
|
||||
port: 5432,
|
||||
});
|
||||
|
||||
pool.query(
|
||||
`
|
||||
CREATE TABLE IF NOT EXISTS socket_io_attachments (
|
||||
id bigserial UNIQUE,
|
||||
created_at timestamptz DEFAULT NOW(),
|
||||
payload bytea
|
||||
);
|
||||
`,
|
||||
() => {},
|
||||
);
|
||||
|
||||
emitter = new Emitter(pool);
|
||||
|
||||
for (let i = 1; i <= NODES_COUNT; i++) {
|
||||
const httpServer = createServer();
|
||||
const io = new Server(httpServer);
|
||||
// @ts-ignore
|
||||
io.adapter(createAdapter(pool));
|
||||
httpServer.listen(() => {
|
||||
const port = (httpServer.address() as AddressInfo).port;
|
||||
const clientSocket = ioc(`http://localhost:${port}`);
|
||||
|
||||
io.on("connection", async (socket) => {
|
||||
clientSockets.push(clientSocket);
|
||||
serverSockets.push(socket);
|
||||
servers.push(io);
|
||||
if (servers.length === NODES_COUNT) {
|
||||
// ensure all nodes know each other
|
||||
servers[0].emit("ping");
|
||||
servers[1].emit("ping");
|
||||
servers[2].emit("ping");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
afterEach((done) => {
|
||||
servers.forEach((server) => {
|
||||
// @ts-ignore
|
||||
server.httpServer.close();
|
||||
server.of("/").adapter.close();
|
||||
});
|
||||
clientSockets.forEach((socket) => {
|
||||
socket.disconnect();
|
||||
});
|
||||
pool.end(done);
|
||||
});
|
||||
|
||||
describe("broadcast", function () {
|
||||
it("broadcasts to all clients", (done) => {
|
||||
const partialDone = times(3, done);
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
clientSocket.on("test", (arg1, arg2, arg3) => {
|
||||
expect(arg1).to.eql(1);
|
||||
expect(arg2).to.eql("2");
|
||||
expect(Buffer.isBuffer(arg3)).to.be(true);
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
|
||||
emitter.emit("test", 1, "2", Buffer.from([3, 4]));
|
||||
});
|
||||
|
||||
it("broadcasts to all clients in a namespace", (done) => {
|
||||
const partialDone = times(3, () => {
|
||||
servers.forEach((server) => server.of("/custom").adapter.close());
|
||||
done();
|
||||
});
|
||||
|
||||
servers.forEach((server) => server.of("/custom"));
|
||||
|
||||
const onConnect = times(3, async () => {
|
||||
await sleep(200);
|
||||
|
||||
emitter.of("/custom").emit("test");
|
||||
});
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
const socket = clientSocket.io.socket("/custom");
|
||||
socket.on("connect", onConnect);
|
||||
socket.on("test", () => {
|
||||
socket.disconnect();
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts to all clients in a room", (done) => {
|
||||
serverSockets[1].join("room1");
|
||||
|
||||
clientSockets[0].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
done();
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
emitter.to("room1").emit("test");
|
||||
});
|
||||
|
||||
it("broadcasts to all clients except in room", (done) => {
|
||||
const partialDone = times(2, done);
|
||||
serverSockets[1].join("room1");
|
||||
|
||||
clientSockets[0].on("test", () => {
|
||||
partialDone();
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
done(new Error("should not happen"));
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
partialDone();
|
||||
});
|
||||
|
||||
emitter.of("/").except("room1").emit("test");
|
||||
});
|
||||
});
|
||||
|
||||
describe("socketsJoin", () => {
|
||||
it("makes all socket instances join the specified room", async () => {
|
||||
emitter.socketsJoin("room1");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
expect(serverSockets[0].rooms.has("room1")).to.be(true);
|
||||
expect(serverSockets[1].rooms.has("room1")).to.be(true);
|
||||
expect(serverSockets[2].rooms.has("room1")).to.be(true);
|
||||
});
|
||||
|
||||
it("makes the matching socket instances join the specified room", async () => {
|
||||
serverSockets[0].join("room1");
|
||||
serverSockets[2].join("room1");
|
||||
|
||||
emitter.in("room1").socketsJoin("room2");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
expect(serverSockets[0].rooms.has("room2")).to.be(true);
|
||||
expect(serverSockets[1].rooms.has("room2")).to.be(false);
|
||||
expect(serverSockets[2].rooms.has("room2")).to.be(true);
|
||||
});
|
||||
|
||||
it("makes the given socket instance join the specified room", async () => {
|
||||
emitter.in(serverSockets[1].id).socketsJoin("room3");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
expect(serverSockets[0].rooms.has("room3")).to.be(false);
|
||||
expect(serverSockets[1].rooms.has("room3")).to.be(true);
|
||||
expect(serverSockets[2].rooms.has("room3")).to.be(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("socketsLeave", () => {
|
||||
it("makes all socket instances leave the specified room", async () => {
|
||||
serverSockets[0].join("room1");
|
||||
serverSockets[2].join("room1");
|
||||
|
||||
emitter.socketsLeave("room1");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
expect(serverSockets[0].rooms.has("room1")).to.be(false);
|
||||
expect(serverSockets[1].rooms.has("room1")).to.be(false);
|
||||
expect(serverSockets[2].rooms.has("room1")).to.be(false);
|
||||
});
|
||||
|
||||
it("makes the matching socket instances leave the specified room", async () => {
|
||||
serverSockets[0].join(["room1", "room2"]);
|
||||
serverSockets[1].join(["room1", "room2"]);
|
||||
serverSockets[2].join(["room2"]);
|
||||
|
||||
emitter.in("room1").socketsLeave("room2");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
expect(serverSockets[0].rooms.has("room2")).to.be(false);
|
||||
expect(serverSockets[1].rooms.has("room2")).to.be(false);
|
||||
expect(serverSockets[2].rooms.has("room2")).to.be(true);
|
||||
});
|
||||
|
||||
it("makes the given socket instance leave the specified room", async () => {
|
||||
serverSockets[0].join("room3");
|
||||
serverSockets[1].join("room3");
|
||||
serverSockets[2].join("room3");
|
||||
|
||||
emitter.in(serverSockets[1].id).socketsLeave("room3");
|
||||
|
||||
await sleep(200);
|
||||
|
||||
expect(serverSockets[0].rooms.has("room3")).to.be(true);
|
||||
expect(serverSockets[1].rooms.has("room3")).to.be(false);
|
||||
expect(serverSockets[2].rooms.has("room3")).to.be(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("disconnectSockets", () => {
|
||||
it("makes all socket instances disconnect", (done) => {
|
||||
const partialDone = times(3, done);
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
clientSocket.on("disconnect", (reason) => {
|
||||
expect(reason).to.eql("io server disconnect");
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
|
||||
emitter.disconnectSockets();
|
||||
});
|
||||
});
|
||||
|
||||
describe("serverSideEmit", () => {
|
||||
it("sends an event to other server instances", (done) => {
|
||||
const partialDone = times(3, done);
|
||||
|
||||
emitter.serverSideEmit("hello", "world", 1, "2");
|
||||
|
||||
servers[0].on("hello", (arg1, arg2, arg3) => {
|
||||
expect(arg1).to.eql("world");
|
||||
expect(arg2).to.eql(1);
|
||||
expect(arg3).to.eql("2");
|
||||
partialDone();
|
||||
});
|
||||
|
||||
servers[1].on("hello", (arg1, arg2, arg3) => {
|
||||
partialDone();
|
||||
});
|
||||
|
||||
servers[2].of("/").on("hello", () => {
|
||||
partialDone();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
13
packages/socket.io-postgres-emitter/test/util.ts
Normal file
13
packages/socket.io-postgres-emitter/test/util.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export function times(count: number, fn: () => void) {
|
||||
let i = 0;
|
||||
return () => {
|
||||
i++;
|
||||
if (i === count) {
|
||||
fn();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function sleep(duration: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, duration));
|
||||
}
|
||||
12
packages/socket.io-postgres-emitter/tsconfig.json
Normal file
12
packages/socket.io-postgres-emitter/tsconfig.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"allowJs": false,
|
||||
"target": "es2017",
|
||||
"module": "commonjs",
|
||||
"declaration": true
|
||||
},
|
||||
"include": [
|
||||
"./lib/**/*"
|
||||
]
|
||||
}
|
||||
19
packages/socket.io-redis-streams-emitter/CHANGELOG.md
Normal file
19
packages/socket.io-redis-streams-emitter/CHANGELOG.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# Changelog
|
||||
|
||||
| Version | Release date |
|
||||
|--------------------------|---------------|
|
||||
| [0.1.1](#011-2025-11-07) | November 2025 |
|
||||
| [0.1.0](#010-2025-11-06) | November 2025 |
|
||||
|
||||
|
||||
## [0.1.1](https://github.com/socketio/socket.io/compare/@socket.io/redis-streams-emitter@0.1.0...@socket.io/redis-streams-emitter@0.1.1) (2025-11-07)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* remove dependency on socket.io-adapter ([7617707](https://github.com/socketio/socket.io/commit/7617707ed8f0defd0e19cb7c6963504ce7b87f6b))
|
||||
|
||||
|
||||
## 0.1.0 (2025-11-06)
|
||||
|
||||
Initial release!
|
||||
7
packages/socket.io-redis-streams-emitter/LICENSE
Normal file
7
packages/socket.io-redis-streams-emitter/LICENSE
Normal file
@@ -0,0 +1,7 @@
|
||||
Copyright (c) 2025-present Guillermo Rauch and Socket.IO contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
220
packages/socket.io-redis-streams-emitter/README.md
Normal file
220
packages/socket.io-redis-streams-emitter/README.md
Normal file
@@ -0,0 +1,220 @@
|
||||
# Socket.IO Redis Streams emitter
|
||||
|
||||
The `@socket.io/redis-streams-emitter` package allows you to easily communicate with a group of Socket.IO servers from another Node.js process (server-side).
|
||||
|
||||
It must be used in conjunction with [`@socket.io/redis-streams-adapter`](https://github.com/socketio/socket.io-redis-streams-adapter).
|
||||
|
||||
**Table of contents**
|
||||
|
||||
<!-- TOC -->
|
||||
* [Installation](#installation)
|
||||
* [Usage](#usage)
|
||||
* [With the `redis` package](#with-the-redis-package)
|
||||
* [With the `redis` package and a Redis cluster](#with-the-redis-package-and-a-redis-cluster)
|
||||
* [With the `ioredis` package](#with-the-ioredis-package)
|
||||
* [With the `ioredis` package and a Redis cluster](#with-the-ioredis-package-and-a-redis-cluster)
|
||||
* [Options](#options)
|
||||
* [API](#api)
|
||||
* [`Emitter(redisClient[, nsp][, opts])`](#emitterredisclient-nsp-opts)
|
||||
* [`Emitter#to(room:string):BroadcastOperator`](#emittertoroomstringbroadcastoperator)
|
||||
* [`Emitter#in(room:string):BroadcastOperator`](#emitterinroomstringbroadcastoperator)
|
||||
* [`Emitter#except(room:string):BroadcastOperator`](#emitterexceptroomstringbroadcastoperator)
|
||||
* [`Emitter#of(namespace:string):Emitter`](#emitterofnamespacestringemitter)
|
||||
* [`Emitter#socketsJoin(rooms:string|string[])`](#emittersocketsjoinroomsstringstring)
|
||||
* [`Emitter#socketsLeave(rooms:string|string[])`](#emittersocketsleaveroomsstringstring)
|
||||
* [`Emitter#disconnectSockets(close:boolean)`](#emitterdisconnectsocketscloseboolean)
|
||||
* [`Emitter#serverSideEmit(ev:string[,...args:any[]])`](#emitterserversideemitevstringargsany)
|
||||
* [License](#license)
|
||||
<!-- TOC -->
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm install @socket.io/redis-streams-emitter redis
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### With the `redis` package
|
||||
|
||||
```js
|
||||
import { createClient } from "redis";
|
||||
import { Emitter } from "@socket.io/redis-streams-emitter";
|
||||
|
||||
const redisClient = createClient({
|
||||
url: "redis://localhost:6379"
|
||||
});
|
||||
|
||||
await redisClient.connect();
|
||||
|
||||
const io = new Emitter(redisClient);
|
||||
|
||||
setInterval(() => {
|
||||
io.emit("ping", new Date());
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
### With the `redis` package and a Redis cluster
|
||||
|
||||
```js
|
||||
import { createCluster } from "redis";
|
||||
import { Emitter } from "@socket.io/redis-streams-emitter";
|
||||
|
||||
const redisClient = createCluster({
|
||||
rootNodes: [
|
||||
{
|
||||
url: "redis://localhost:7000",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7001",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7002",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await redisClient.connect();
|
||||
|
||||
const io = new Emitter(redisClient);
|
||||
|
||||
setInterval(() => {
|
||||
io.emit("ping", new Date());
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
### With the `ioredis` package
|
||||
|
||||
```js
|
||||
import { Redis } from "ioredis";
|
||||
import { Emitter } from "@socket.io/redis-streams-emitter";
|
||||
|
||||
const redisClient = new Redis();
|
||||
|
||||
const io = new Emitter(redisClient);
|
||||
|
||||
setInterval(() => {
|
||||
io.emit("ping", new Date());
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
### With the `ioredis` package and a Redis cluster
|
||||
|
||||
```js
|
||||
import { Cluster } from "ioredis";
|
||||
import { Emitter } from "@socket.io/redis-streams-emitter";
|
||||
|
||||
const redisClient = new Cluster([
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7000,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7001,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7002,
|
||||
},
|
||||
]);
|
||||
|
||||
const io = new Emitter(redisClient);
|
||||
|
||||
setInterval(() => {
|
||||
io.emit("ping", new Date());
|
||||
}, 1000);
|
||||
```
|
||||
|
||||
## Options
|
||||
|
||||
| Name | Description | Default value |
|
||||
|--------------|--------------------------------------------------------------------|---------------|
|
||||
| `streamName` | The name of the Redis stream. | `socket.io` |
|
||||
| `maxLen` | The maximum size of the stream. Almost exact trimming (~) is used. | `10_000` |
|
||||
|
||||
## API
|
||||
|
||||
### `Emitter(redisClient[, nsp][, opts])`
|
||||
|
||||
```js
|
||||
const io = new Emitter(redisClient);
|
||||
```
|
||||
|
||||
### `Emitter#to(room:string):BroadcastOperator`
|
||||
### `Emitter#in(room:string):BroadcastOperator`
|
||||
|
||||
Specifies a specific `room` that you want to emit to.
|
||||
|
||||
```js
|
||||
io.to("room1").emit("hello");
|
||||
```
|
||||
|
||||
### `Emitter#except(room:string):BroadcastOperator`
|
||||
|
||||
Specifies a specific `room` that you want to exclude from broadcasting.
|
||||
|
||||
```js
|
||||
io.except("room2").emit("hello");
|
||||
```
|
||||
|
||||
### `Emitter#of(namespace:string):Emitter`
|
||||
|
||||
Specifies a specific namespace that you want to emit to.
|
||||
|
||||
```js
|
||||
const customNamespace = io.of("/custom");
|
||||
|
||||
customNamespace.emit("hello");
|
||||
```
|
||||
|
||||
### `Emitter#socketsJoin(rooms:string|string[])`
|
||||
|
||||
Makes the matching socket instances join the specified rooms:
|
||||
|
||||
```js
|
||||
// make all Socket instances join the "room1" room
|
||||
io.socketsJoin("room1");
|
||||
|
||||
// make all Socket instances of the "admin" namespace in the "room1" room join the "room2" room
|
||||
io.of("/admin").in("room1").socketsJoin("room2");
|
||||
```
|
||||
|
||||
### `Emitter#socketsLeave(rooms:string|string[])`
|
||||
|
||||
Makes the matching socket instances leave the specified rooms:
|
||||
|
||||
```js
|
||||
// make all Socket instances leave the "room1" room
|
||||
io.socketsLeave("room1");
|
||||
|
||||
// make all Socket instances of the "admin" namespace in the "room1" room leave the "room2" room
|
||||
io.of("/admin").in("room1").socketsLeave("room2");
|
||||
```
|
||||
|
||||
### `Emitter#disconnectSockets(close:boolean)`
|
||||
|
||||
Makes the matching socket instances disconnect:
|
||||
|
||||
```js
|
||||
// make all Socket instances disconnect
|
||||
io.disconnectSockets();
|
||||
|
||||
// make all Socket instances of the "admin" namespace in the "room1" room disconnect
|
||||
io.of("/admin").in("room1").disconnectSockets();
|
||||
|
||||
// this also works with a single socket ID
|
||||
io.of("/admin").in(theSocketId).disconnectSockets();
|
||||
```
|
||||
|
||||
### `Emitter#serverSideEmit(ev:string[,...args:any[]])`
|
||||
|
||||
Emits an event that will be received by each Socket.IO server of the cluster.
|
||||
|
||||
```js
|
||||
io.serverSideEmit("ping");
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./LICENSE)
|
||||
15
packages/socket.io-redis-streams-emitter/compose.yaml
Normal file
15
packages/socket.io-redis-streams-emitter/compose.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
services:
|
||||
redis:
|
||||
image: redis:5
|
||||
ports:
|
||||
- "6379:6379"
|
||||
|
||||
redis-cluster:
|
||||
image: grokzen/redis-cluster:7.0.10
|
||||
ports:
|
||||
- "7000-7005:7000-7005"
|
||||
|
||||
valkey:
|
||||
image: valkey/valkey:8
|
||||
ports:
|
||||
- "6389:6379"
|
||||
@@ -0,0 +1,75 @@
|
||||
// imported from the 'socket.io-adapter' package
|
||||
export enum MessageType {
|
||||
INITIAL_HEARTBEAT = 1,
|
||||
HEARTBEAT,
|
||||
BROADCAST,
|
||||
SOCKETS_JOIN,
|
||||
SOCKETS_LEAVE,
|
||||
DISCONNECT_SOCKETS,
|
||||
FETCH_SOCKETS,
|
||||
FETCH_SOCKETS_RESPONSE,
|
||||
SERVER_SIDE_EMIT,
|
||||
SERVER_SIDE_EMIT_RESPONSE,
|
||||
BROADCAST_CLIENT_COUNT,
|
||||
BROADCAST_ACK,
|
||||
ADAPTER_CLOSE,
|
||||
}
|
||||
|
||||
export type ServerId = string;
|
||||
|
||||
export type ClusterMessage = {
|
||||
uid: ServerId;
|
||||
nsp: string;
|
||||
} & (
|
||||
| {
|
||||
type:
|
||||
| MessageType.INITIAL_HEARTBEAT
|
||||
| MessageType.HEARTBEAT
|
||||
| MessageType.ADAPTER_CLOSE;
|
||||
}
|
||||
| {
|
||||
type: MessageType.BROADCAST;
|
||||
data: {
|
||||
opts: { rooms: string[]; except: string[]; flags: BroadcastFlags };
|
||||
packet: unknown;
|
||||
requestId?: string;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: MessageType.SOCKETS_JOIN | MessageType.SOCKETS_LEAVE;
|
||||
data: {
|
||||
opts: { rooms: string[]; except: string[]; flags: BroadcastFlags };
|
||||
rooms: string[];
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: MessageType.DISCONNECT_SOCKETS;
|
||||
data: {
|
||||
opts: { rooms: string[]; except: string[]; flags: BroadcastFlags };
|
||||
close?: boolean;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: MessageType.FETCH_SOCKETS;
|
||||
data: {
|
||||
opts: { rooms: string[]; except: string[]; flags: BroadcastFlags };
|
||||
requestId: string;
|
||||
};
|
||||
}
|
||||
| {
|
||||
type: MessageType.SERVER_SIDE_EMIT;
|
||||
data: {
|
||||
requestId?: string;
|
||||
packet: any[];
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
export interface BroadcastFlags {
|
||||
volatile?: boolean;
|
||||
compress?: boolean;
|
||||
local?: boolean;
|
||||
broadcast?: boolean;
|
||||
binary?: boolean;
|
||||
timeout?: number;
|
||||
}
|
||||
496
packages/socket.io-redis-streams-emitter/lib/index.ts
Normal file
496
packages/socket.io-redis-streams-emitter/lib/index.ts
Normal file
@@ -0,0 +1,496 @@
|
||||
import debugModule from "debug";
|
||||
import type {
|
||||
DefaultEventsMap,
|
||||
EventNames,
|
||||
EventParams,
|
||||
EventsMap,
|
||||
TypedEventBroadcaster,
|
||||
} from "./typed-events";
|
||||
import { encode } from "@msgpack/msgpack";
|
||||
import { hasBinary, XADD } from "./util";
|
||||
import { ClusterMessage, MessageType, BroadcastFlags } from "./adapter-types";
|
||||
|
||||
const debug = debugModule("socket.io-redis-streams-emitter");
|
||||
const EMITTER_UID = "emitter";
|
||||
|
||||
type DistributiveOmit<T, K extends keyof any> = T extends any
|
||||
? Omit<T, K>
|
||||
: never;
|
||||
|
||||
// TODO move to the socket.io-adapter package
|
||||
abstract class BaseEmitter<
|
||||
EmitEvents extends EventsMap = DefaultEventsMap,
|
||||
ServerSideEvents extends EventsMap = DefaultEventsMap,
|
||||
> {
|
||||
protected abstract publish(
|
||||
message: DistributiveOmit<ClusterMessage, "uid" | "nsp">,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Emits to all clients.
|
||||
*
|
||||
* @return Always true
|
||||
* @public
|
||||
*/
|
||||
public emit<Ev extends EventNames<EmitEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<EmitEvents, Ev>
|
||||
): true {
|
||||
return this.newBroadcastOperator().emit(ev, ...args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public to(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.newBroadcastOperator().to(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public in(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.newBroadcastOperator().in(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public except(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.newBroadcastOperator().except(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
|
||||
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
|
||||
* and is in the middle of a request-response cycle).
|
||||
*
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public get volatile(): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.newBroadcastOperator().volatile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compress flag.
|
||||
*
|
||||
* @param compress - if `true`, compresses the sending data
|
||||
* @return BroadcastOperator
|
||||
* @public
|
||||
*/
|
||||
public compress(
|
||||
compress: boolean,
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.newBroadcastOperator().compress(compress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances join the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsJoin(rooms: string | string[]): void {
|
||||
return this.newBroadcastOperator().socketsJoin(rooms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances leave the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsLeave(rooms: string | string[]): void {
|
||||
return this.newBroadcastOperator().socketsLeave(rooms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances disconnect
|
||||
*
|
||||
* @param close - whether to close the underlying connection
|
||||
* @public
|
||||
*/
|
||||
public disconnectSockets(close: boolean = false): void {
|
||||
return this.newBroadcastOperator().disconnectSockets(close);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the Socket.IO servers in the cluster
|
||||
*
|
||||
* @param ev - the event name
|
||||
* @param args - any number of serializable arguments
|
||||
*/
|
||||
public serverSideEmit<Ev extends EventNames<ServerSideEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<ServerSideEvents, Ev>
|
||||
): void {
|
||||
return this.newBroadcastOperator().serverSideEmit(ev, ...args);
|
||||
}
|
||||
|
||||
private newBroadcastOperator() {
|
||||
return new BroadcastOperator<EmitEvents, ServerSideEvents>((msg) =>
|
||||
this.publish(msg),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const RESERVED_EVENTS: ReadonlySet<string | Symbol> = new Set(<const>[
|
||||
"connect",
|
||||
"connect_error",
|
||||
"disconnect",
|
||||
"disconnecting",
|
||||
"newListener",
|
||||
"removeListener",
|
||||
]);
|
||||
|
||||
export class BroadcastOperator<
|
||||
EmitEvents extends EventsMap,
|
||||
ServerSideEvents extends EventsMap,
|
||||
> implements TypedEventBroadcaster<EmitEvents>
|
||||
{
|
||||
constructor(
|
||||
private readonly publish: (
|
||||
message: DistributiveOmit<ClusterMessage, "uid" | "nsp">,
|
||||
) => void,
|
||||
private readonly rooms: Set<string> = new Set<string>(),
|
||||
private readonly exceptRooms: Set<string> = new Set<string>(),
|
||||
private readonly flags: BroadcastFlags = {},
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public to(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const rooms = new Set(this.rooms);
|
||||
if (Array.isArray(room)) {
|
||||
room.forEach((r) => rooms.add(r));
|
||||
} else {
|
||||
rooms.add(room);
|
||||
}
|
||||
return new BroadcastOperator(
|
||||
this.publish,
|
||||
rooms,
|
||||
this.exceptRooms,
|
||||
this.flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Targets a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public in(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
return this.to(room);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excludes a room when emitting.
|
||||
*
|
||||
* @param room
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public except(
|
||||
room: string | string[],
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const exceptRooms = new Set(this.exceptRooms);
|
||||
if (Array.isArray(room)) {
|
||||
room.forEach((r) => exceptRooms.add(r));
|
||||
} else {
|
||||
exceptRooms.add(room);
|
||||
}
|
||||
return new BroadcastOperator(
|
||||
this.publish,
|
||||
this.rooms,
|
||||
exceptRooms,
|
||||
this.flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the compress flag.
|
||||
*
|
||||
* @param compress - if `true`, compresses the sending data
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public compress(
|
||||
compress: boolean,
|
||||
): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const flags = Object.assign({}, this.flags, { compress });
|
||||
return new BroadcastOperator(
|
||||
this.publish,
|
||||
this.rooms,
|
||||
this.exceptRooms,
|
||||
flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a modifier for a subsequent event emission that the event data may be lost if the client is not ready to
|
||||
* receive messages (because of network slowness or other issues, or because they’re connected through long polling
|
||||
* and is in the middle of a request-response cycle).
|
||||
*
|
||||
* @return a new BroadcastOperator instance
|
||||
* @public
|
||||
*/
|
||||
public get volatile(): BroadcastOperator<EmitEvents, ServerSideEvents> {
|
||||
const flags = Object.assign({}, this.flags, { volatile: true });
|
||||
return new BroadcastOperator(
|
||||
this.publish,
|
||||
this.rooms,
|
||||
this.exceptRooms,
|
||||
flags,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emits to all clients.
|
||||
*
|
||||
* @return Always true
|
||||
* @public
|
||||
*/
|
||||
public emit<Ev extends EventNames<EmitEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<EmitEvents, Ev>
|
||||
): true {
|
||||
if (RESERVED_EVENTS.has(ev)) {
|
||||
throw new Error(`"${String(ev)}" is a reserved event name`);
|
||||
}
|
||||
|
||||
// set up packet object
|
||||
const data = [ev, ...args];
|
||||
const packet = {
|
||||
type: 2, // EVENT
|
||||
data: data,
|
||||
};
|
||||
|
||||
const opts = {
|
||||
rooms: [...this.rooms],
|
||||
flags: this.flags,
|
||||
except: [...this.exceptRooms],
|
||||
};
|
||||
|
||||
this.publish({
|
||||
type: MessageType.BROADCAST,
|
||||
data: {
|
||||
packet,
|
||||
opts,
|
||||
},
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances join the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsJoin(rooms: string | string[]): void {
|
||||
this.publish({
|
||||
type: MessageType.SOCKETS_JOIN,
|
||||
data: {
|
||||
opts: {
|
||||
rooms: [...this.rooms],
|
||||
except: [...this.exceptRooms],
|
||||
flags: {},
|
||||
},
|
||||
rooms: Array.isArray(rooms) ? rooms : [rooms],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances leave the specified rooms
|
||||
*
|
||||
* @param rooms
|
||||
* @public
|
||||
*/
|
||||
public socketsLeave(rooms: string | string[]): void {
|
||||
this.publish({
|
||||
type: MessageType.SOCKETS_LEAVE,
|
||||
data: {
|
||||
opts: {
|
||||
rooms: [...this.rooms],
|
||||
except: [...this.exceptRooms],
|
||||
flags: {},
|
||||
},
|
||||
rooms: Array.isArray(rooms) ? rooms : [rooms],
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the matching socket instances disconnect
|
||||
*
|
||||
* @param close - whether to close the underlying connection
|
||||
* @public
|
||||
*/
|
||||
public disconnectSockets(close: boolean = false): void {
|
||||
this.publish({
|
||||
type: MessageType.DISCONNECT_SOCKETS,
|
||||
data: {
|
||||
opts: {
|
||||
rooms: [...this.rooms],
|
||||
except: [...this.exceptRooms],
|
||||
flags: {},
|
||||
},
|
||||
close,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a packet to the Socket.IO servers in the cluster
|
||||
*
|
||||
* @param ev - the event name
|
||||
* @param args - any number of serializable arguments
|
||||
*/
|
||||
public serverSideEmit<Ev extends EventNames<ServerSideEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<ServerSideEvents, Ev>
|
||||
): void {
|
||||
const withAck = args.length && typeof args[args.length - 1] === "function";
|
||||
|
||||
if (withAck) {
|
||||
throw new Error("Acknowledgements are not supported");
|
||||
}
|
||||
|
||||
this.publish({
|
||||
type: MessageType.SERVER_SIDE_EMIT,
|
||||
data: {
|
||||
packet: [ev, ...args],
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function flattenPayload(message: ClusterMessage) {
|
||||
const rawMessage = {
|
||||
uid: message.uid,
|
||||
nsp: message.nsp,
|
||||
type: message.type.toString(),
|
||||
data: undefined as string | undefined,
|
||||
};
|
||||
|
||||
// @ts-expect-error
|
||||
const data = message.data;
|
||||
|
||||
if (data) {
|
||||
const mayContainBinary = [
|
||||
MessageType.BROADCAST,
|
||||
MessageType.FETCH_SOCKETS_RESPONSE,
|
||||
MessageType.SERVER_SIDE_EMIT,
|
||||
MessageType.SERVER_SIDE_EMIT_RESPONSE,
|
||||
MessageType.BROADCAST_ACK,
|
||||
].includes(message.type);
|
||||
|
||||
if (mayContainBinary && hasBinary(data)) {
|
||||
rawMessage.data = Buffer.from(encode(data)).toString("base64");
|
||||
} else {
|
||||
rawMessage.data = JSON.stringify(data);
|
||||
}
|
||||
}
|
||||
|
||||
return rawMessage;
|
||||
}
|
||||
|
||||
export interface RedisStreamsEmitterOptions {
|
||||
/**
|
||||
* The name of the Redis stream.
|
||||
* @default "socket.io"
|
||||
*/
|
||||
streamName?: string;
|
||||
/**
|
||||
* The maximum size of the stream. Almost exact trimming (~) is used.
|
||||
* @default 10_000
|
||||
*/
|
||||
maxLen?: number;
|
||||
}
|
||||
|
||||
export class Emitter<
|
||||
EmitEvents extends EventsMap = DefaultEventsMap,
|
||||
ServerSideEvents extends EventsMap = DefaultEventsMap,
|
||||
> extends BaseEmitter<EmitEvents, ServerSideEvents> {
|
||||
readonly #redisClient: any;
|
||||
readonly #opts: Required<RedisStreamsEmitterOptions>;
|
||||
readonly #nsp: string;
|
||||
|
||||
constructor(
|
||||
redisClient: any,
|
||||
opts: RedisStreamsEmitterOptions = {},
|
||||
nsp = "/",
|
||||
) {
|
||||
super();
|
||||
this.#redisClient = redisClient;
|
||||
this.#opts = Object.assign(
|
||||
{
|
||||
streamName: "socket.io",
|
||||
maxLen: 10_000,
|
||||
},
|
||||
opts,
|
||||
);
|
||||
this.#nsp = nsp;
|
||||
}
|
||||
|
||||
public of(nsp: string) {
|
||||
return new Emitter(this.#redisClient, this.#opts, nsp);
|
||||
}
|
||||
|
||||
protected override publish(
|
||||
message: DistributiveOmit<ClusterMessage, "uid" | "nsp">,
|
||||
) {
|
||||
(message as ClusterMessage).uid = EMITTER_UID;
|
||||
(message as ClusterMessage).nsp = this.#nsp;
|
||||
|
||||
debug(
|
||||
"publishing message %s to stream %s",
|
||||
message.type,
|
||||
this.#opts.streamName,
|
||||
);
|
||||
|
||||
if (message.type === MessageType.BROADCAST) {
|
||||
// @ts-expect-error FIXME untyped packet object
|
||||
message.data.packet.nsp = this.#nsp;
|
||||
}
|
||||
|
||||
return XADD(
|
||||
this.#redisClient,
|
||||
this.#opts.streamName,
|
||||
flattenPayload(message as ClusterMessage),
|
||||
this.#opts.maxLen,
|
||||
);
|
||||
}
|
||||
}
|
||||
37
packages/socket.io-redis-streams-emitter/lib/typed-events.ts
Normal file
37
packages/socket.io-redis-streams-emitter/lib/typed-events.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* An events map is an interface that maps event names to their value, which
|
||||
* represents the type of the `on` listener.
|
||||
*/
|
||||
export interface EventsMap {
|
||||
[event: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* The default events map, used if no EventsMap is given. Using this EventsMap
|
||||
* is equivalent to accepting all event names, and any data.
|
||||
*/
|
||||
export interface DefaultEventsMap {
|
||||
[event: string]: (...args: any[]) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a union type containing all the keys of an event map.
|
||||
*/
|
||||
export type EventNames<Map extends EventsMap> = keyof Map & (string | symbol);
|
||||
|
||||
/** The tuple type representing the parameters of an event listener */
|
||||
export type EventParams<
|
||||
Map extends EventsMap,
|
||||
Ev extends EventNames<Map>,
|
||||
> = Parameters<Map[Ev]>;
|
||||
|
||||
/**
|
||||
* Interface for classes that aren't `EventEmitter`s, but still expose a
|
||||
* strictly typed `emit` method.
|
||||
*/
|
||||
export interface TypedEventBroadcaster<EmitEvents extends EventsMap> {
|
||||
emit<Ev extends EventNames<EmitEvents>>(
|
||||
ev: Ev,
|
||||
...args: EventParams<EmitEvents, Ev>
|
||||
): boolean;
|
||||
}
|
||||
68
packages/socket.io-redis-streams-emitter/lib/util.ts
Normal file
68
packages/socket.io-redis-streams-emitter/lib/util.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
export function hasBinary(obj: any, toJSON?: boolean): boolean {
|
||||
if (!obj || typeof obj !== "object") {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj instanceof ArrayBuffer || ArrayBuffer.isView(obj)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
for (let i = 0, l = obj.length; i < l; i++) {
|
||||
if (hasBinary(obj[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const key in obj) {
|
||||
if (Object.prototype.hasOwnProperty.call(obj, key) && hasBinary(obj[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj.toJSON && typeof obj.toJSON === "function" && !toJSON) {
|
||||
return hasBinary(obj.toJSON(), true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the client comes from the `redis` package
|
||||
*
|
||||
* @param redisClient
|
||||
*
|
||||
* @see https://github.com/redis/node-redis
|
||||
*/
|
||||
function isRedisV4Client(redisClient: any) {
|
||||
return typeof redisClient.sSubscribe === "function";
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://redis.io/commands/xadd/
|
||||
*/
|
||||
export function XADD(
|
||||
redisClient: any,
|
||||
streamName: string,
|
||||
payload: any,
|
||||
maxLenThreshold: number,
|
||||
) {
|
||||
if (isRedisV4Client(redisClient)) {
|
||||
return redisClient.xAdd(streamName, "*", payload, {
|
||||
TRIM: {
|
||||
strategy: "MAXLEN",
|
||||
strategyModifier: "~",
|
||||
threshold: maxLenThreshold,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const args = [streamName, "MAXLEN", "~", maxLenThreshold, "*"];
|
||||
Object.keys(payload).forEach((k) => {
|
||||
args.push(k, payload[k]);
|
||||
});
|
||||
|
||||
return redisClient.xadd.call(redisClient, args);
|
||||
}
|
||||
}
|
||||
38
packages/socket.io-redis-streams-emitter/package.json
Normal file
38
packages/socket.io-redis-streams-emitter/package.json
Normal file
@@ -0,0 +1,38 @@
|
||||
{
|
||||
"name": "@socket.io/redis-streams-emitter",
|
||||
"version": "0.1.1",
|
||||
"description": "The Socket.IO Redis streams emitter, allowing to communicate with a group of Socket.IO servers from another Node.js process",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/socketio/socket.io/tree/main/packages/socket.io-redis-streams-emitter#readme",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/socketio/socket.io.git"
|
||||
},
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"format:check": "prettier --parser typescript --check 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"format:fix": "prettier --parser typescript --write 'lib/**/*.ts' 'test/**/*.ts'",
|
||||
"prepack": "npm run compile",
|
||||
"test": "npm run format:check && npm run compile && npm run test:redis-standalone && npm run test:ioredis-standalone",
|
||||
"test:redis-standalone": "tsx --test",
|
||||
"test:redis-cluster": "REDIS_CLUSTER=1 npm run test:redis-standalone",
|
||||
"test:ioredis-standalone": "REDIS_LIB=ioredis npm run test:redis-standalone",
|
||||
"test:ioredis-cluster": "REDIS_LIB=ioredis REDIS_CLUSTER=1 npm run test:redis-standalone",
|
||||
"test:valkey-standalone": "VALKEY=1 npm run test:redis-standalone"
|
||||
},
|
||||
"dependencies": {
|
||||
"@msgpack/msgpack": "~2.8.0",
|
||||
"debug": "~4.4.1"
|
||||
},
|
||||
"keywords": [
|
||||
"socket.io",
|
||||
"redis",
|
||||
"redis-streams",
|
||||
"emitter"
|
||||
]
|
||||
}
|
||||
238
packages/socket.io-redis-streams-emitter/test/index.ts
Normal file
238
packages/socket.io-redis-streams-emitter/test/index.ts
Normal file
@@ -0,0 +1,238 @@
|
||||
import { describe, it, beforeEach, afterEach } from "node:test";
|
||||
import * as assert from "node:assert";
|
||||
import { type Server, type Socket as ServerSocket } from "socket.io";
|
||||
import { type Socket as ClientSocket } from "socket.io-client";
|
||||
import { times, sleep, setup, initRedisClient } from "./util";
|
||||
import { Emitter } from "../lib";
|
||||
|
||||
const PROPAGATION_DELAY_IN_MS = 100;
|
||||
|
||||
describe("@socket.io/redis-streams-emitter", () => {
|
||||
let servers: [Server, Server, Server],
|
||||
serverSockets: [ServerSocket, ServerSocket, ServerSocket],
|
||||
clientSockets: [ClientSocket, ClientSocket, ClientSocket],
|
||||
cleanup: () => void,
|
||||
emitter: Emitter;
|
||||
|
||||
beforeEach(async () => {
|
||||
const testContext = await setup();
|
||||
servers = testContext.servers;
|
||||
serverSockets = testContext.serverSockets;
|
||||
clientSockets = testContext.clientSockets;
|
||||
const redisClient = await initRedisClient();
|
||||
emitter = new Emitter(redisClient);
|
||||
|
||||
cleanup = () => {
|
||||
testContext.cleanup();
|
||||
redisClient.quit();
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => cleanup());
|
||||
|
||||
describe("broadcast", function () {
|
||||
it("broadcasts to all clients", () => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const partialResolve = times(3, resolve);
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
clientSocket.on("test", (arg1, arg2, arg3) => {
|
||||
assert.equal(arg1, 1);
|
||||
assert.equal(arg2, "2");
|
||||
assert.ok(Buffer.isBuffer(arg3));
|
||||
partialResolve();
|
||||
});
|
||||
});
|
||||
|
||||
emitter.emit("test", 1, "2", Buffer.from([3, 4]));
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts to all clients in a namespace", () => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const partialResolve = times(3, () => {
|
||||
servers.forEach((server) => server.of("/custom").adapter.close());
|
||||
resolve();
|
||||
});
|
||||
|
||||
servers.forEach((server) => server.of("/custom"));
|
||||
|
||||
const onConnect = times(3, async () => {
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
emitter.of("/custom").emit("test");
|
||||
});
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
const socket = clientSocket.io.socket("/custom");
|
||||
socket.on("connect", onConnect);
|
||||
socket.on("test", () => {
|
||||
socket.disconnect();
|
||||
partialResolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts to all clients in a room", () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
serverSockets[1].join("room1");
|
||||
|
||||
clientSockets[0].on("test", () => {
|
||||
reject("should not happen");
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
resolve();
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
reject("should not happen");
|
||||
});
|
||||
|
||||
emitter.to("room1").emit("test");
|
||||
});
|
||||
});
|
||||
|
||||
it("broadcasts to all clients except in room", () => {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const partialResolve = times(2, resolve);
|
||||
serverSockets[1].join("room1");
|
||||
|
||||
clientSockets[0].on("test", () => {
|
||||
partialResolve();
|
||||
});
|
||||
|
||||
clientSockets[1].on("test", () => {
|
||||
reject("should not happen");
|
||||
});
|
||||
|
||||
clientSockets[2].on("test", () => {
|
||||
partialResolve();
|
||||
});
|
||||
|
||||
emitter.of("/").except("room1").emit("test");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("socketsJoin", () => {
|
||||
it("makes all socket instances join the specified room", async () => {
|
||||
emitter.socketsJoin("room1");
|
||||
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
assert.ok(serverSockets[0].rooms.has("room1"));
|
||||
assert.ok(serverSockets[1].rooms.has("room1"));
|
||||
assert.ok(serverSockets[2].rooms.has("room1"));
|
||||
});
|
||||
|
||||
it("makes the matching socket instances join the specified room", async () => {
|
||||
serverSockets[0].join("room1");
|
||||
serverSockets[2].join("room1");
|
||||
|
||||
emitter.in("room1").socketsJoin("room2");
|
||||
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
assert.ok(serverSockets[0].rooms.has("room2"));
|
||||
assert.ok(serverSockets[1].rooms.has("room2") === false);
|
||||
assert.ok(serverSockets[2].rooms.has("room2"));
|
||||
});
|
||||
|
||||
it("makes the given socket instance join the specified room", async () => {
|
||||
emitter.in(serverSockets[1].id).socketsJoin("room3");
|
||||
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
assert.ok(serverSockets[0].rooms.has("room3") === false);
|
||||
assert.ok(serverSockets[1].rooms.has("room3"));
|
||||
assert.ok(serverSockets[2].rooms.has("room3") === false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("socketsLeave", () => {
|
||||
it("makes all socket instances leave the specified room", async () => {
|
||||
serverSockets[0].join("room1");
|
||||
serverSockets[2].join("room1");
|
||||
|
||||
emitter.socketsLeave("room1");
|
||||
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
assert.ok(serverSockets[0].rooms.has("room1") === false);
|
||||
assert.ok(serverSockets[1].rooms.has("room1") === false);
|
||||
assert.ok(serverSockets[2].rooms.has("room1") === false);
|
||||
});
|
||||
|
||||
it("makes the matching socket instances leave the specified room", async () => {
|
||||
serverSockets[0].join(["room1", "room2"]);
|
||||
serverSockets[1].join(["room1", "room2"]);
|
||||
serverSockets[2].join(["room2"]);
|
||||
|
||||
emitter.in("room1").socketsLeave("room2");
|
||||
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
assert.ok(serverSockets[0].rooms.has("room2") === false);
|
||||
assert.ok(serverSockets[1].rooms.has("room2") === false);
|
||||
assert.ok(serverSockets[2].rooms.has("room2"));
|
||||
});
|
||||
|
||||
it("makes the given socket instance leave the specified room", async () => {
|
||||
serverSockets[0].join("room3");
|
||||
serverSockets[1].join("room3");
|
||||
serverSockets[2].join("room3");
|
||||
|
||||
emitter.in(serverSockets[1].id).socketsLeave("room3");
|
||||
|
||||
await sleep(PROPAGATION_DELAY_IN_MS);
|
||||
|
||||
assert.ok(serverSockets[0].rooms.has("room3"));
|
||||
assert.ok(serverSockets[1].rooms.has("room1") === false);
|
||||
assert.ok(serverSockets[2].rooms.has("room3"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("disconnectSockets", () => {
|
||||
it("makes all socket instances disconnect", () => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const partialResolve = times(3, resolve);
|
||||
|
||||
clientSockets.forEach((clientSocket) => {
|
||||
clientSocket.on("disconnect", (reason) => {
|
||||
assert.equal(reason, "io server disconnect");
|
||||
partialResolve();
|
||||
});
|
||||
});
|
||||
|
||||
emitter.disconnectSockets();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("serverSideEmit", () => {
|
||||
it("sends an event to other server instances", () => {
|
||||
return new Promise<void>((resolve) => {
|
||||
const partialResolve = times(3, resolve);
|
||||
|
||||
emitter.serverSideEmit("hello", "world", 1, "2");
|
||||
|
||||
servers[0].on("hello", (arg1, arg2, arg3) => {
|
||||
assert.equal(arg1, "world");
|
||||
assert.equal(arg2, 1);
|
||||
assert.equal(arg3, "2");
|
||||
partialResolve();
|
||||
});
|
||||
|
||||
servers[1].on("hello", (arg1, arg2, arg3) => {
|
||||
partialResolve();
|
||||
});
|
||||
|
||||
servers[2].of("/").on("hello", () => {
|
||||
partialResolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
164
packages/socket.io-redis-streams-emitter/test/util.ts
Normal file
164
packages/socket.io-redis-streams-emitter/test/util.ts
Normal file
@@ -0,0 +1,164 @@
|
||||
import { createServer } from "node:http";
|
||||
import { type AddressInfo } from "node:net";
|
||||
import { createClient, createCluster } from "redis";
|
||||
import { Redis, Cluster } from "ioredis";
|
||||
import { Server, type Socket as ServerSocket } from "socket.io";
|
||||
import { io as ioc, type Socket as ClientSocket } from "socket.io-client";
|
||||
import { createAdapter } from "@socket.io/redis-streams-adapter";
|
||||
|
||||
export function times(count: number, fn: () => void) {
|
||||
let i = 0;
|
||||
return () => {
|
||||
i++;
|
||||
if (i === count) {
|
||||
fn();
|
||||
} else if (i > count) {
|
||||
throw new Error(`too many calls: ${i} instead of ${count}`);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function sleep(duration: number) {
|
||||
return new Promise((resolve) => setTimeout(resolve, duration));
|
||||
}
|
||||
|
||||
const mode = process.env.REDIS_CLUSTER === "1" ? "cluster" : "standalone";
|
||||
const lib = process.env.REDIS_LIB || "redis";
|
||||
|
||||
console.log(`[INFO] testing in ${mode} mode with ${lib}`);
|
||||
|
||||
export async function initRedisClient() {
|
||||
if (mode === "cluster") {
|
||||
if (lib === "ioredis") {
|
||||
return new Cluster([
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7000,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7001,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7002,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7003,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7004,
|
||||
},
|
||||
{
|
||||
host: "localhost",
|
||||
port: 7005,
|
||||
},
|
||||
]);
|
||||
} else {
|
||||
const redisClient = createCluster({
|
||||
rootNodes: [
|
||||
{
|
||||
url: "redis://localhost:7000",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7001",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7002",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7003",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7004",
|
||||
},
|
||||
{
|
||||
url: "redis://localhost:7005",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await redisClient.connect();
|
||||
|
||||
return redisClient;
|
||||
}
|
||||
} else {
|
||||
if (lib === "ioredis") {
|
||||
return new Redis();
|
||||
} else {
|
||||
const port = process.env.VALKEY === "1" ? 6389 : 6379;
|
||||
const redisClient = createClient({
|
||||
url: `redis://localhost:${port}`,
|
||||
});
|
||||
await redisClient.connect();
|
||||
|
||||
return redisClient;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
const redisClient = await initRedisClient();
|
||||
|
||||
const httpServer = createServer();
|
||||
const io = new Server(httpServer, {
|
||||
adapter: createAdapter(redisClient, {
|
||||
readCount: 1, // return as soon as possible
|
||||
}),
|
||||
});
|
||||
|
||||
return new Promise<{
|
||||
io: Server;
|
||||
socket: ServerSocket;
|
||||
clientSocket: ClientSocket;
|
||||
cleanup: () => void;
|
||||
}>((resolve) => {
|
||||
httpServer.listen(() => {
|
||||
const port = (httpServer.address() as AddressInfo).port;
|
||||
const clientSocket = ioc(`http://localhost:${port}`);
|
||||
|
||||
io.on("connection", async (socket) => {
|
||||
resolve({
|
||||
io,
|
||||
socket,
|
||||
clientSocket,
|
||||
cleanup: () => {
|
||||
io.close();
|
||||
clientSocket.disconnect();
|
||||
redisClient.quit();
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function setup() {
|
||||
const results = await Promise.all([init(), init(), init()]);
|
||||
|
||||
const servers = results.map(({ io }) => io) as [Server, Server, Server];
|
||||
const serverSockets = results.map(({ socket }) => socket) as [
|
||||
ServerSocket,
|
||||
ServerSocket,
|
||||
ServerSocket,
|
||||
];
|
||||
const clientSockets = results.map(({ clientSocket }) => clientSocket) as [
|
||||
ClientSocket,
|
||||
ClientSocket,
|
||||
ClientSocket,
|
||||
];
|
||||
const cleanupMethods = results.map(({ cleanup }) => cleanup);
|
||||
|
||||
return {
|
||||
servers,
|
||||
serverSockets,
|
||||
clientSockets,
|
||||
cleanup: () => {
|
||||
for (const cleanup of cleanupMethods) {
|
||||
cleanup();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
13
packages/socket.io-redis-streams-emitter/tsconfig.json
Normal file
13
packages/socket.io-redis-streams-emitter/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"outDir": "./dist",
|
||||
"allowJs": false,
|
||||
"target": "es2022",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"strict": true
|
||||
},
|
||||
"include": [
|
||||
"./lib/**/*"
|
||||
]
|
||||
}
|
||||
8
packages/socket.io/RELEASING.md
Normal file
8
packages/socket.io/RELEASING.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Releasing
|
||||
|
||||
1. Update the version in `package.json`
|
||||
2. Update the changelog `CHANGELOG.md` with `conventional-changelog -p angular`
|
||||
3. Copy the bundles from the client project to `client-dist/`
|
||||
4. Commit the changes in `package.json`, `CHANGELOG.md` and `client-dist/`
|
||||
5. Create the tag `socket.io@x.y.z` and push it to the GitHub repository. The workflow `.github/workflows/publish.yml` will safely publish the package to npm using trusted publishing.
|
||||
6. Create a new release at https://github.com/socketio/socket.io/releases
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Decoder, Encoder, Packet, PacketType } from "socket.io-parser";
|
||||
import debugModule = require("debug");
|
||||
import url = require("url");
|
||||
import debugModule from "debug";
|
||||
import url from "url";
|
||||
import type { IncomingMessage } from "http";
|
||||
import type { Server } from "./index";
|
||||
import type { Namespace } from "./namespace";
|
||||
@@ -61,12 +61,13 @@ export class Client<
|
||||
*/
|
||||
constructor(
|
||||
server: Server<ListenEvents, EmitEvents, ServerSideEvents, SocketData>,
|
||||
conn: any,
|
||||
conn: RawSocket,
|
||||
) {
|
||||
this.server = server;
|
||||
this.conn = conn;
|
||||
this.encoder = server.encoder;
|
||||
this.decoder = new server._parser.Decoder();
|
||||
// @ts-expect-error use of private
|
||||
this.id = conn.id;
|
||||
this.setup();
|
||||
}
|
||||
@@ -216,13 +217,13 @@ export class Client<
|
||||
* @param {Object} opts
|
||||
* @private
|
||||
*/
|
||||
_packet(packet: Packet | any[], opts: WriteOptions = {}): void {
|
||||
_packet(packet: Packet | Packet[], opts: WriteOptions = {}): void {
|
||||
if (this.conn.readyState !== "open") {
|
||||
debug("ignoring packet write %j", packet);
|
||||
return;
|
||||
}
|
||||
const encodedPackets = opts.preEncoded
|
||||
? (packet as any[]) // previous versions of the adapter incorrectly used socket.packet() instead of writeToEngine()
|
||||
? (packet as Packet[]) // previous versions of the adapter incorrectly used socket.packet() instead of writeToEngine()
|
||||
: this.encoder.encode(packet as Packet);
|
||||
this.writeToEngine(encodedPackets, opts);
|
||||
}
|
||||
@@ -250,7 +251,7 @@ export class Client<
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
private ondata(data): void {
|
||||
private ondata(data: unknown): void {
|
||||
// try/catch is needed for protocol violations (GH-1880)
|
||||
try {
|
||||
this.decoder.add(data);
|
||||
@@ -266,16 +267,7 @@ export class Client<
|
||||
* @private
|
||||
*/
|
||||
private ondecoded(packet: Packet): void {
|
||||
let namespace: string;
|
||||
let authPayload: Record<string, unknown>;
|
||||
if (this.conn.protocol === 3) {
|
||||
const parsed = url.parse(packet.nsp, true);
|
||||
namespace = parsed.pathname!;
|
||||
authPayload = parsed.query;
|
||||
} else {
|
||||
namespace = packet.nsp;
|
||||
authPayload = packet.data;
|
||||
}
|
||||
const { namespace, authPayload } = this._parseNamespace(packet);
|
||||
const socket = this.nsps.get(namespace);
|
||||
|
||||
if (!socket && packet.type === PacketType.CONNECT) {
|
||||
@@ -294,6 +286,20 @@ export class Client<
|
||||
}
|
||||
}
|
||||
|
||||
private _parseNamespace(packet: Packet) {
|
||||
if (this.conn.protocol !== 3) {
|
||||
return {
|
||||
namespace: packet.nsp,
|
||||
authPayload: packet.data,
|
||||
};
|
||||
}
|
||||
const url = new URL(packet.nsp, "https://socket.io");
|
||||
return {
|
||||
namespace: url.pathname,
|
||||
authPayload: Object.fromEntries(url.searchParams.entries()),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an error.
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import http = require("http");
|
||||
import http from "http";
|
||||
import type { Server as HTTPSServer } from "https";
|
||||
import type { Http2SecureServer, Http2Server } from "http2";
|
||||
import { createReadStream } from "fs";
|
||||
@@ -7,7 +7,11 @@ import accepts = require("accepts");
|
||||
import { pipeline } from "stream";
|
||||
import path = require("path");
|
||||
import { attach, Server as Engine, uServer } from "engine.io";
|
||||
import type { ServerOptions as EngineOptions, AttachOptions } from "engine.io";
|
||||
import type {
|
||||
ServerOptions as EngineOptions,
|
||||
AttachOptions,
|
||||
Socket as RawSocket,
|
||||
} from "engine.io";
|
||||
import { Client } from "./client";
|
||||
import { EventEmitter } from "events";
|
||||
import { ExtendedError, Namespace, ServerReservedEventsMap } from "./namespace";
|
||||
@@ -506,6 +510,11 @@ export class Server<
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attaches socket.io to a uWebSockets.js app.
|
||||
* @param app
|
||||
* @param opts
|
||||
*/
|
||||
public attachApp(app /*: TemplatedApp */, opts: Partial<ServerOptions> = {}) {
|
||||
// merge the options passed to the Socket.IO server
|
||||
Object.assign(opts, this.opts);
|
||||
@@ -582,7 +591,7 @@ export class Server<
|
||||
): void {
|
||||
// initialize engine
|
||||
debug("creating engine.io instance with opts %j", opts);
|
||||
this.eio = attach(srv, opts);
|
||||
this.eio = attach(srv as http.Server, opts);
|
||||
|
||||
// attach static file serving
|
||||
if (this._serveClient) this.attachServe(srv);
|
||||
@@ -723,11 +732,12 @@ export class Server<
|
||||
* @return self
|
||||
* @private
|
||||
*/
|
||||
private onconnection(conn): this {
|
||||
private onconnection(conn: RawSocket): this {
|
||||
// @ts-expect-error use of private
|
||||
debug("incoming connection with id %s", conn.id);
|
||||
const client = new Client(this, conn);
|
||||
if (conn.protocol === 3) {
|
||||
// @ts-ignore
|
||||
// @ts-expect-error use of private
|
||||
client.connect("/");
|
||||
}
|
||||
return this;
|
||||
|
||||
@@ -197,6 +197,10 @@ export class Namespace<
|
||||
_initAdapter(): void {
|
||||
// @ts-ignore
|
||||
this.adapter = new (this.server.adapter()!)(this);
|
||||
|
||||
Promise.resolve(this.adapter.init()).catch((err) => {
|
||||
debug("error while initializing adapter: %s", err);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -163,7 +163,7 @@ export class Socket<
|
||||
) {
|
||||
super();
|
||||
this.server = nsp.server;
|
||||
this.adapter = this.nsp.adapter;
|
||||
this.adapter = nsp.adapter;
|
||||
if (previousSession) {
|
||||
this.id = previousSession.sid;
|
||||
this.pid = previousSession.pid;
|
||||
|
||||
@@ -26,9 +26,12 @@
|
||||
"type": "commonjs",
|
||||
"main": "./dist/index.js",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./wrapper.mjs",
|
||||
"require": "./dist/index.js"
|
||||
".": {
|
||||
"types": "./dist/index.d.ts",
|
||||
"import": "./wrapper.mjs",
|
||||
"require": "./dist/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"types": "./dist/index.d.ts",
|
||||
"license": "MIT",
|
||||
@@ -44,7 +47,7 @@
|
||||
"compile": "rimraf ./dist && tsc",
|
||||
"test": "npm run format:check && npm run compile && npm run test:types && npm run test:unit",
|
||||
"test:types": "tsd",
|
||||
"test:unit": "nyc mocha --require ts-node/register --reporter spec --slow 200 --bail --timeout 10000 test/index.ts",
|
||||
"test:unit": "nyc mocha --import=tsx --reporter spec --slow 200 --bail --timeout 10000 test/index.ts",
|
||||
"format:check": "prettier --check \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"format:fix": "prettier --write \"lib/**/*.ts\" \"test/**/*.ts\"",
|
||||
"prepack": "npm run compile"
|
||||
@@ -53,7 +56,7 @@
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "~2.0.0",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.2",
|
||||
"debug": "~4.4.1",
|
||||
"engine.io": "~6.6.0",
|
||||
"socket.io-adapter": "~2.5.2",
|
||||
"socket.io-parser": "~4.2.4"
|
||||
|
||||
Reference in New Issue
Block a user