diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:50 +0000 |
commit | def92d1b8e9d373e2f6f27c366d578d97d8960c6 (patch) | |
tree | 2ef34b9ad8bb9a9220e05d60352558b15f513894 /dom/media/PeerConnection.sys.mjs | |
parent | Adding debian version 125.0.3-1. (diff) | |
download | firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.tar.xz firefox-def92d1b8e9d373e2f6f27c366d578d97d8960c6.zip |
Merging upstream version 126.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/PeerConnection.sys.mjs')
-rw-r--r-- | dom/media/PeerConnection.sys.mjs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/dom/media/PeerConnection.sys.mjs b/dom/media/PeerConnection.sys.mjs index 00b4023c2f..a775a92d99 100644 --- a/dom/media/PeerConnection.sys.mjs +++ b/dom/media/PeerConnection.sys.mjs @@ -217,6 +217,51 @@ setupPrototype(GlobalPCList, { var _globalPCList = new GlobalPCList(); +// Parses grammar in RFC5245 section 15 and ICE TCP from RFC6544 section 4.5. +function parseCandidate(line) { + const match = line.match( + /^(a=)?candidate:([A-Za-z0-9+\/]{1,32}) (\d+) (UDP|TCP) (\d+) ([A-Za-z0-9.:-]+) (\d+) typ (host|srflx|prflx|relay)(?: raddr ([A-Za-z0-9.:-]+) rport (\d+))?(.*)$/i + ); + if (!match) { + return null; + } + const candidate = { + foundation: match[2], + componentId: parseInt(match[3], 10), + transport: match[4], + priority: parseInt(match[5], 10), + address: match[6], + port: parseInt(match[7], 10), + type: match[8], + relatedAddress: match[9], + relatedPort: match[10], + }; + if (candidate.componentId < 1 || candidate.componentId > 256) { + return null; + } + if (candidate.priority < 0 || candidate.priority > 4294967295) { + return null; + } + if (candidate.port < 0 || candidate.port > 65535) { + return null; + } + candidate.component = { 1: "rtp", 2: "rtcp" }[candidate.componentId] || null; + candidate.protocol = + { udp: "udp", tcp: "tcp" }[candidate.transport.toLowerCase()] || null; + + const tcpTypeMatch = match[11].match(/tcptype (\S+)/i); + if (tcpTypeMatch) { + candidate.tcpType = tcpTypeMatch[1]; + if ( + candidate.protocol != "tcp" || + !["active", "passive", "so"].includes(candidate.tcpType) + ) { + return null; + } + } + return candidate; +} + export class RTCIceCandidate { init(win) { this._win = win; @@ -229,6 +274,20 @@ export class RTCIceCandidate { ); } Object.assign(this, dict); + const candidate = parseCandidate(this.candidate); + if (!candidate) { + return; + } + Object.assign(this, candidate); + } + + toJSON() { + return { + candidate: this.candidate, + sdpMid: this.sdpMid, + sdpMLineIndex: this.sdpMLineIndex, + usernameFragment: this.usernameFragment, + }; } } |