Parcourir la source

fix(peerconnection): create a new description to modify sdp (#631)

Firefox has deprecated modifying a description's sdp through
re-assignment. Safari (without temasys) does not allow it.
As such, wherever the sdp has to be modified instead create
a new description with the modified sdp.
dev1
virtuacoplenny il y a 8 ans
Parent
révision
c0c77d1e89
2 fichiers modifiés avec 94 ajouts et 45 suppressions
  1. 8
    8
      modules/RTC/LocalSdpMunger.js
  2. 86
    37
      modules/RTC/TraceablePeerConnection.js

+ 8
- 8
modules/RTC/LocalSdpMunger.js Voir le fichier

@@ -169,19 +169,19 @@ export default class LocalSdpMunger {
169 169
      * description.
170 170
      */
171 171
     maybeMungeLocalSdp(desc) {
172
-        // Nothing to be done in early stage when localDescription
173
-        // is not available yet
174
-        if (!desc || !desc.sdp) {
175
-            return;
172
+        if (!desc || !(desc instanceof RTCSessionDescription)) {
173
+            throw new Error('Incorrect type, expected RTCSessionDescription');
176 174
         }
177 175
 
178 176
         const transformer = new SdpTransformWrap(desc.sdp);
179 177
 
180 178
         if (this._addMutedLocalVideoTracksToSDP(transformer)) {
181
-            // Write
182
-            desc.sdp = transformer.toRawSDP();
183
-
184
-            // logger.info("Post TRANSFORM: ", desc.sdp);
179
+            return new RTCSessionDescription({
180
+                type: desc.type,
181
+                sdp: transformer.toRawSDP()
182
+            });
185 183
         }
184
+
185
+        return desc;
186 186
     }
187 187
 }

+ 86
- 37
modules/RTC/TraceablePeerConnection.js Voir le fichier

@@ -1075,26 +1075,35 @@ const normalizePlanB = function(desc) {
1075 1075
  * @param {Object} localDescription the SDP object as defined by WebRTC.
1076 1076
  */
1077 1077
 const enforceSendRecv = function(localDescription) {
1078
-    if (localDescription && localDescription.sdp) {
1079
-        const transformer = new SdpTransformWrap(localDescription.sdp);
1080
-        const audioMedia = transformer.selectMedia('audio');
1081
-        let changed = false;
1082
-
1083
-        if (audioMedia && audioMedia.direction !== 'sendrecv') {
1084
-            audioMedia.direction = 'sendrecv';
1085
-            changed = true;
1086
-        }
1087
-        const videoMedia = transformer.selectMedia('video');
1078
+    if (!localDescription
1079
+        || !(localDescription instanceof RTCSessionDescription)) {
1080
+        throw new Error('Incorrect type, expected RTCSessionDescription');
1081
+    }
1088 1082
 
1089
-        if (videoMedia && videoMedia.direction !== 'sendrecv') {
1090
-            videoMedia.direction = 'sendrecv';
1091
-            changed = true;
1092
-        }
1083
+    const transformer = new SdpTransformWrap(localDescription.sdp);
1084
+    const audioMedia = transformer.selectMedia('audio');
1085
+    let changed = false;
1093 1086
 
1094
-        if (changed) {
1095
-            localDescription.sdp = transformer.toRawSDP();
1096
-        }
1087
+    if (audioMedia && audioMedia.direction !== 'sendrecv') {
1088
+        audioMedia.direction = 'sendrecv';
1089
+        changed = true;
1097 1090
     }
1091
+
1092
+    const videoMedia = transformer.selectMedia('video');
1093
+
1094
+    if (videoMedia && videoMedia.direction !== 'sendrecv') {
1095
+        videoMedia.direction = 'sendrecv';
1096
+        changed = true;
1097
+    }
1098
+
1099
+    if (changed) {
1100
+        return new RTCSessionDescription({
1101
+            type: localDescription.type,
1102
+            sdp: transformer.toRawSDP()
1103
+        });
1104
+    }
1105
+
1106
+    return localDescription;
1098 1107
 };
1099 1108
 
1100 1109
 /**
@@ -1146,9 +1155,11 @@ TraceablePeerConnection.prototype._injectSsrcGroupForUnifiedSimulcast
1146 1155
                 ssrcs: ssrcs.join(' ')
1147 1156
             });
1148 1157
         }
1149
-        desc.sdp = transform.write(sdp);
1150 1158
 
1151
-        return desc;
1159
+        return new RTCSessionDescription({
1160
+            type: desc.type,
1161
+            sdp: transform.write(sdp)
1162
+        });
1152 1163
     };
1153 1164
 
1154 1165
 /* eslint-disable-next-line vars-on-top */
@@ -1169,13 +1180,14 @@ const getters = {
1169 1180
             desc = this.interop.toPlanB(desc);
1170 1181
             this.trace('getLocalDescription::postTransform (Plan B)',
1171 1182
                 dumpSDP(desc));
1183
+
1172 1184
             desc = this._injectSsrcGroupForUnifiedSimulcast(desc);
1173 1185
             this.trace('getLocalDescription::postTransform (inject ssrc group)',
1174 1186
                 dumpSDP(desc));
1175 1187
         }
1176 1188
 
1177 1189
         if (RTCBrowserType.doesVideoMuteByStreamRemove()) {
1178
-            this.localSdpMunger.maybeMungeLocalSdp(desc);
1190
+            desc = this.localSdpMunger.maybeMungeLocalSdp(desc);
1179 1191
             logger.debug(
1180 1192
                 'getLocalDescription::postTransform (munge local SDP)', desc);
1181 1193
         }
@@ -1188,7 +1200,7 @@ const getters = {
1188 1200
         // Note that the description we set in chrome does have the accurate
1189 1201
         // direction (e.g. 'recvonly'), since that is technically what is
1190 1202
         // happening (check setLocalDescription impl).
1191
-        enforceSendRecv(desc);
1203
+        desc = enforceSendRecv(desc);
1192 1204
 
1193 1205
         return desc || {};
1194 1206
     },
@@ -1499,7 +1511,7 @@ TraceablePeerConnection.prototype._ensureSimulcastGroupIsLast = function(
1499 1511
     if (simStartIndex === -1
1500 1512
         || otherStartIndex === -1
1501 1513
         || otherStartIndex === simStartIndex) {
1502
-        return;
1514
+        return localSdp;
1503 1515
     }
1504 1516
 
1505 1517
     const simEndIndex = sdpStr.indexOf('\r\n', simStartIndex);
@@ -1514,7 +1526,10 @@ TraceablePeerConnection.prototype._ensureSimulcastGroupIsLast = function(
1514 1526
 
1515 1527
     sdpStr = `${sdpHead}\r\n${simStrTrimmed}${sdpTail}`;
1516 1528
 
1517
-    localSdp.sdp = sdpStr;
1529
+    return new RTCSessionDescription({
1530
+        type: localSdp.type,
1531
+        sdp: sdpStr
1532
+    });
1518 1533
 };
1519 1534
 
1520 1535
 /**
@@ -1562,8 +1577,13 @@ TraceablePeerConnection.prototype._adjustLocalMediaDirection = function(
1562 1577
     }
1563 1578
 
1564 1579
     if (modifiedDirection) {
1565
-        localDescription.sdp = transformer.toRawSDP();
1580
+        return new RTCSessionDescription({
1581
+            type: localDescription.type,
1582
+            sdp: transformer.toRawSDP()
1583
+        });
1566 1584
     }
1585
+
1586
+    return localDescription;
1567 1587
 };
1568 1588
 
1569 1589
 TraceablePeerConnection.prototype.setLocalDescription = function(
@@ -1584,15 +1604,18 @@ TraceablePeerConnection.prototype.setLocalDescription = function(
1584 1604
             SDPUtil.preferVideoCodec(videoMLine, 'h264');
1585 1605
         }
1586 1606
 
1587
-        localSdp.sdp = transform.write(parsedSdp);
1607
+        localSdp = new RTCSessionDescription({
1608
+            type: localSdp.type,
1609
+            sdp: transform.write(parsedSdp)
1610
+        });
1588 1611
 
1589 1612
         this.trace('setLocalDescription::postTransform (H264)',
1590 1613
             dumpSDP(localSdp));
1591 1614
     }
1592 1615
 
1593
-    this._adjustLocalMediaDirection(localSdp);
1616
+    localSdp = this._adjustLocalMediaDirection(localSdp);
1594 1617
 
1595
-    this._ensureSimulcastGroupIsLast(localSdp);
1618
+    localSdp = this._ensureSimulcastGroupIsLast(localSdp);
1596 1619
 
1597 1620
     // if we're using unified plan, transform to it first.
1598 1621
     if (RTCBrowserType.usesUnifiedPlan()) {
@@ -1680,9 +1703,11 @@ TraceablePeerConnection.prototype._insertUnifiedPlanSimulcastReceive
1680 1703
         video.simulcast_03 = {
1681 1704
             value: `recv rid=${SIM_LAYER_RIDS.join(';')}`
1682 1705
         };
1683
-        desc.sdp = transform.write(sdp);
1684 1706
 
1685
-        return desc;
1707
+        return new RTCSessionDescription({
1708
+            type: desc.type,
1709
+            sdp: transform.write(sdp)
1710
+        });
1686 1711
     };
1687 1712
 
1688 1713
 TraceablePeerConnection.prototype.setRemoteDescription = function(
@@ -1703,12 +1728,22 @@ TraceablePeerConnection.prototype.setRemoteDescription = function(
1703 1728
         const videoMLine = parsedSdp.media.find(m => m.type === 'video');
1704 1729
 
1705 1730
         SDPUtil.preferVideoCodec(videoMLine, 'h264');
1706
-        description.sdp = transform.write(parsedSdp);
1731
+
1732
+        // eslint-disable-next-line no-param-reassign
1733
+        description = new RTCSessionDescription({
1734
+            type: description.type,
1735
+            sdp: transform.write(parsedSdp)
1736
+        });
1707 1737
     }
1708 1738
 
1709 1739
     // If the browser uses unified plan, transform to it first
1710 1740
     if (RTCBrowserType.usesUnifiedPlan()) {
1711
-        description.sdp = this.rtxModifier.stripRtx(description.sdp);
1741
+        // eslint-disable-next-line no-param-reassign
1742
+        description = new RTCSessionDescription({
1743
+            type: description.type,
1744
+            sdp: this.rtxModifier.stripRtx(description.sdp)
1745
+        });
1746
+
1712 1747
         this.trace(
1713 1748
             'setRemoteDescription::postTransform (stripRtx)',
1714 1749
             dumpSDP(description));
@@ -1976,9 +2011,14 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
1976 2011
                     && !this.sdpConsistency.hasPrimarySsrcCached()) {
1977 2012
                     this.generateRecvonlySsrc();
1978 2013
                 }
1979
-                resultSdp.sdp
1980
-                    = this.sdpConsistency.makeVideoPrimarySsrcsConsistent(
1981
-                        resultSdp.sdp);
2014
+
2015
+                // eslint-disable-next-line no-param-reassign
2016
+                resultSdp = new RTCSessionDescription({
2017
+                    type: resultSdp.type,
2018
+                    sdp: this.sdpConsistency.makeVideoPrimarySsrcsConsistent(
2019
+                        resultSdp.sdp)
2020
+                });
2021
+
1982 2022
                 this.trace(
1983 2023
                     `create${logName}OnSuccess::postTransform `
1984 2024
                          + '(make primary audio/video ssrcs consistent)',
@@ -1997,8 +2037,12 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
1997 2037
             }
1998 2038
 
1999 2039
             if (!this.options.disableRtx && RTCBrowserType.supportsRtx()) {
2000
-                resultSdp.sdp
2001
-                    = this.rtxModifier.modifyRtxSsrcs(resultSdp.sdp);
2040
+                // eslint-disable-next-line no-param-reassign
2041
+                resultSdp = new RTCSessionDescription({
2042
+                    type: resultSdp.type,
2043
+                    sdp: this.rtxModifier.modifyRtxSsrcs(resultSdp.sdp)
2044
+                });
2045
+
2002 2046
                 this.trace(
2003 2047
                     `create${logName}`
2004 2048
                          + 'OnSuccess::postTransform (rtx modifier)',
@@ -2013,7 +2057,12 @@ TraceablePeerConnection.prototype._createOfferOrAnswer = function(
2013 2057
                 const localDescription = new SDP(resultSdp.sdp);
2014 2058
 
2015 2059
                 _fixAnswerRFC4145Setup(remoteDescription, localDescription);
2016
-                resultSdp.sdp = localDescription.raw;
2060
+
2061
+                // eslint-disable-next-line no-param-reassign
2062
+                resultSdp = new RTCSessionDescription({
2063
+                    type: resultSdp.type,
2064
+                    sdp: localDescription.raw
2065
+                });
2017 2066
             }
2018 2067
 
2019 2068
             const ssrcMap = extractSSRCMap(resultSdp);

Chargement…
Annuler
Enregistrer