Added basic code as channelCallJoin in index.js
included more TODOs in function
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user