From bb34b7b0fa14f314a8586086427862cdc72caaca Mon Sep 17 00:00:00 2001 From: Cody Larkin Date: Tue, 31 Mar 2026 18:59:25 -0400 Subject: [PATCH] Added basic code as channelCallJoin in index.js included more TODOs in function --- RelayClient/Resources/Raw/wwwroot/index.js | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/RelayClient/Resources/Raw/wwwroot/index.js b/RelayClient/Resources/Raw/wwwroot/index.js index 58fe2fd..70ce3f3 100644 --- a/RelayClient/Resources/Raw/wwwroot/index.js +++ b/RelayClient/Resources/Raw/wwwroot/index.js @@ -197,6 +197,55 @@ async function joinChannelCall() { } } +async function channelCallJoin() +{ + const activeCall = true; //TODO: Read Surreal DB with channel id for active call + + if (activeCall) + { + const offer = roomSnapshot.data().offer; //TODO: Replace with active call offer from DB using the active ID for current channel + await peerConnection.setRemoteDescription(offer); + const answer = await peerConnection.createAnswer(); + await peerConnection.setLocalDescription(answer); + + const roomAnswer = { + answer: { + type: answer.type, + sdp: answer.sdp + } + } + await roomRef.update(roomAnswer); //TODO: Update offer in SurrealDB to include answer + } + else + { + const offer = await peerConnection.createOffer(); + await peerConnection.setLocalDescription(offer); + + const roomOffer = { + offer: { + type: offer.type, + sdp: offer.sdp + } + } + + const roomRef = "id"; //TODO: Add offer to SurrealDB on server + const roomId = roomRef.id; + //TODO: Write roomId to surreal DB with channel id as active call + + //TODO: Add callback function for when call is answered to replace following code block + roomRef.onSnapshot(async snapshot => { + console.log('Got updated room:', snapshot.data()); + const data = snapshot.data(); + if (!peerConnection.currentRemoteDescription && data.answer) { + console.log('Set remote description: ', data.answer); + const answer = new RTCSessionDescription(data.answer) + await peerConnection.setRemoteDescription(answer); + } + }); + } + +} + async function handleRtcSignal(rawJson) { try { const msg = typeof rawJson === "string" ? JSON.parse(rawJson) : rawJson;