Browse Source

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

Moves caching of selected endpoint out of data channel.
dev1
Paweł Domas 9 years ago
parent
commit
ebed693847
3 changed files with 34 additions and 22 deletions
  1. 1
    0
      JitsiConference.js
  2. 0
    15
      modules/RTC/DataChannels.js
  3. 33
    7
      modules/RTC/RTC.js

+ 1
- 0
JitsiConference.js View File

597
 /**
597
 /**
598
  * Elects the participant with the given id to be the selected participant in
598
  * Elects the participant with the given id to be the selected participant in
599
  * order to receive higher video quality (if simulcast is enabled).
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
  * @param participantId the identifier of the participant
601
  * @param participantId the identifier of the participant
601
  * @throws NetworkError or InvalidStateError or Error if the operation fails.
602
  * @throws NetworkError or InvalidStateError or Error if the operation fails.
602
  */
603
  */

+ 0
- 15
modules/RTC/DataChannels.js View File

51
 DataChannels.prototype.onDataChannel = function (event) {
51
 DataChannels.prototype.onDataChannel = function (event) {
52
     var dataChannel = event.channel;
52
     var dataChannel = event.channel;
53
     var self = this;
53
     var self = this;
54
-    var selectedEndpoint = null;
55
 
54
 
56
     dataChannel.onopen = function () {
55
     dataChannel.onopen = function () {
57
         logger.info("Data channel opened by the Videobridge!", dataChannel);
56
         logger.info("Data channel opened by the Videobridge!", dataChannel);
63
         //dataChannel.send(new ArrayBuffer(12));
62
         //dataChannel.send(new ArrayBuffer(12));
64
 
63
 
65
         self.eventEmitter.emit(RTCEvents.DATA_CHANNEL_OPEN);
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
     dataChannel.onerror = function (error) {
67
     dataChannel.onerror = function (error) {
195
  * or Error with "No opened data channels found!" message.
181
  * or Error with "No opened data channels found!" message.
196
  */
182
  */
197
 DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
183
 DataChannels.prototype.sendSelectedEndpointMessage = function (endpointId) {
198
-    this.selectedEndpoint = endpointId;
199
     this._onXXXEndpointChanged("selected", endpointId);
184
     this._onXXXEndpointChanged("selected", endpointId);
200
 };
185
 };
201
 
186
 

+ 33
- 7
modules/RTC/RTC.js View File

84
 };
84
 };
85
 
85
 
86
 RTC.prototype.onIncommingCall = function(event) {
86
 RTC.prototype.onIncommingCall = function(event) {
87
-    if(this.options.config.openSctp)
87
+    if(this.options.config.openSctp) {
88
         this.dataChannels = new DataChannels(event.peerconnection,
88
         this.dataChannels = new DataChannels(event.peerconnection,
89
             this.eventEmitter);
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
 };
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
  * order to always receive video for this participant (even when last n is
130
  * order to always receive video for this participant (even when last n is
109
  * enabled).
131
  * enabled).
132
+ * If there is no data channel we store it and send it through the channel once
133
+ * it is created.
110
  * @param id {string} the user id.
134
  * @param id {string} the user id.
111
  * @throws NetworkError or InvalidStateError or Error if the operation fails.
135
  * @throws NetworkError or InvalidStateError or Error if the operation fails.
112
 */
136
 */
113
 RTC.prototype.selectEndpoint = function (id) {
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
         this.dataChannels.sendSelectedEndpointMessage(id);
141
         this.dataChannels.sendSelectedEndpointMessage(id);
116
-    } else {
117
-        throw new Error("Data channels support is disabled!");
118
-    }
119
 };
142
 };
120
 
143
 
121
 /**
144
 /**
129
     if(this.dataChannels) {
152
     if(this.dataChannels) {
130
         this.dataChannels.sendPinnedEndpointMessage(id);
153
         this.dataChannels.sendPinnedEndpointMessage(id);
131
     } else {
154
     } else {
155
+        // FIXME: cache value while there is no data channel created
156
+        // and send the cached state once channel is created
132
         throw new Error("Data channels support is disabled!");
157
         throw new Error("Data channels support is disabled!");
133
     }
158
     }
134
 };
159
 };
527
  * @param to {string} the id of the endpoint that should receive the message.
552
  * @param to {string} the id of the endpoint that should receive the message.
528
  * If "" the message will be sent to all participants.
553
  * If "" the message will be sent to all participants.
529
  * @param payload {object} the payload of the message.
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
 RTC.prototype.sendDataChannelMessage = function (to, payload) {
558
 RTC.prototype.sendDataChannelMessage = function (to, payload) {
533
     if(this.dataChannels) {
559
     if(this.dataChannels) {

Loading…
Cancel
Save