Last active
November 28, 2022 12:48
-
-
Save sky0014/6f3b387519d062b20f75fb2b43e52d77 to your computer and use it in GitHub Desktop.
transform sdp old & new format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Browser.firefox || this.options.isSDPOldFormat) { | |
try { | |
const obj = sdpTransform.parse(sdp); | |
// workaround: 火狐替换大于uint64的session_id(可能由老版本chrome或sdk发出) | |
obj.origin.sessionId = 1; | |
// workaround: 火狐datachannel新旧格式支持问题 | |
// workaround: 旧版本chrome同样不支持新的sdp格式,需要转换 | |
const isOld = !!obj.media[0].sctpmap; | |
if (this.options.isSDPOldFormat) { | |
if (!isOld) { | |
// 新格式转换为老格式 | |
obj.media[0].sctpmap = { | |
app: obj.media[0].payloads, | |
maxMessageSize: 1024, | |
sctpmapNumber: obj.media[0].sctpPort | |
}; | |
obj.media[0].payloads = `${obj.media[0].sctpPort}`; | |
delete obj.media[0].sctpPort; | |
} | |
// UDP/DTLS/SCTP旧版可能不支持,强制替换 | |
obj.media[0].protocol = "DTLS/SCTP"; | |
// 部分较新而无用的属性精简,某些旧版本浏览器可能无法解析 | |
// @ts-ignore | |
delete obj.extmapAllowMixed; | |
delete obj.msidSemantic; | |
delete obj.groups; | |
} | |
if (!this.options.isSDPOldFormat && isOld) { | |
// 老格式转换为新格式 | |
obj.media[0].sctpPort = +obj.media[0].sctpmap.sctpmapNumber; | |
obj.media[0].payloads = obj.media[0].sctpmap.app; | |
// 强制替换,否则火狐无法解析 | |
obj.media[0].protocol = "UDP/DTLS/SCTP"; | |
delete obj.media[0].sctpmap; | |
} | |
sdp = sdpTransform.write(obj); | |
} catch (e) { | |
this.reportLog(`sdp transform error: ${e}, sdp=${sdp}`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment