Parcourir la source

Merge pull request #247 from jitsi/dc-selected-endpoint

Moves caching of selected endpoint out of data channel.
dev1
Paweł Domas il y a 9 ans
Parent
révision
ebed693847
3 fichiers modifiés avec 34 ajouts et 22 suppressions
  1. 1
    0
      JitsiConference.js
  2. 0
    15
      modules/RTC/DataChannels.js
  3. 33
    7
      modules/RTC/RTC.js

+ 1
- 0
JitsiConference.js Voir le fichier

@@ -597,6 +597,7 @@ JitsiConference.prototype.unlock = function () {
597 597
 /**
598 598
  * Elects the participant with the given id to be the selected participant in
599 599
  * order to receive higher video quality (if simulcast is enabled).
600
+ * Or cache it if channel is not created and send it once channel is available.
600 601
  * @param participantId the identifier of the participant
601 602
  * @throws NetworkError or InvalidStateError or Error if the operation fails.
602 603
  */

+ 0
- 15
modules/RTC/DataChannels.js Voir le fichier

@@ -51,7 +51,6 @@ function DataChannels(peerConnection, emitter) {
51 51
 DataChannels.prototype.onDataChannel = function (event) {
52 52
     var dataChannel = event.channel;
53 53
     var self = this;
54
-    var selectedEndpoint = null;
55 54
 
56 55
     dataChannel.onopen = function () {
57 56
         logger.info("Data channel opened by the Videobridge!", dataChannel);
@@ -63,19 +62,6 @@ DataChannels.prototype.onDataChannel = function (event) {
63 62
         //dataChannel.send(new ArrayBuffer(12));
64 63
 
65 64
         self.eventEmitter.emit(RTCEvents.DATA_CHANNEL_OPEN);
66
-
67
-        // when the data channel becomes available, tell the bridge about video
68
-        // selections so that it can do adaptive simulcast,
69
-        // we want the notification to trigger even if userJid is undefined,
70
-        // or null.
71
-        // XXX why do we not do the same for pinned endpoints?
72
-        try {
73
-            self.sendSelectedEndpointMessage(self.selectedEndpoint);
74
-        } catch (error) {
75
-            GlobalOnErrorHandler.callErrorHandler(error);
76
-            logger.error("Cannot sendSelectedEndpointMessage ",
77
-                self.selectedEndpoint, ". Error: ", error);
78
-        }
79 65
     };
80 66
 
81 67
     dataChannel.onerror = function (error) {
@@ -195,7 +181,6 @@ DataChannels.prototype.closeAllChannels = function () {
195 181
  * or Error with "No opened data channels found!" message.
196 182
  */
197 183
 DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
198
-    this.selectedEndpoint = endpointId;
199 184
     this._onXXXEndpointChanged("selected", endpointId);
200 185
 };
201 186
 

+ 33
- 7
modules/RTC/RTC.js Voir le fichier

@@ -84,9 +84,31 @@ RTC.obtainAudioAndVideoPermissions = function (options) {
84 84
 };
85 85
 
86 86
 RTC.prototype.onIncommingCall = function(event) {
87
-    if(this.options.config.openSctp)
87
+    if(this.options.config.openSctp) {
88 88
         this.dataChannels = new DataChannels(event.peerconnection,
89 89
             this.eventEmitter);
90
+        this._dataChannelOpenListener = () => {
91
+            // when the data channel becomes available, tell the bridge
92
+            // about video selections so that it can do adaptive simulcast,
93
+            // we want the notification to trigger even if userJid
94
+            // is undefined, or null.
95
+            // XXX why do we not do the same for pinned endpoints?
96
+            try {
97
+                this.dataChannels.sendSelectedEndpointMessage(
98
+                    this.selectedEndpoint);
99
+            } catch (error) {
100
+                GlobalOnErrorHandler.callErrorHandler(error);
101
+                logger.error("Cannot sendSelectedEndpointMessage ",
102
+                    this.selectedEndpoint, ". Error: ", error);
103
+            }
104
+
105
+            this.removeListener(RTCEvents.DATA_CHANNEL_OPEN,
106
+                this._dataChannelOpenListener);
107
+            this._dataChannelOpenListener = null;
108
+        };
109
+        this.addListener(RTCEvents.DATA_CHANNEL_OPEN,
110
+            this._dataChannelOpenListener);
111
+    }
90 112
 };
91 113
 
92 114
 /**
@@ -104,18 +126,19 @@ RTC.prototype.onCallEnded = function() {
104 126
 };
105 127
 
106 128
 /**
107
- * Elects the participant with the given id to be the pinned participant in
129
+ * Elects the participant with the given id to be the selected participant in
108 130
  * order to always receive video for this participant (even when last n is
109 131
  * enabled).
132
+ * If there is no data channel we store it and send it through the channel once
133
+ * it is created.
110 134
  * @param id {string} the user id.
111 135
  * @throws NetworkError or InvalidStateError or Error if the operation fails.
112 136
 */
113 137
 RTC.prototype.selectEndpoint = function (id) {
114
-    if(this.dataChannels) {
138
+    // cache the value if channel is missing, till we open it
139
+    this.selectedEndpoint = id;
140
+    if(this.dataChannels)
115 141
         this.dataChannels.sendSelectedEndpointMessage(id);
116
-    } else {
117
-        throw new Error("Data channels support is disabled!");
118
-    }
119 142
 };
120 143
 
121 144
 /**
@@ -129,6 +152,8 @@ RTC.prototype.pinEndpoint = function (id) {
129 152
     if(this.dataChannels) {
130 153
         this.dataChannels.sendPinnedEndpointMessage(id);
131 154
     } else {
155
+        // FIXME: cache value while there is no data channel created
156
+        // and send the cached state once channel is created
132 157
         throw new Error("Data channels support is disabled!");
133 158
     }
134 159
 };
@@ -527,7 +552,8 @@ RTC.prototype.handleRemoteTrackVideoTypeChanged = function (value, from) {
527 552
  * @param to {string} the id of the endpoint that should receive the message.
528 553
  * If "" the message will be sent to all participants.
529 554
  * @param payload {object} the payload of the message.
530
- * @throws NetworkError or InvalidStateError or Error if the operation fails.
555
+ * @throws NetworkError or InvalidStateError or Error if the operation fails
556
+ * or there is no data channel created
531 557
  */
532 558
 RTC.prototype.sendDataChannelMessage = function (to, payload) {
533 559
     if(this.dataChannels) {

Chargement…
Annuler
Enregistrer