Browse Source

fix(BridgeChannel): Attempt conn retries when there are remote endpoints.

Currently, the client doesn't attempt to re-establish bridge WS when the connection is closed by the remote end with a code 1001. We have noticed that Cloudflare terminates the WS with the same error code when it recycles its proxies. When that happens, client ends up not having a bridge channel which can result quality issues.
Client now tries to re-establish connection when there are remote endpoints in the call.
dev1
Jaya Allamsetty 2 years ago
parent
commit
df2c309658
2 changed files with 12 additions and 6 deletions
  1. 11
    5
      modules/RTC/BridgeChannel.js
  2. 1
    1
      modules/RTC/RTC.js

+ 11
- 5
modules/RTC/BridgeChannel.js View File

21
      * instance.
21
      * instance.
22
      * @param {string} [wsUrl] WebSocket URL.
22
      * @param {string} [wsUrl] WebSocket URL.
23
      * @param {EventEmitter} emitter the EventEmitter instance to use for event emission.
23
      * @param {EventEmitter} emitter the EventEmitter instance to use for event emission.
24
+     * @param {JitsiConference} conference the conference instance.
24
      */
25
      */
25
-    constructor(peerconnection, wsUrl, emitter) {
26
+    constructor(peerconnection, wsUrl, emitter, conference) {
26
         if (!peerconnection && !wsUrl) {
27
         if (!peerconnection && !wsUrl) {
27
             throw new TypeError('At least peerconnection or wsUrl must be given');
28
             throw new TypeError('At least peerconnection or wsUrl must be given');
28
         } else if (peerconnection && wsUrl) {
29
         } else if (peerconnection && wsUrl) {
39
         // @type {RTCDataChannel|WebSocket}
40
         // @type {RTCDataChannel|WebSocket}
40
         this._channel = null;
41
         this._channel = null;
41
 
42
 
43
+        // The conference that uses this bridge channel.
44
+        this._conference = conference;
45
+
42
         // Whether the channel is connected or not. It will start as undefined
46
         // Whether the channel is connected or not. It will start as undefined
43
         // for the first connection attempt. Then transition to either true or false.
47
         // for the first connection attempt. Then transition to either true or false.
44
         this._connected = undefined;
48
         this._connected = undefined;
377
                 return;
381
                 return;
378
             }
382
             }
379
 
383
 
380
-            // When the JVB closes the connection gracefully due to the participant being alone in
381
-            // the meeting it uses code 1001, so treat that as a graceful close and don't say
382
-            // anything.
383
-            const isGracefulClose = this._closedFromClient || event.code === 1001;
384
+            // When the JVB closes the connection gracefully due to the participant being alone in the meeting it uses
385
+            // code 1001. However, the same code is also used by Cloudflare when it terminates the ws. Therefore, check
386
+            // for the number of remote participants in the call and abort retries only when the endpoint is the only
387
+            // endpoint in the call.
388
+            const isGracefulClose = this._closedFromClient
389
+                || (event.code === 1001 && this._conference.getParticipantCount() === 1);
384
 
390
 
385
             if (!isGracefulClose) {
391
             if (!isGracefulClose) {
386
                 const { code, reason } = event;
392
                 const { code, reason } = event;

+ 1
- 1
modules/RTC/RTC.js View File

193
      * @param {string} [wsUrl] WebSocket URL.
193
      * @param {string} [wsUrl] WebSocket URL.
194
      */
194
      */
195
     initializeBridgeChannel(peerconnection, wsUrl) {
195
     initializeBridgeChannel(peerconnection, wsUrl) {
196
-        this._channel = new BridgeChannel(peerconnection, wsUrl, this.eventEmitter);
196
+        this._channel = new BridgeChannel(peerconnection, wsUrl, this.eventEmitter, this.conference);
197
 
197
 
198
         this._channelOpenListener = () => {
198
         this._channelOpenListener = () => {
199
             const logError = (error, msgType, value) => {
199
             const logError = (error, msgType, value) => {

Loading…
Cancel
Save