From: Nirbheek Chauhan Date: Tue, 9 Feb 2021 08:57:31 +0000 (+0530) Subject: sendrecv/js: Handle OFFER_REQUEST as part of the switch X-Git-Tag: 1.19.3~487^2~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ea3c0e87660aa987881b4c7c3424fbf56e709c54;p=platform%2Fupstream%2Fgstreamer.git sendrecv/js: Handle OFFER_REQUEST as part of the switch This is clearer, and also stricter w.r.t. what sort of messages we accept. Part-of: --- diff --git a/webrtc/sendrecv/js/webrtc.js b/webrtc/sendrecv/js/webrtc.js index b646b88..6f893e7 100644 --- a/webrtc/sendrecv/js/webrtc.js +++ b/webrtc/sendrecv/js/webrtc.js @@ -130,40 +130,38 @@ function onServerMessage(event) { if (!peer_connection) createCall(null).then (generateOffer); return; + case "OFFER_REQUEST": + // The peer wants us to set up and then send an offer + if (!peer_connection) + createCall(null).then (generateOffer); + return; default: if (event.data.startsWith("ERROR")) { handleIncomingError(event.data); return; } - if (event.data.startsWith("OFFER_REQUEST")) { - // The peer wants us to set up and then send an offer - if (!peer_connection) - createCall(null).then (generateOffer); - } - else { - // Handle incoming JSON SDP and ICE messages - try { - msg = JSON.parse(event.data); - } catch (e) { - if (e instanceof SyntaxError) { - handleIncomingError("Error parsing incoming JSON: " + event.data); - } else { - handleIncomingError("Unknown error parsing response: " + event.data); - } - return; - } - - // Incoming JSON signals the beginning of a call - if (!peer_connection) - createCall(msg); - - if (msg.sdp != null) { - onIncomingSDP(msg.sdp); - } else if (msg.ice != null) { - onIncomingICE(msg.ice); + // Handle incoming JSON SDP and ICE messages + try { + msg = JSON.parse(event.data); + } catch (e) { + if (e instanceof SyntaxError) { + handleIncomingError("Error parsing incoming JSON: " + event.data); } else { - handleIncomingError("Unknown incoming JSON: " + msg); + handleIncomingError("Unknown error parsing response: " + event.data); } + return; + } + + // Incoming JSON signals the beginning of a call + if (!peer_connection) + createCall(msg); + + if (msg.sdp != null) { + onIncomingSDP(msg.sdp); + } else if (msg.ice != null) { + onIncomingICE(msg.ice); + } else { + handleIncomingError("Unknown incoming JSON: " + msg); } } }