Skip to content

Commit 7ca2b69

Browse files
Initial commit
0 parents  commit 7ca2b69

14 files changed

+4849
-0
lines changed

.github/workflows/ci.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * 0'
8+
9+
jobs:
10+
test-node:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [12.x, 14.x, 16.x]
16+
17+
services:
18+
postgres:
19+
image: postgres
20+
env:
21+
POSTGRES_PASSWORD: changeit
22+
options: >-
23+
--health-cmd pg_isready
24+
--health-interval 10s
25+
--health-timeout 5s
26+
--health-retries 5
27+
ports:
28+
- 5432:5432
29+
30+
steps:
31+
- uses: actions/checkout@v2
32+
- name: Use Node.js ${{ matrix.node-version }}
33+
uses: actions/setup-node@v1
34+
with:
35+
node-version: ${{ matrix.node-version }}
36+
37+
- run: npm ci
38+
39+
- run: npm test
40+
env:
41+
CI: true
42+
timeout-minutes: 10

.gitignore

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
pids
11+
logs
12+
results
13+
14+
npm-debug.log
15+
node_modules
16+
.idea
17+
.nyc_output/
18+
dist/

CHANGELOG.md

Whitespace-only changes.

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2021 Damien Arrachequesne (@darrachequesne)
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Socket.IO Postgres adapter
2+
3+
The `@socket.io/postgres-adapter` package allows broadcasting packets between multiple Socket.IO servers.
4+
5+
![Adapter diagram](./assets/adapter.png)
6+
7+
Supported features:
8+
9+
- [broadcasting](https://socket.io/docs/v4/broadcasting-events/)
10+
- [utility methods](https://socket.io/docs/v4/server-instance/#Utility-methods)
11+
- [`socketsJoin`](https://socket.io/docs/v4/server-instance/#socketsJoin)
12+
- [`socketsLeave`](https://socket.io/docs/v4/server-instance/#socketsLeave)
13+
- [`disconnectSockets`](https://socket.io/docs/v4/server-instance/#disconnectSockets)
14+
- [`fetchSockets`](https://socket.io/docs/v4/server-instance/#fetchSockets)
15+
- [`serverSideEmit`](https://socket.io/docs/v4/server-instance/#serverSideEmit)
16+
17+
**Table of contents**
18+
19+
- [Installation](#installation)
20+
- [Usage](#usage)
21+
- [License](#license)
22+
23+
## Installation
24+
25+
```
26+
npm install @socket.io/postgres-adapter pg
27+
```
28+
29+
For TypeScript users, you might also need `@types/pg`.
30+
31+
## Usage
32+
33+
```js
34+
const { Server } = require("socket.io");
35+
const { createAdapter } = require("@socket.io/postgres-adapter");
36+
const { Pool } = require("pg");
37+
38+
const io = new Server();
39+
40+
const pool = new Pool({
41+
user: "postgres",
42+
host: "localhost",
43+
database: "postgres",
44+
password: "changeit",
45+
port: 5432,
46+
});
47+
48+
pool.query(`
49+
CREATE TABLE IF NOT EXISTS events (
50+
id bigserial UNIQUE,
51+
created_at timestamptz DEFAULT NOW(),
52+
payload bytea
53+
);
54+
`);
55+
56+
io.adapter(createAdapter(pool));
57+
io.listen(3000);
58+
```
59+
60+
## License
61+
62+
[MIT](LICENSE)

0 commit comments

Comments
 (0)