Skip to content

Commit 1b4f58a

Browse files
committed
update subcription method
1 parent c09dd62 commit 1b4f58a

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

articles/communication-services/how-tos/calling-sdk/lobby-admit-and-reject.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,37 @@ const state = remoteParticipant.state;
5353
```
5454

5555
You could check remote participant state in subscription method:
56+
[Learn more about events and subscription ](../../how-tos/calling-sdk/includes/events/events-web.md)
5657

5758
```js
58-
const subscribeToRemoteParticipant = (remoteParticipant: RemoteParticipant) => {
59+
// Subscribe to a call obj.
60+
// Listen for property changes and collection updates.
61+
subscribeToCall = (call) => {
62+
try {
63+
// Inspect the call's current remote participants and subscribe to them.
64+
call.remoteParticipants.forEach(remoteParticipant => {
65+
subscribeToRemoteParticipant(remoteParticipant);
66+
})
67+
// Subscribe to the call's 'remoteParticipantsUpdated' event to be
68+
// notified when new participants are added to the call or removed from the call.
69+
call.on('remoteParticipantsUpdated', e => {
70+
// Subscribe to new remote participants that are added to the call.
71+
e.added.forEach(remoteParticipant => {
72+
subscribeToRemoteParticipant(remoteParticipant)
73+
});
74+
// Unsubscribe from participants that are removed from the call
75+
e.removed.forEach(remoteParticipant => {
76+
console.log('Remote participant removed from the call.');
77+
})
78+
});
79+
} catch (error) {
80+
console.error(error);
81+
}
82+
}
83+
84+
// Subscribe to a remote participant obj.
85+
// Listen for property changes and collection updates.
86+
subscribeToRemoteParticipant = (remoteParticipant) => {
5987
try {
6088
// Inspect the initial remoteParticipant.state value.
6189
console.log(`Remote participant state: ${remoteParticipant.state}`);
@@ -76,19 +104,6 @@ const subscribeToRemoteParticipant = (remoteParticipant: RemoteParticipant) => {
76104
console.error(error);
77105
}
78106
}
79-
80-
call.on('remoteParticipantsUpdated', args => {
81-
args.added.forEach(p => {
82-
subscribeToRemoteParticipant(p);
83-
});
84-
args.removed.forEach(p => {
85-
console.log(`${p._displayName} leave the meeting`);
86-
});
87-
});
88-
89-
call.remoteParticipants.forEach(p => {
90-
subscribeToRemoteParticipant(p);
91-
});
92107
```
93108

94109
Before admit or reject `remoteParticipant` with `InLobby` state, you could get the identifier for a remote participant:

0 commit comments

Comments
 (0)