mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
adding endpoints used for webrtc coordination
This commit is contained in:
parent
d6b642d6a2
commit
cd06333ccb
8
app/mobile/src/api/addCall.js
Normal file
8
app/mobile/src/api/addCall.js
Normal 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();
|
||||
}
|
||||
|
7
app/mobile/src/api/addContactRing.js
Normal file
7
app/mobile/src/api/addContactRing.js
Normal 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);
|
||||
}
|
||||
|
7
app/mobile/src/api/keepCall.js
Normal file
7
app/mobile/src/api/keepCall.js
Normal 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);
|
||||
}
|
||||
|
7
app/mobile/src/api/removeCall.js
Normal file
7
app/mobile/src/api/removeCall.js
Normal 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)
|
||||
}
|
||||
|
6
app/mobile/src/api/removeContactCall.js
Normal file
6
app/mobile/src/api/removeContactCall.js
Normal 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);
|
||||
}
|
@ -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) => {
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user