borogove
created pr with
borogove/media-ufrag-look-everywhere.1
cmds
checkout latest patchset:
ssh pr.pico.sh pull borogove:media-ufrag-look-everywhere | git am -3checkout specific patchset revision:
ssh pr.pico.sh pull borogove:media-ufrag-look-everywhere [rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh borogove:media-ufrag-look-everywhereadd comment to patch request:
ssh pr.pico.sh comment borogove:media-ufrag-look-everywhere "lgtm!"
Patchset
borogove/media-ufrag-look-everywhere.1
Find media and ufrag elsewhere if needed
Stephen Paul Weber
2026-12-01T21:53:34ZSome clients ony set ufrag in the SDP or media by index and not id. This allows us to still find it.
Semantic diff summary
0 added,
0 modified,
0 signature changed,
0 removed
across 0 analyzed files
(1 file skipped: unsupported file type)
+39
-5
borogove/calls/Session.hx
#
| ... | ... | @@ -22,6 +22,13 @@ enum abstract CallStatus(Int) { | |
| 22 | 22 | var Failed; | |
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | + | typedef OutboundIceCandidate = { | |
| 26 | + | candidate: String, | |
| 27 | + | sdpMid: Null<String>, | |
| 28 | + | ?sdpMLineIndex: Null<Int>, | |
| 29 | + | ?usernameFragment: Null<String> | |
| 30 | + | }; | |
| 31 | + | ||
| 25 | 32 | #if cpp | |
| 26 | 33 | @:build(HaxeCBridge.expose()) | |
| 27 | 34 | @:build(HaxeSwiftBridge.expose()) |
| ... | ... | @@ -345,7 +352,7 @@ class InitiatedSession implements Session { | |
| 345 | 352 | private var pc: PeerConnection = null; | |
| 346 | 353 | private var peerDtlsSetup: String = "actpass"; | |
| 347 | 354 | private final queuedInboundTransportInfo: Array<Stanza> = []; | |
| 348 | - | private final queuedOutboundCandidate: Array<{ candidate: String, sdpMid: String, usernameFragment: String }> = []; | |
| 355 | + | private final queuedOutboundCandidate: Array<OutboundIceCandidate> = []; | |
| 349 | 356 | private var accepted: Bool = false; | |
| 350 | 357 | private var afterMedia: Null<()->Void> = null; | |
| 351 | 358 | private final initiator: Bool; |
| ... | ... | @@ -563,7 +570,7 @@ class InitiatedSession implements Session { | |
| 563 | 570 | return transceiver.sender.dtmf; | |
| 564 | 571 | } | |
| 565 | 572 | ||
| 566 | - | private function sendIceCandidate(candidate: { candidate: String, sdpMid: String, usernameFragment: String }) { | |
| 573 | + | private function sendIceCandidate(candidate: Null<OutboundIceCandidate>) { | |
| 567 | 574 | if (candidate == null || candidate.candidate == "") { // All candidates received now | |
| 568 | 575 | if (candidatesDone != null) candidatesDone(); | |
| 569 | 576 | return; |
| ... | ... | @@ -573,8 +580,18 @@ class InitiatedSession implements Session { | |
| 573 | 580 | queuedOutboundCandidate.push(candidate); | |
| 574 | 581 | return; | |
| 575 | 582 | } | |
| 576 | - | final media = localDescription.media.find((media) -> media.mid == candidate.sdpMid); | |
| 577 | - | if (media == null) throw "Unknown media: " + candidate.sdpMid; | |
| 583 | + | final media = resolveCandidateMedia(candidate); | |
| 584 | + | if (media == null) return; | |
| 585 | + | ||
| 586 | + | var ufrag = candidate.usernameFragment; | |
| 587 | + | if (ufrag == null || ufrag == "") { | |
| 588 | + | ufrag = media.attributes.find((attr) -> attr.key == "ice-ufrag")?.value; | |
| 589 | + | } | |
| 590 | + | if (ufrag == null || ufrag == "") { | |
| 591 | + | ufrag = localDescription.attributes.find((attr) -> attr.key == "ice-ufrag")?.value; | |
| 592 | + | } | |
| 593 | + | if (ufrag == null || ufrag == "") throw "No usernameFragment anywhere"; | |
| 594 | + | ||
| 578 | 595 | final transportInfo = new TransportInfo( | |
| 579 | 596 | new Media( | |
| 580 | 597 | media.mid, |
| ... | ... | @@ -584,7 +601,7 @@ class InitiatedSession implements Session { | |
| 584 | 601 | media.protocol, | |
| 585 | 602 | [ | |
| 586 | 603 | Attribute.parse(candidate.candidate), | |
| 587 | - | new Attribute("ice-ufrag", candidate.usernameFragment), | |
| 604 | + | new Attribute("ice-ufrag", ufrag), | |
| 588 | 605 | media.attributes.find((attr) -> attr.key == "ice-pwd") ?? | |
| 589 | 606 | localDescription.attributes.find((attr) -> attr.key == "ice-pwd") | |
| 590 | 607 | ], |
| ... | ... | @@ -597,6 +614,23 @@ class InitiatedSession implements Session { | |
| 597 | 614 | client.sendStanza(transportInfo); | |
| 598 | 615 | } | |
| 599 | 616 | ||
| 617 | + | private function resolveCandidateMedia(candidate: OutboundIceCandidate): Null<Media> { | |
| 618 | + | if (localDescription?.media == null) return null; | |
| 619 | + | ||
| 620 | + | final byMid = localDescription.media.find((media) -> media.mid == candidate.sdpMid); | |
| 621 | + | if (byMid != null) return byMid; | |
| 622 | + | ||
| 623 | + | final index = candidate.sdpMLineIndex; | |
| 624 | + | final media = if (index != null && index >= 0 && index < localDescription.media.length) { | |
| 625 | + | localDescription.media[index]; | |
| 626 | + | } else if (localDescription.media.length == 1) { | |
| 627 | + | localDescription.media[0]; | |
| 628 | + | } else { | |
| 629 | + | null; | |
| 630 | + | }; | |
| 631 | + | return media; | |
| 632 | + | } | |
| 633 | + | ||
| 600 | 634 | public function supplyMedia(streams: Array<MediaStream>): Void { | |
| 601 | 635 | setupPeerConnection(() -> { | |
| 602 | 636 | for (stream in streams) { |