浏览代码

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,6 +191,13 @@ export default function TraceablePeerConnection(
191 191
      */
192 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 202
      * The signaling layer which operates this peer connection.
196 203
      * @type {SignalingLayer}
@@ -2277,6 +2284,31 @@ TraceablePeerConnection.prototype._mungeOpus = function(description) {
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 2313
  * Configures the stream encodings depending on the video type and the bitrates configured.
2282 2314
  *
@@ -2316,6 +2348,9 @@ TraceablePeerConnection.prototype.setLocalDescription = function(description) {
2316 2348
                     this.localUfrag = localUfrag;
2317 2349
                     this.eventEmitter.emit(RTCEvents.LOCAL_UFRAG_CHANGED, this, localUfrag);
2318 2350
                 }
2351
+
2352
+                this._initializeDtlsTransport();
2353
+
2319 2354
                 resolve();
2320 2355
             }, err => {
2321 2356
                 this.trace('setLocalDescriptionOnFailure', err);
@@ -2405,6 +2440,9 @@ TraceablePeerConnection.prototype.setRemoteDescription = function(description) {
2405 2440
                     this.remoteUfrag = remoteUfrag;
2406 2441
                     this.eventEmitter.emit(RTCEvents.REMOTE_UFRAG_CHANGED, this, remoteUfrag);
2407 2442
                 }
2443
+
2444
+                this._initializeDtlsTransport();
2445
+
2408 2446
                 resolve();
2409 2447
             }, err => {
2410 2448
                 this.trace('setRemoteDescriptionOnFailure', err);

正在加载...
取消
保存