Skip to content

Commit

Permalink
Remove json double encoding in ws communication
Browse files Browse the repository at this point in the history
  • Loading branch information
tcriess committed Feb 20, 2021
1 parent e937aa9 commit b10ef8d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,22 @@ const App = () => {
socket.send(
JSON.stringify({
event: "candidate",
data: JSON.stringify(e.candidate),
data: e.candidate,
})
);
}
};

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");
Expand All @@ -89,7 +89,7 @@ const App = () => {
socket.send(
JSON.stringify({
event: "answer",
data: JSON.stringify(answer),
data: answer,
})
);
} catch (e) {
Expand All @@ -104,7 +104,7 @@ const App = () => {
case "info":
dispatch({
type: "info",
viewers: JSON.parse(msg.data).no_connections,
viewers: msg.data.no_connections,
});
}
};
Expand Down

0 comments on commit b10ef8d

Please sign in to comment.