Skip to content

Commit b10ef8d

Browse files
committed
Remove json double encoding in ws communication
1 parent e937aa9 commit b10ef8d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/App.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ const App = () => {
5656
socket.send(
5757
JSON.stringify({
5858
event: "candidate",
59-
data: JSON.stringify(e.candidate),
59+
data: e.candidate,
6060
})
6161
);
6262
}
6363
};
6464

6565
if (socket) {
6666
socket.onmessage = async (event) => {
67-
const msg = JSON.parse(event.data);
67+
const msg = event.data;
6868

6969
if (!msg) {
7070
console.log("Failed to parse msg");
7171
return;
7272
}
7373

74-
const offerCandidate = JSON.parse(msg.data);
74+
const offerCandidate = msg.data;
7575

7676
if (!offerCandidate) {
7777
console.log("Failed to parse offer msg data");
@@ -89,7 +89,7 @@ const App = () => {
8989
socket.send(
9090
JSON.stringify({
9191
event: "answer",
92-
data: JSON.stringify(answer),
92+
data: answer,
9393
})
9494
);
9595
} catch (e) {
@@ -104,7 +104,7 @@ const App = () => {
104104
case "info":
105105
dispatch({
106106
type: "info",
107-
viewers: JSON.parse(msg.data).no_connections,
107+
viewers: msg.data.no_connections,
108108
});
109109
}
110110
};

0 commit comments

Comments
 (0)