@@ -53,9 +53,37 @@ const state = remoteParticipant.state;
53
53
```
54
54
55
55
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 )
56
57
57
58
``` 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 ) => {
59
87
try {
60
88
// Inspect the initial remoteParticipant.state value.
61
89
console .log (` Remote participant state: ${ remoteParticipant .state } ` );
@@ -76,19 +104,6 @@ const subscribeToRemoteParticipant = (remoteParticipant: RemoteParticipant) => {
76
104
console .error (error);
77
105
}
78
106
}
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
- });
92
107
```
93
108
94
109
Before admit or reject ` remoteParticipant ` with ` InLobby ` state, you could get the identifier for a remote participant:
0 commit comments