From b10ef8dee51e414422a14fb62c0af85406bf11e4 Mon Sep 17 00:00:00 2001 From: Thorsten Riess Date: Sat, 20 Feb 2021 14:08:38 +0100 Subject: [PATCH 1/2] Remove json double encoding in ws communication --- src/App.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/App.js b/src/App.js index a5819ba..42e2012 100644 --- a/src/App.js +++ b/src/App.js @@ -56,7 +56,7 @@ const App = () => { socket.send( JSON.stringify({ event: "candidate", - data: JSON.stringify(e.candidate), + data: e.candidate, }) ); } @@ -64,14 +64,14 @@ const App = () => { if (socket) { socket.onmessage = async (event) => { - const msg = JSON.parse(event.data); + const msg = event.data; if (!msg) { console.log("Failed to parse msg"); return; } - const offerCandidate = JSON.parse(msg.data); + const offerCandidate = msg.data; if (!offerCandidate) { console.log("Failed to parse offer msg data"); @@ -89,7 +89,7 @@ const App = () => { socket.send( JSON.stringify({ event: "answer", - data: JSON.stringify(answer), + data: answer, }) ); } catch (e) { @@ -104,7 +104,7 @@ const App = () => { case "info": dispatch({ type: "info", - viewers: JSON.parse(msg.data).no_connections, + viewers: msg.data.no_connections, }); } }; From dad04cd9efb9ff3405e5545e98b3ff075c813242 Mon Sep 17 00:00:00 2001 From: Thorsten Riess Date: Sat, 20 Feb 2021 17:23:00 +0100 Subject: [PATCH 2/2] Fix missing decode --- src/App.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 42e2012..92fa4e7 100644 --- a/src/App.js +++ b/src/App.js @@ -64,7 +64,7 @@ const App = () => { if (socket) { socket.onmessage = async (event) => { - const msg = event.data; + const msg = JSON.parse(event.data); if (!msg) { console.log("Failed to parse msg");