fixing call exit handling

This commit is contained in:
Roland Osborne 2023-03-27 22:40:24 -07:00
parent 8376f75f9c
commit 09e0ffbe34
6 changed files with 27 additions and 21 deletions

View File

@ -56,7 +56,7 @@ func AddCall(w http.ResponseWriter, r *http.Request) {
// allocate bridge // allocate bridge
callerToken := hex.EncodeToString(callerBin); callerToken := hex.EncodeToString(callerBin);
calleeToken := hex.EncodeToString(calleeBin); calleeToken := hex.EncodeToString(calleeBin);
bridgeRelay.AddBridge(account.ID, callId, callerToken, calleeToken); bridgeRelay.AddBridge(account.ID, callId, cardId, callerToken, calleeToken);
// create response // create response
call := Call{ call := Call{

View File

@ -1,9 +0,0 @@
package databag
import (
"net/http"
)
//EndCall termines an active call
func EndCall(w http.ResponseWriter, r *http.Request) {
}

View File

@ -31,12 +31,13 @@ type BridgeRelay struct {
bridges []*Bridge bridges []*Bridge
} }
func (s *BridgeRelay) AddBridge(accountId uint, callId string, callerToken string, calleeToken string) { func (s *BridgeRelay) AddBridge(accountId uint, callId string, cardId string, callerToken string, calleeToken string) {
s.sync.Lock() s.sync.Lock()
defer s.sync.Unlock() defer s.sync.Unlock()
bridge := &Bridge{ bridge := &Bridge{
accountId: accountId, accountId: accountId,
callId: callId, callId: callId,
cardId: cardId,
expires: time.Now().Unix() + (BridgeKeepAlive * 3), expires: time.Now().Unix() + (BridgeKeepAlive * 3),
closed: false, closed: false,
callerToken: callerToken, callerToken: callerToken,

View File

@ -815,7 +815,7 @@ var endpoints = routes{
"EndCall", "EndCall",
strings.ToUpper("Delete"), strings.ToUpper("Delete"),
"/talk/calls/{callId}", "/talk/calls/{callId}",
EndCall, RemoveCall,
}, },
route{ route{

View File

@ -64,13 +64,19 @@ export function useRingContext() {
updateState({ ringing: ringing.current }); updateState({ ringing: ringing.current });
} }
}, },
decline: (cardId, callId) => { decline: async (cardId, contactNode, contactToken, callId) => {
const key = `${cardId}:${callId}` const key = `${cardId}:${callId}`
const call = ringing.current.get(key); const call = ringing.current.get(key);
if (call) { if (call) {
call.status = 'declined' call.status = 'declined'
ringing.current.set(key, call); ringing.current.set(key, call);
updateState({ ringing: ringing.current }); updateState({ ringing: ringing.current });
try {
await removeContactCall(contactNode, contactToken, callId);
}
catch (err) {
console.log(err);
}
} }
}, },
accept: async (cardId, callId, contactNode, contactToken, calleeToken) => { accept: async (cardId, callId, contactNode, contactToken, calleeToken) => {
@ -121,7 +127,10 @@ export function useRingContext() {
// handle messages [impolite] // handle messages [impolite]
try { try {
const signal = JSON.parse(ev.data); const signal = JSON.parse(ev.data);
if (signal.description) { if (signal.status === 'closed') {
ws.current.close();
}
else if (signal.description) {
stream.current = null; stream.current = null;
if (signal.description.type === 'offer' && pc.current.signalingState !== 'stable') { if (signal.description.type === 'offer' && pc.current.signalingState !== 'stable') {
return; //rudely ignore return; //rudely ignore
@ -262,12 +271,14 @@ export function useRingContext() {
} }
}; };
videoTrack.current = false;
audioTrack.current = false;
accessVideo.current = false; accessVideo.current = false;
const stream = await navigator.mediaDevices.getUserMedia({ const stream = await navigator.mediaDevices.getUserMedia({
video: false, video: false,
audio: true, audio: true,
}); });
updateState({ audio: true, localStream: stream }); updateState({ video: false, audio: true, localStream: stream });
for (const track of stream.getTracks()) { for (const track of stream.getTracks()) {
if (track.kind === 'audio') { if (track.kind === 'audio') {
audioTrack.current = track; audioTrack.current = track;
@ -363,7 +374,9 @@ export function useRingContext() {
updateState({ video: true }); updateState({ video: true });
}, },
disableVideo: async () => { disableVideo: async () => {
videoTrack.current.enabled = false; if (videoTrack.current) {
videoTrack.current.enabled = false;
}
updateState({ video: false }); updateState({ video: false });
}, },
enableAudio: async () => { enableAudio: async () => {

View File

@ -150,15 +150,16 @@ export function useSession() {
ignore: (call) => { ignore: (call) => {
ring.actions.ignore(call.cardId, call.callId); ring.actions.ignore(call.cardId, call.callId);
}, },
decline: (call) => { decline: async (call) => {
ring.actions.decline(call.cardId, call.callId); const { cardId, contactNode, contactToken, callId } = call;
await ring.actions.decline(cardId, contactNode, contactToken, callId);
}, },
accept: (call) => { accept: async (call) => {
const { cardId, callId, contactNode, contactToken, calleeToken } = call; const { cardId, callId, contactNode, contactToken, calleeToken } = call;
ring.actions.accept(cardId, callId, contactNode, contactToken, calleeToken); await ring.actions.accept(cardId, callId, contactNode, contactToken, calleeToken);
}, },
end: async () => { end: async () => {
ring.actions.end(); await ring.actions.end();
}, },
enableVideo: async () => { enableVideo: async () => {
await ring.actions.enableVideo(); await ring.actions.enableVideo();