Bläddra i källkod

lastn: allow setting the last N value early

If it's set before the data channel is open, save it and send it as soon as the
data channel is open.
release-8443
Saúl Ibarra Corretgé 8 år sedan
förälder
incheckning
1a7c75bb76
1 ändrade filer med 25 tillägg och 4 borttagningar
  1. 25
    4
      modules/RTC/RTC.js

+ 25
- 4
modules/RTC/RTC.js Visa fil

85
         // this happen
85
         // this happen
86
         this.dataChannelsOpen = false;
86
         this.dataChannelsOpen = false;
87
 
87
 
88
+        /**
89
+         * The value specified to the last invocation of setLastN before the
90
+         * data channels completed opening. If non-null, the value will be sent
91
+         * through a data channel (once) as soon as it opens and will then be
92
+         * discarded.
93
+         *
94
+         * @private
95
+         * @type {number}
96
+         */
97
+        this._lastN = null;
98
+
88
         // Defines the last N endpoints list. It can be null or an array once
99
         // Defines the last N endpoints list. It can be null or an array once
89
         // initialised with a datachannel last N event.
100
         // initialised with a datachannel last N event.
90
         // @type {Array<string>|null}
101
         // @type {Array<string>|null}
165
                 this.removeListener(RTCEvents.DATA_CHANNEL_OPEN,
176
                 this.removeListener(RTCEvents.DATA_CHANNEL_OPEN,
166
                     this._dataChannelOpenListener);
177
                     this._dataChannelOpenListener);
167
                 this._dataChannelOpenListener = null;
178
                 this._dataChannelOpenListener = null;
179
+
180
+                // If setLastN was invoked before the data channels completed
181
+                // opening, apply the specified value now that the data channels
182
+                // are open.
183
+                if (this._lastN !== null) {
184
+                    this.setLastN(this._lastN);
185
+                    this._lastN = null;
186
+                }
168
             };
187
             };
169
             this.addListener(RTCEvents.DATA_CHANNEL_OPEN,
188
             this.addListener(RTCEvents.DATA_CHANNEL_OPEN,
170
                 this._dataChannelOpenListener);
189
                 this._dataChannelOpenListener);
722
      * Selects a new value for "lastN". The requested amount of videos are going
741
      * Selects a new value for "lastN". The requested amount of videos are going
723
      * to be delivered after the value is in effect. Set to -1 for unlimited or
742
      * to be delivered after the value is in effect. Set to -1 for unlimited or
724
      * all available videos.
743
      * all available videos.
725
-     * @param value {int} the new value for lastN.
726
-     * @trows Error if there is no data channel created.
744
+     * @param value {number} the new value for lastN.
727
      */
745
      */
728
     setLastN(value) {
746
     setLastN(value) {
729
-        if (this.dataChannels) {
747
+        if (this.dataChannels && this.dataChannelsOpen) {
730
             this.dataChannels.sendSetLastNMessage(value);
748
             this.dataChannels.sendSetLastNMessage(value);
731
         } else {
749
         } else {
732
-            throw new Error('Data channels support is disabled!');
750
+            // No data channel has been initialized or has completed opening
751
+            // yet. Remember the specified value and apply it as soon as a data
752
+            // channel opens.
753
+            this._lastN = value;
733
         }
754
         }
734
     }
755
     }
735
 
756
 

Laddar…
Avbryt
Spara