Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jun 14, 2021
0 parents commit 7ca2b69
Show file tree
Hide file tree
Showing 14 changed files with 4,849 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: CI

on:
push:
pull_request:
schedule:
- cron: '0 0 * * 0'

jobs:
test-node:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: changeit
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- run: npm ci

- run: npm test
env:
CI: true
timeout-minutes: 10
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz

pids
logs
results

npm-debug.log
node_modules
.idea
.nyc_output/
dist/
Empty file added CHANGELOG.md
Empty file.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Socket.IO Postgres adapter

The `@socket.io/postgres-adapter` package allows broadcasting packets between multiple Socket.IO servers.

![Adapter diagram](./assets/adapter.png)

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)

**Table of contents**

- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

## Installation

```
npm install @socket.io/postgres-adapter pg
```

For TypeScript users, you might also need `@types/pg`.

## Usage

```js
const { Server } = require("socket.io");
const { createAdapter } = require("@socket.io/postgres-adapter");
const { Pool } = require("pg");

const io = new Server();

const pool = new Pool({
user: "postgres",
host: "localhost",
database: "postgres",
password: "changeit",
port: 5432,
});

pool.query(`
CREATE TABLE IF NOT EXISTS events (
id bigserial UNIQUE,
created_at timestamptz DEFAULT NOW(),
payload bytea
);
`);

io.adapter(createAdapter(pool));
io.listen(3000);
```

## License

[MIT](LICENSE)

0 comments on commit 7ca2b69

Please sign in to comment.