Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions docs-snippets/publish-subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ pubnub.unsubscribe({
// create a subscription set with multiple channels
const subscriptionSet1 = pubnub.subscriptionSet({ channels: ['ch1', 'ch2'] });

// create a subscription set with multiple channel groups and options
// create another subscription set with multiple channels and options
const subscriptionSet2 = pubnub.subscriptionSet({
channels: ['ch1', 'ch2'],
channels: ['ch3', 'ch4'],
subscriptionOptions: { receivePresenceEvents: true },
});

Expand All @@ -236,3 +236,28 @@ subscriptionSet1.addSubscriptionSet(subscriptionSet2);
// remove a subscription set from another subscription set
subscriptionSet1.removeSubscriptionSet(subscriptionSet2);
// snippet.end

// snippet.AddToExistingSubscriptionSet
// create a subscription set with multiple channels
const subscriptionSet1 = pubnub.subscriptionSet({ channels: ['ch1', 'ch2'] });

// subscribe to the set
// start receiving events from ch1 and ch2
subscriptionSet1.subscribe();

// create another subscription set with multiple channels
const subscriptionSet2 = pubnub.subscriptionSet({ channels: ['ch3', 'ch4'] });

// add the new set to the initial set
subscriptionSet1.addSubscriptionSet(subscriptionSet2);

// you're now receiving events from ch1, ch2, ch3, and ch4
// because the set has been subscribed to previously

// create and add another subscription to the set
const channelGroup = pubnub.channelGroup('channelGroup_1');
const subscription2 = channelGroup.subscription();
subscriptionSet1.addSubscription(subscription2);

// you're now receiving events from ch1, ch2, ch3, and ch4 and channelGroup_1
// snippet.end
Loading