MCPcopy Create free account
hub / github.com/GRVYDEV/Project-Lightspeed / App

Function App

frontend/src/App.js:32–115  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

30};
31
32const App = () => {
33 const [state, dispatch] = useReducer(appReducer, initialState);
34 const { pc } = useRTC();
35 const { socket } = useSocket();
36
37 pc.ontrack = (event) => {
38 const { track } = event;
39 dispatch({ type: "track", track: track });
40 };
41
42 pc.onicecandidate = (e) => {
43 const { candidate } = e;
44 if (candidate) {
45 console.log("Candidate success");
46 socket.send(
47 JSON.stringify({
48 event: "candidate",
49 data: e.candidate,
50 })
51 );
52 }
53 };
54
55 if (socket) {
56 socket.onmessage = async (event) => {
57 const msg = JSON.parse(event.data);
58
59 if (!msg) {
60 console.log("Failed to parse msg");
61 return;
62 }
63
64 const offerCandidate = msg.data;
65
66 if (!offerCandidate) {
67 console.log("Failed to parse offer msg data");
68 return;
69 }
70
71 switch (msg.event) {
72 case "offer":
73 console.log("Offer");
74 pc.setRemoteDescription(offerCandidate);
75
76 try {
77 const answer = await pc.createAnswer();
78 pc.setLocalDescription(answer);
79 socket.send(
80 JSON.stringify({
81 event: "answer",
82 data: answer,
83 })
84 );
85 } catch (e) {
86 console.error(e.message);
87 }
88
89 return;

Callers

nothing calls this directly

Calls 2

useRTCFunction · 0.90
useSocketFunction · 0.90

Tested by

no test coverage detected