浏览代码

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 年前
父节点
当前提交
1a7c75bb76
共有 1 个文件被更改,包括 25 次插入4 次删除
  1. 25
    4
      modules/RTC/RTC.js

+ 25
- 4
modules/RTC/RTC.js 查看文件

@@ -85,6 +85,17 @@ export default class RTC extends Listenable {
85 85
         // this happen
86 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 99
         // Defines the last N endpoints list. It can be null or an array once
89 100
         // initialised with a datachannel last N event.
90 101
         // @type {Array<string>|null}
@@ -165,6 +176,14 @@ export default class RTC extends Listenable {
165 176
                 this.removeListener(RTCEvents.DATA_CHANNEL_OPEN,
166 177
                     this._dataChannelOpenListener);
167 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 188
             this.addListener(RTCEvents.DATA_CHANNEL_OPEN,
170 189
                 this._dataChannelOpenListener);
@@ -722,14 +741,16 @@ export default class RTC extends Listenable {
722 741
      * Selects a new value for "lastN". The requested amount of videos are going
723 742
      * to be delivered after the value is in effect. Set to -1 for unlimited or
724 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 746
     setLastN(value) {
729
-        if (this.dataChannels) {
747
+        if (this.dataChannels && this.dataChannelsOpen) {
730 748
             this.dataChannels.sendSetLastNMessage(value);
731 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
 

正在加载...
取消
保存