瀏覽代碼

feat: add PARTICIPANT_CONN_STATUS_CHANGED conference event

The event is triggered when the notification about the user's connection
status change arrives from the JVB.
dev1
paweldomas 9 年之前
父節點
當前提交
34b05f11f6

+ 5
- 0
JitsiConference.js 查看文件

@@ -18,6 +18,8 @@ var GlobalOnErrorHandler = require("./modules/util/GlobalOnErrorHandler");
18 18
 var JitsiConferenceEventManager = require("./JitsiConferenceEventManager");
19 19
 var VideoType = require('./service/RTC/VideoType');
20 20
 var Transcriber = require("./modules/transcription/transcriber");
21
+var ParticipantConnectionStatus
22
+    = require("./modules/connectivity/ParticipantConnectionStatus");
21 23
 
22 24
 /**
23 25
  * Creates a JitsiConference object with the given name and properties.
@@ -92,6 +94,9 @@ JitsiConference.prototype._init = function (options) {
92 94
         this.eventManager.setupRTCListeners();
93 95
     }
94 96
 
97
+    this.participantConnectionStatus
98
+        = new ParticipantConnectionStatus(this.rtc, this);
99
+
95 100
     if(!this.statistics) {
96 101
         this.statistics = new Statistics(this.xmpp, {
97 102
             callStatsID: this.options.config.callStatsID,

+ 10
- 0
JitsiConferenceEvents.js 查看文件

@@ -81,6 +81,16 @@ export const LOCK_STATE_CHANGED = "conference.lock_state_changed";
81 81
  * New text message was received.
82 82
  */
83 83
 export const MESSAGE_RECEIVED = "conference.messageReceived";
84
+/**
85
+ * Event fired when JVB sends notification about interrupted/restored user's
86
+ * ICE connection status. First argument is the ID of the participant and
87
+ * the seconds is a boolean indicating if the connection is currently
88
+ * active(true = active, false = interrupted).
89
+ * The current status value can be obtained by calling
90
+ * JitsiParticipant.isConnectionActive().
91
+ */
92
+export const PARTICIPANT_CONN_STATUS_CHANGED
93
+    = "conference.participant_conn_status_changed";
84 94
 /**
85 95
  * Indicates that a the value of a specific property of a specific participant
86 96
  * has changed.

+ 21
- 0
JitsiParticipant.js 查看文件

@@ -30,6 +30,7 @@ export default class JitsiParticipant {
30 30
             video: undefined
31 31
         };
32 32
         this._hidden = hidden;
33
+        this._isConnectionActive = true;
33 34
         this._properties = {};
34 35
     }
35 36
 
@@ -48,6 +49,26 @@ export default class JitsiParticipant {
48 49
         return this._properties[name];
49 50
     }
50 51
 
52
+    /**
53
+     * Updates participant's connection status.
54
+     * @param {boolean} isActive true if the user's connection is fine or false
55
+     * when the user is having connectivity issues.
56
+     * @private
57
+     */
58
+    _setIsConnectionActive(isActive) {
59
+        this._isConnectionActive = isActive;
60
+    }
61
+
62
+    /**
63
+     * Checks participant's connectivity status.
64
+     *
65
+     * @returns {boolean} true if the connection is currently ok or false when
66
+     * the user is having connectivity issues.
67
+     */
68
+    isConnectionActive() {
69
+        return this._isConnectionActive;
70
+    }
71
+
51 72
     /**
52 73
      * Sets the value of a property of this participant, and fires an event if
53 74
      * the value has changed.

+ 8
- 0
modules/RTC/DataChannels.js 查看文件

@@ -143,6 +143,14 @@ DataChannels.prototype.onDataChannel = function (event) {
143 143
                     RTCEvents.ENDPOINT_MESSAGE_RECEIVED, obj.from,
144 144
                     obj.msgPayload);
145 145
             }
146
+            else if ("EndpointConnectivityStatusChangeEvent" === colibriClass) {
147
+                var endpoint = obj.endpoint;
148
+                var isActive = obj.active === "true";
149
+                logger.info("Endpoint connection status changed: " + endpoint
150
+                           + " active ? " + isActive);
151
+                self.eventEmitter.emit(RTCEvents.ENDPOINT_CONN_STATUS_CHANGED,
152
+                    endpoint, isActive);
153
+            }
146 154
             else {
147 155
                 logger.debug("Data channel JSON-formatted message: ", obj);
148 156
                 // The received message appears to be appropriately formatted

+ 63
- 0
modules/connectivity/ParticipantConnectionStatus.js 查看文件

@@ -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;

+ 1
- 0
service/RTC/RTCEvents.js 查看文件

@@ -1,6 +1,7 @@
1 1
 var RTCEvents = {
2 2
     RTC_READY: "rtc.ready",
3 3
     DATA_CHANNEL_OPEN: "rtc.data_channel_open",
4
+    ENDPOINT_CONN_STATUS_CHANGED: "rtc.endpoint_conn_status_changed",
4 5
     LASTN_CHANGED: "rtc.lastn_changed",
5 6
     DOMINANTSPEAKER_CHANGED: "rtc.dominantspeaker_changed",
6 7
     LASTN_ENDPOINT_CHANGED: "rtc.lastn_endpoint_changed",

Loading…
取消
儲存