adding endpoints used for webrtc coordination

This commit is contained in:
Roland Osborne 2023-03-28 16:35:57 -07:00
parent d6b642d6a2
commit cd06333ccb
6 changed files with 63 additions and 1 deletions

View File

@ -0,0 +1,8 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addCall(server, token, cardId) {
let call = await fetchWithTimeout(`https://${server}/talk/calls?agent=${token}`, { method: 'POST', body: JSON.stringify(cardId)} );
checkResponse(call);
return await call.json();
}

View File

@ -0,0 +1,7 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function addContactRing(server, token, call) {
let ring = await fetchWithTimeout(`https://${server}/talk/rings?contact=${token}`, { method: 'POST', body: JSON.stringify(call) });
checkResponse(ring);
}

View File

@ -0,0 +1,7 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function keepCall(server, token, callId) {
let call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?agent=${token}`, { method: 'PUT' });
checkResponse(call);
}

View File

@ -0,0 +1,7 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeCall(server, token, callId) {
let call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?agent=${token}` + param, { method: 'DELETE' });
checkResponse(call)
}

View File

@ -0,0 +1,6 @@
import { checkResponse, fetchWithTimeout } from './fetchUtil';
export async function removeContactCall(server, token, calllId) {
const call = await fetchWithTimeout(`https://${server}/talk/calls/${callId}?contact=${token}`, { method: 'DELETE' });
checkResponse(call);
}

View File

@ -62,11 +62,38 @@ export function useRingContext() {
access.current = null;
},
ring: (cardId, callId, calleeToken) => {
console.log("RING");
const key = `${cardId}:${callId}`
const call = ringing.current.get(key) || { cardId, calleeToken, callId }
call.expires = Date.now() + EXPIRE;
ringing.current.set(key, call);
updateState({ ringing: ringing.current });
setTimeout(() => {
updateState({ ringing: ringing.current });
}, EXPIRE);
},
ignore: (cardId, callId) => {
const key = `${cardId}:${callId}`
const call = ringing.current.get(key);
if (call) {
call.status = 'ignored'
ringing.current.set(key, call);
updateState({ ringing: ringing.current });
}
},
decline: async (cardId, contactNode, contactToken, callId) => {
const key = `${cardId}:${callId}`
const call = ringing.current.get(key);
if (call) {
call.status = 'declined'
ringing.current.set(key, call);
updateState({ ringing: ringing.current });
try {
await removeContactCall(contactNode, contactToken, callId);
}
catch (err) {
console.log(err);
}
}
},
accept: async (cardId, callId, contactNode, contactToken, calleeToken) => {
},