diff --git a/net/server/internal/api_addCall.go b/net/server/internal/api_addCall.go index 597bde1f..db660690 100644 --- a/net/server/internal/api_addCall.go +++ b/net/server/internal/api_addCall.go @@ -56,7 +56,7 @@ func AddCall(w http.ResponseWriter, r *http.Request) { // allocate bridge callerToken := hex.EncodeToString(callerBin); calleeToken := hex.EncodeToString(calleeBin); - bridgeRelay.AddBridge(account.ID, callId, callerToken, calleeToken); + bridgeRelay.AddBridge(account.ID, callId, cardId, callerToken, calleeToken); // create response call := Call{ diff --git a/net/server/internal/api_endCall.go b/net/server/internal/api_endCall.go deleted file mode 100644 index e17e8aa0..00000000 --- a/net/server/internal/api_endCall.go +++ /dev/null @@ -1,9 +0,0 @@ -package databag - -import ( - "net/http" -) - -//EndCall termines an active call -func EndCall(w http.ResponseWriter, r *http.Request) { -} diff --git a/net/server/internal/bridge.go b/net/server/internal/bridge.go index cada50fe..e08e1f8e 100644 --- a/net/server/internal/bridge.go +++ b/net/server/internal/bridge.go @@ -31,12 +31,13 @@ type BridgeRelay struct { 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() defer s.sync.Unlock() bridge := &Bridge{ accountId: accountId, callId: callId, + cardId: cardId, expires: time.Now().Unix() + (BridgeKeepAlive * 3), closed: false, callerToken: callerToken, diff --git a/net/server/internal/routers.go b/net/server/internal/routers.go index fb8360c0..8f855560 100644 --- a/net/server/internal/routers.go +++ b/net/server/internal/routers.go @@ -815,7 +815,7 @@ var endpoints = routes{ "EndCall", strings.ToUpper("Delete"), "/talk/calls/{callId}", - EndCall, + RemoveCall, }, route{ diff --git a/net/web/src/context/useRingContext.hook.js b/net/web/src/context/useRingContext.hook.js index 24a06da7..b5f0a073 100644 --- a/net/web/src/context/useRingContext.hook.js +++ b/net/web/src/context/useRingContext.hook.js @@ -64,13 +64,19 @@ export function useRingContext() { updateState({ ringing: ringing.current }); } }, - decline: (cardId, callId) => { + 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) => { @@ -121,7 +127,10 @@ export function useRingContext() { // handle messages [impolite] try { const signal = JSON.parse(ev.data); - if (signal.description) { + if (signal.status === 'closed') { + ws.current.close(); + } + else if (signal.description) { stream.current = null; if (signal.description.type === 'offer' && pc.current.signalingState !== 'stable') { return; //rudely ignore @@ -262,12 +271,14 @@ export function useRingContext() { } }; + videoTrack.current = false; + audioTrack.current = false; accessVideo.current = false; const stream = await navigator.mediaDevices.getUserMedia({ video: false, audio: true, }); - updateState({ audio: true, localStream: stream }); + updateState({ video: false, audio: true, localStream: stream }); for (const track of stream.getTracks()) { if (track.kind === 'audio') { audioTrack.current = track; @@ -363,7 +374,9 @@ export function useRingContext() { updateState({ video: true }); }, disableVideo: async () => { - videoTrack.current.enabled = false; + if (videoTrack.current) { + videoTrack.current.enabled = false; + } updateState({ video: false }); }, enableAudio: async () => { diff --git a/net/web/src/session/useSession.hook.js b/net/web/src/session/useSession.hook.js index 821006fb..c9a0d7b0 100644 --- a/net/web/src/session/useSession.hook.js +++ b/net/web/src/session/useSession.hook.js @@ -150,15 +150,16 @@ export function useSession() { ignore: (call) => { ring.actions.ignore(call.cardId, call.callId); }, - decline: (call) => { - ring.actions.decline(call.cardId, call.callId); + decline: async (call) => { + 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; - ring.actions.accept(cardId, callId, contactNode, contactToken, calleeToken); + await ring.actions.accept(cardId, callId, contactNode, contactToken, calleeToken); }, end: async () => { - ring.actions.end(); + await ring.actions.end(); }, enableVideo: async () => { await ring.actions.enableVideo();