0.1.0 • Published 1 year ago

@socket.io/gcp-pubsub-adapter v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

Featuresocket.io versionSupport
Socket management4.0.0:white_check_mark: YES (since version 0.1.0)
Inter-server communication4.1.0:white_check_mark: YES (since version 0.1.0)
Broadcast with acknowledgements4.5.0:white_check_mark: YES (since version 0.1.0)
Connection state recovery4.6.0:x: NO

Installation

npm install @socket.io/gcp-pubsub-adapter

Usage

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

NameDescriptionDefault value
subscriptionPrefixThe prefix for the new subscription to create.socket.io
subscriptionOptionsThe options used to create the subscription.-
heartbeatIntervalThe number of ms between two heartbeats.5_000
heartbeatTimeoutThe number of ms without heartbeat before we consider a node down.10_000

License

MIT