瀏覽代碼

feat(RTC) added DTLS transport monitoring

dev1
Nils Ohlmeier 3 年之前
父節點
當前提交
7ea0f6a1d8
共有 1 個文件被更改,包括 38 次插入0 次删除
  1. 38
    0
      modules/RTC/TraceablePeerConnection.js

+ 38
- 0
modules/RTC/TraceablePeerConnection.js 查看文件

191
      */
191
      */
192
     this.remoteUfrag = null;
192
     this.remoteUfrag = null;
193
 
193
 
194
+    /**
195
+     * The DTLS transport object for the PeerConnection.
196
+     * Note: this assume only one shared transport exists because we bundled
197
+     *       all streams on the same underlying transport.
198
+     */
199
+    this._dtlsTransport = null;
200
+
194
     /**
201
     /**
195
      * The signaling layer which operates this peer connection.
202
      * The signaling layer which operates this peer connection.
196
      * @type {SignalingLayer}
203
      * @type {SignalingLayer}
2277
     });
2284
     });
2278
 };
2285
 };
2279
 
2286
 
2287
+/**
2288
+ * Sets up the _dtlsTransport object and initializes callbacks for it.
2289
+ */
2290
+TraceablePeerConnection.prototype._initializeDtlsTransport = function() {
2291
+    // We are assuming here that we only have one bundled transport here
2292
+    if (this._dtlsTransport) {
2293
+        return;
2294
+    }
2295
+
2296
+    const senders = this.peerconnection.getSenders();
2297
+
2298
+    if (senders.length !== 0 && senders[0].transport) {
2299
+        this._dtlsTransport = senders[0].transport;
2300
+
2301
+        this._dtlsTransport.onerror = error => {
2302
+            logger.error(`${this} DtlsTransport error: ${error}`);
2303
+        };
2304
+
2305
+        this._dtlsTransport.onstatechange = () => {
2306
+            this.trace('dtlsTransport.onstatechange', this._dtlsTransport.state);
2307
+        };
2308
+    }
2309
+};
2310
+
2311
+
2280
 /**
2312
 /**
2281
  * Configures the stream encodings depending on the video type and the bitrates configured.
2313
  * Configures the stream encodings depending on the video type and the bitrates configured.
2282
  *
2314
  *
2316
                     this.localUfrag = localUfrag;
2348
                     this.localUfrag = localUfrag;
2317
                     this.eventEmitter.emit(RTCEvents.LOCAL_UFRAG_CHANGED, this, localUfrag);
2349
                     this.eventEmitter.emit(RTCEvents.LOCAL_UFRAG_CHANGED, this, localUfrag);
2318
                 }
2350
                 }
2351
+
2352
+                this._initializeDtlsTransport();
2353
+
2319
                 resolve();
2354
                 resolve();
2320
             }, err => {
2355
             }, err => {
2321
                 this.trace('setLocalDescriptionOnFailure', err);
2356
                 this.trace('setLocalDescriptionOnFailure', err);
2405
                     this.remoteUfrag = remoteUfrag;
2440
                     this.remoteUfrag = remoteUfrag;
2406
                     this.eventEmitter.emit(RTCEvents.REMOTE_UFRAG_CHANGED, this, remoteUfrag);
2441
                     this.eventEmitter.emit(RTCEvents.REMOTE_UFRAG_CHANGED, this, remoteUfrag);
2407
                 }
2442
                 }
2443
+
2444
+                this._initializeDtlsTransport();
2445
+
2408
                 resolve();
2446
                 resolve();
2409
             }, err => {
2447
             }, err => {
2410
                 this.trace('setRemoteDescriptionOnFailure', err);
2448
                 this.trace('setRemoteDescriptionOnFailure', err);

Loading…
取消
儲存