|
@@ -0,0 +1,63 @@
|
|
1
|
+/* global __filename, module, require */
|
|
2
|
+var logger = require("jitsi-meet-logger").getLogger(__filename);
|
|
3
|
+var RTCEvents = require("../../service/RTC/RTCEvents");
|
|
4
|
+import * as JitsiConferenceEvents from "../../JitsiConferenceEvents";
|
|
5
|
+
|
|
6
|
+/**
|
|
7
|
+ * Class is responsible for emitting
|
|
8
|
+ * JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED events.
|
|
9
|
+ *
|
|
10
|
+ * @constructor
|
|
11
|
+ * @param rtc {RTC} the RTC service instance
|
|
12
|
+ * @param conference {JitsiConference} parent conference instance
|
|
13
|
+ */
|
|
14
|
+function ParticipantConnectionStatus(rtc, conference) {
|
|
15
|
+ this.rtc = rtc;
|
|
16
|
+ this.conference = conference;
|
|
17
|
+ rtc.addListener(
|
|
18
|
+ RTCEvents.ENDPOINT_CONN_STATUS_CHANGED,
|
|
19
|
+ this.onEndpointConnStatusChanged.bind(this));
|
|
20
|
+}
|
|
21
|
+
|
|
22
|
+/**
|
|
23
|
+ * Handles RTCEvents.ENDPOINT_CONN_STATUS_CHANGED triggered when we receive
|
|
24
|
+ * notification over the data channel from the bridge about endpoint's
|
|
25
|
+ * connection status update.
|
|
26
|
+ * @param endpointId {string} the endpoint ID(MUC nickname/resource JID)
|
|
27
|
+ * @param status {boolean} true if the connection is OK or false otherwise
|
|
28
|
+ */
|
|
29
|
+ParticipantConnectionStatus.prototype.onEndpointConnStatusChanged
|
|
30
|
+= function(endpointId, status) {
|
|
31
|
+ logger.debug(
|
|
32
|
+ 'Detector RTCEvents.ENDPOINT_CONN_STATUS_CHANGED(' + Date.now() +'): '
|
|
33
|
+ + endpointId +": " + status);
|
|
34
|
+ // Filter out events for the local JID for now
|
|
35
|
+ if (endpointId !== this.conference.myUserId()) {
|
|
36
|
+ this._changeConnectionStatus(endpointId, status);
|
|
37
|
+ }
|
|
38
|
+};
|
|
39
|
+
|
|
40
|
+ParticipantConnectionStatus.prototype._changeConnectionStatus
|
|
41
|
+= function (endpointId, newStatus) {
|
|
42
|
+ var participant = this.conference.getParticipantById(endpointId);
|
|
43
|
+ if (!participant) {
|
|
44
|
+ // This will happen when participant exits the conference with broken
|
|
45
|
+ // ICE connection and we join after that. The bridge keeps sending
|
|
46
|
+ // that notification until the conference does not expire.
|
|
47
|
+ logger.warn(
|
|
48
|
+ 'Missed participant connection status update - ' +
|
|
49
|
+ 'no participant for endpoint: ' + endpointId);
|
|
50
|
+ return;
|
|
51
|
+ }
|
|
52
|
+ if (participant.isConnectionActive() !== newStatus) {
|
|
53
|
+ participant._setIsConnectionActive(newStatus);
|
|
54
|
+ logger.debug(
|
|
55
|
+ 'Emit endpoint conn status(' + Date.now() + '): ',
|
|
56
|
+ endpointId, newStatus);
|
|
57
|
+ this.conference.eventEmitter.emit(
|
|
58
|
+ JitsiConferenceEvents.PARTICIPANT_CONN_STATUS_CHANGED,
|
|
59
|
+ endpointId, newStatus);
|
|
60
|
+ }
|
|
61
|
+};
|
|
62
|
+
|
|
63
|
+module.exports = ParticipantConnectionStatus;
|