Sfoglia il codice sorgente

fix: Ensures simulcast is activated in the browser.

Ensures that the simulcast ssrc-group appears after any other
ssrc-groups in the SDP so that simulcast is properly activated.
tags/v0.0.2
George Politis 8 anni fa
parent
commit
0f5c9a3fbc
1 ha cambiato i file con 39 aggiunte e 0 eliminazioni
  1. 39
    0
      modules/RTC/TraceablePeerConnection.js

+ 39
- 0
modules/RTC/TraceablePeerConnection.js Vedi File

1317
     return this.peerconnection.createDataChannel(label, opts);
1317
     return this.peerconnection.createDataChannel(label, opts);
1318
 };
1318
 };
1319
 
1319
 
1320
+/**
1321
+ * Ensures that the simulcast ssrc-group appears after any other ssrc-groups
1322
+ * in the SDP so that simulcast is properly activated.
1323
+ *
1324
+ * @param {Object} localSdp the WebRTC session description instance for
1325
+ * the local description.
1326
+ * @private
1327
+ */
1328
+TraceablePeerConnection.prototype._ensureSimulcastGroupIsLast
1329
+= function(localSdp) {
1330
+    let sdpStr = localSdp.sdp;
1331
+
1332
+    const videoStartIndex = sdpStr.indexOf('m=video');
1333
+    const simStartIndex = sdpStr.indexOf('a=ssrc-group:SIM', videoStartIndex);
1334
+    let otherStartIndex = sdpStr.lastIndexOf('a=ssrc-group');
1335
+
1336
+    if (simStartIndex === -1
1337
+        || otherStartIndex === -1
1338
+        || otherStartIndex === simStartIndex) {
1339
+        return;
1340
+    }
1341
+
1342
+    const simEndIndex = sdpStr.indexOf('\r\n', simStartIndex);
1343
+    const simStr = sdpStr.substring(simStartIndex, simEndIndex + 2);
1344
+
1345
+    sdpStr = sdpStr.replace(simStr, '');
1346
+    otherStartIndex = sdpStr.lastIndexOf('a=ssrc-group');
1347
+    const otherEndIndex = sdpStr.indexOf('\r\n', otherStartIndex);
1348
+    const sdpHead = sdpStr.slice(0, otherEndIndex);
1349
+    const simStrTrimmed = simStr.trim();
1350
+    const sdpTail = sdpStr.slice(otherEndIndex);
1351
+
1352
+    sdpStr = `${sdpHead}\r\n${simStrTrimmed}${sdpTail}`;
1353
+
1354
+    localSdp.sdp = sdpStr;
1355
+};
1356
+
1320
 /**
1357
 /**
1321
  * Will adjust audio and video media direction in the given SDP object to
1358
  * Will adjust audio and video media direction in the given SDP object to
1322
  * reflect the current status of the {@link mediaTransferActive} flag.
1359
  * reflect the current status of the {@link mediaTransferActive} flag.
1373
 
1410
 
1374
     this._adjustLocalMediaDirection(localSdp);
1411
     this._adjustLocalMediaDirection(localSdp);
1375
 
1412
 
1413
+    this._ensureSimulcastGroupIsLast(localSdp);
1414
+
1376
     // if we're using unified plan, transform to it first.
1415
     // if we're using unified plan, transform to it first.
1377
     if (RTCBrowserType.usesUnifiedPlan()) {
1416
     if (RTCBrowserType.usesUnifiedPlan()) {
1378
         localSdp = this.interop.toUnifiedPlan(localSdp);
1417
         localSdp = this.interop.toUnifiedPlan(localSdp);

Loading…
Annulla
Salva