From 43970061866a54b3d63526a093e413503f6f1f80 Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Fri, 24 Feb 2023 17:42:38 -0800 Subject: [PATCH] Stringify WebRTC candidate/sdp payloads --- pkg/messages.go | 4 ++-- web/static/js/BareRTC.js | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/pkg/messages.go b/pkg/messages.go index 147a270..4d10b65 100644 --- a/pkg/messages.go +++ b/pkg/messages.go @@ -20,8 +20,8 @@ type Message struct { OpenSecret string `json:"openSecret,omitempty"` // Parameters sent on WebRTC signaling messages. - Candidate map[string]interface{} `json:"candidate,omitempty"` // candidate - Description map[string]interface{} `json:"description,omitempty"` // sdp + Candidate string `json:"candidate,omitempty"` // candidate + Description string `json:"description,omitempty"` // sdp } const ( diff --git a/web/static/js/BareRTC.js b/web/static/js/BareRTC.js index 1ce919c..9ba6684 100644 --- a/web/static/js/BareRTC.js +++ b/web/static/js/BareRTC.js @@ -545,7 +545,7 @@ const app = Vue.createApp({ this.ws.conn.send(JSON.stringify({ action: "candidate", username: username, - candidate: event.candidate, + candidate: JSON.stringify(event.candidate), })); } }; @@ -609,7 +609,7 @@ const app = Vue.createApp({ this.ws.conn.send(JSON.stringify({ action: "sdp", username: username, - description: pc.localDescription, + description: JSON.stringify(pc.localDescription), })); }, console.error, @@ -624,10 +624,16 @@ const app = Vue.createApp({ } let pc = this.WebRTC.pc[msg.username].connecting; + // XX: WebRTC candidate/SDP messages JSON stringify their inner payload so that the + // Go back-end server won't re-order their json keys (Safari on Mac OS is very sensitive + // to the keys being re-ordered during the handshake, in ways that NO OTHER BROWSER cares + // about at all). Re-parse the JSON stringified object here. + let candidate = JSON.parse(msg.candidate); + // Add the new ICE candidate. pc.addIceCandidate( new RTCIceCandidate( - msg.candidate, + candidate, () => { }, console.error, ) @@ -638,7 +644,12 @@ const app = Vue.createApp({ return; } let pc = this.WebRTC.pc[msg.username].connecting; - let message = msg.description; + + // XX: WebRTC candidate/SDP messages JSON stringify their inner payload so that the + // Go back-end server won't re-order their json keys (Safari on Mac OS is very sensitive + // to the keys being re-ordered during the handshake, in ways that NO OTHER BROWSER cares + // about at all). Re-parse the JSON stringified object here. + let message = JSON.parse(msg.description); // Add the new ICE candidate. // this.ChatClient(`Received a Remote Description from ${msg.username}: ${JSON.stringify(msg.description)}.`);