https://github.com/socketio/socket.io-gcp-pubsub-adapter
The Socket.IO adapter for Google Cloud pub/sub, allowing to broadcast events between several Socket.IO servers
https://github.com/socketio/socket.io-gcp-pubsub-adapter
gcp gcp-pubsub socketio
Last synced: 10 months ago
JSON representation
The Socket.IO adapter for Google Cloud pub/sub, allowing to broadcast events between several Socket.IO servers
- Host: GitHub
- URL: https://github.com/socketio/socket.io-gcp-pubsub-adapter
- Owner: socketio
- License: mit
- Created: 2024-03-18T17:30:35.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-19T13:54:57.000Z (almost 2 years ago)
- Last Synced: 2025-03-20T08:22:40.546Z (11 months ago)
- Topics: gcp, gcp-pubsub, socketio
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@socket.io/gcp-pubsub-adapter
- Size: 53.7 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Socket.IO Google Cloud pub/sub adapter
The `@socket.io/gcp-pubsub-adapter` package allows broadcasting packets between multiple Socket.IO servers.
**Table of contents**
- [Supported features](#supported-features)
- [Installation](#installation)
- [Usage](#usage)
- [Options](#options)
- [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.1.0`) |
| Connection state recovery | `4.6.0` | :x: NO |
## Installation
```
npm install @socket.io/gcp-pubsub-adapter
```
## Usage
```js
import { PubSub } from "@google-cloud/pubsub";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/gcp-pubsub-adapter";
const pubsub = new PubSub({
projectId: "your-project-id"
});
const topic = pubsub.topic(topicNameOrId);
const io = new Server({
adapter: createAdapter(topic)
});
// wait for the creation of the pub/sub subscription
await io.of("/").adapter.init();
io.listen(3000);
```
## Options
| Name | Description | Default value |
|-----------------------|-------------------------------------------------------------------------------------------------------------------|----------------|
| `subscriptionPrefix` | The prefix for the new subscription to create. | `socket.io` |
| `subscriptionOptions` | The options used to create the subscription. | `-` |
| `heartbeatInterval` | The number of ms between two heartbeats. | `5_000` |
| `heartbeatTimeout` | The number of ms without heartbeat before we consider a node down. | `10_000` |
## License
[MIT](LICENSE)