Skip to content

Commit 3f03362

Browse files
Mohit TejaniMohit Tejani
authored andcommitted
added missing subscriptionSet example code snippets
1 parent e23870d commit 3f03362

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

docs-snippets/publish-subscribe.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,47 @@ pubnub.unsubscribe({
197197
pubnub.unsubscribe({
198198
channelGroups: ["demo_group1", "demo_group2"],
199199
});
200-
// snippet.end
200+
// snippet.end
201+
202+
{
203+
// snippet.subscriptionSetFrom2IndividualSubscriptions
204+
// create a subscription from a channel entity
205+
const channel = pubnub.channel('channel_1')
206+
const subscription1 = channel.subscription({ receivePresenceEvents: true });
207+
208+
// create a subscription from a channel group entity
209+
const channelGroup = pubnub.channelGroup('channelGroup_1')
210+
const subscription2 = channelGroup.subscription();
211+
212+
// add 2 subscriptions to create a subscription set
213+
const subscriptionSet = subscription1.addSubscription(subscription2);
214+
215+
// add another subscription to the set
216+
const subscription3 = pubnub.channel('channel_3').subscription({ receivePresenceEvents: false });
217+
subscriptionSet.addSubscription(subscription3);
218+
219+
// remove a subscription from a subscription set
220+
subscriptionSet.removeSubscription(subscription3);
221+
222+
subscriptionSet.subscribe();
223+
// snippet.end
224+
}
225+
226+
{
227+
// snippet.SubscriptionSetFrom2Sets
228+
// create a subscription set with multiple channels
229+
const subscriptionSet1 = pubnub.subscriptionSet({ channels: ['ch1', 'ch2'] });
230+
231+
// create a subscription set with multiple channel groups and options
232+
const subscriptionSet2 = pubnub.subscriptionSet({
233+
channels: ['ch1', 'ch2'],
234+
subscriptionOptions: { receivePresenceEvents: true }
235+
});
236+
237+
// create a new subscription set from 2 sets
238+
const subscriptionSet3 = subscriptionSet1.addSubscriptionSet(subscriptionSet2);
239+
240+
// you can also remove sets
241+
const subscriptionSetWithChannelsOnly = subscriptionSet3.removeSubscriptionSet(subscriptionSet2);
242+
// snippet.end
243+
}

lib/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4767,7 +4767,7 @@ declare namespace PubNub {
47674767
*
47684768
* @param subscriptionSet - Other entities' subscription set, which should be joined.
47694769
*/
4770-
addSubscriptionSet(subscriptionSet: SubscriptionSet): void;
4770+
addSubscriptionSet(subscriptionSet: SubscriptionSet): SubscriptionSet;
47714771
/**
47724772
* Subtract another {@link SubscriptionSet} object.
47734773
*

0 commit comments

Comments
 (0)