Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/socketio/socket.io-postgres-adapter
The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
https://github.com/socketio/socket.io-postgres-adapter
postgres postgresql socket-io websocket
Last synced: about 1 month ago
JSON representation
The Socket.IO Postgres adapter, allowing to broadcast events between several Socket.IO servers
- Host: GitHub
- URL: https://github.com/socketio/socket.io-postgres-adapter
- Owner: socketio
- License: mit
- Created: 2021-06-12T07:04:12.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T23:47:41.000Z (4 months ago)
- Last Synced: 2024-09-29T01:01:54.432Z (about 1 month ago)
- Topics: postgres, postgresql, socket-io, websocket
- Language: TypeScript
- Homepage: https://socket.io
- Size: 620 KB
- Stars: 24
- Watchers: 3
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Socket.IO Postgres adapter
The `@socket.io/postgres-adapter` package allows broadcasting packets between multiple Socket.IO servers.
**Table of contents**
- [Supported features](#supported-features)
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)## Supported features
| Feature | `socket.io` version | Support |
|---------------------------------|---------------------|------------------------------------------------|
| Socket management | `4.0.0` | :white_check_mark: YES (since version `0.1.0`) |
| Inter-server communication | `4.1.0` | :white_check_mark: YES (since version `0.1.0`) |
| Broadcast with acknowledgements | `4.5.0` | :white_check_mark: YES (since version `0.3.0`) |
| Connection state recovery | `4.6.0` | :x: NO |## Installation
```
npm install @socket.io/postgres-adapter
```## Usage
```js
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/postgres-adapter";
import pg from "pg";const io = new Server();
const pool = new pg.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
);
`);pool.on("error", (err) => {
console.error("Postgres error", err);
});io.adapter(createAdapter(pool));
io.listen(3000);
```## License
[MIT](LICENSE)