Skip to content

Commit

Permalink
allow the specification of options for subscription creation (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaugh42 authored and Ido Shamun committed Jan 7, 2020
1 parent 45432cf commit b3324b6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ process, you should use [socket.io-emitter](https://github.com/socketio/socket.i

### adapter(pubsub[, opts])

`pubsub` is a [google-cloud](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud) [pubsub](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/pubsub) object.
`pubsub` is a [google-cloud](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud) [pubsub](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/pubsub) object.

The following options are allowed:

- `key`: the topic name of the pub/sub events (`socket.io`)
- `createSubscriptionOpts`: [options for creating a subscription](https://googleapis.dev/nodejs/pubsub/latest/global.html#CreateSubscriptionRequest)


### PubsubAdapter
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function adapter(pubsub, opts) {

const prefix = opts.key || 'socket.io';
const uid = `socket.io-${shortid.generate()}`;
const createSubscriptionOpts = opts.createSubscriptionOpts || {};

/**
* PubsubAdapter constructor.
Expand All @@ -84,6 +85,7 @@ function adapter(pubsub, opts) {
this.prefix = prefix;
this.channel = prefix + '#' + nsp.name + '#';
this.topics = {};
this.createSubscriptionOpts = createSubscriptionOpts;
this.subscriptions = {};

this.subscribe(this.prefix, () => {
Expand Down Expand Up @@ -128,7 +130,7 @@ function adapter(pubsub, opts) {
callback(null, topicObj);
},

getSubscription.bind(null, this.uid, {})
getSubscription.bind(null, this.uid, this.createSubscriptionOpts)
], (err, subscription) => {

if (err) {
Expand Down

0 comments on commit b3324b6

Please sign in to comment.