yarn format + project architecture image in readme

This commit is contained in:
Koper
2023-07-19 13:17:09 +07:00
parent 2b06ea74b3
commit 55e425f2b1
4 changed files with 212 additions and 226 deletions

View File

@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import Peer from "simple-peer";
const WebRTC_SERVER_URL = "http://127.0.0.1:1250/offer"
const WebRTC_SERVER_URL = "http://127.0.0.1:1250/offer";
const useWebRTC = (stream) => {
const [data, setData] = useState(null);
@@ -13,23 +13,26 @@ const useWebRTC = (stream) => {
// This is where you'd send the signal data to the server.
// The server would then send it back to other peers who would then
// use `peer.signal()` method to continue the connection negotiation.
if ('sdp' in data) {
if ("sdp" in data) {
fetch(WebRTC_SERVER_URL, {
body: JSON.stringify({
sdp: data.sdp,
type: data.type,
}),
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json",
},
method: 'POST'
}).then(function (response) {
return response.json();
}).then(function (answer) {
return peer.signal(answer);
}).catch(function (e) {
alert(e);
});
method: "POST",
})
.then(function (response) {
return response.json();
})
.then(function (answer) {
return peer.signal(answer);
})
.catch(function (e) {
alert(e);
});
}
});
@@ -39,7 +42,7 @@ const useWebRTC = (stream) => {
peer.on("data", (data) => {
// Received data from the server.
console.log(data.toString())
console.log(data.toString());
const serverData = JSON.parse(data.toString());
setData(serverData);
});