mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
implemented remainder of endpoints for signal bridging
This commit is contained in:
parent
d2c7dcd06a
commit
86497089e8
11
doc/api.oa3
11
doc/api.oa3
@ -3696,7 +3696,13 @@ paths:
|
|||||||
- name: agent
|
- name: agent
|
||||||
in: query
|
in: query
|
||||||
description: agent token
|
description: agent token
|
||||||
required: true
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- name: contact
|
||||||
|
in: query
|
||||||
|
description: contact token
|
||||||
|
required: false
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
- name: callId
|
- name: callId
|
||||||
@ -4612,9 +4618,12 @@ components:
|
|||||||
Ring:
|
Ring:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
|
- callId
|
||||||
- calleeToken
|
- calleeToken
|
||||||
- index
|
- index
|
||||||
properties:
|
properties:
|
||||||
|
callId:
|
||||||
|
type: string
|
||||||
calleeToken:
|
calleeToken:
|
||||||
type: string
|
type: string
|
||||||
index:
|
index:
|
||||||
|
@ -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(callId, callerToken, calleeToken);
|
bridgeRelay.AddBridge(account.ID, callId, callerToken, calleeToken);
|
||||||
|
|
||||||
// create response
|
// create response
|
||||||
call := Call{
|
call := Call{
|
||||||
|
@ -25,6 +25,5 @@ func AddRing(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SetRing(card, ring);
|
SetRing(card, ring);
|
||||||
|
|
||||||
WriteResponse(w, nil)
|
WriteResponse(w, nil)
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,22 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
//KeepCall keeps the call alive
|
//KeepCall keeps call and signaling alive
|
||||||
func KeepCall(w http.ResponseWriter, r *http.Request) {
|
func KeepCall(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
account, code, err := ParamAgentToken(r, false)
|
||||||
|
if err != nil {
|
||||||
|
ErrResponse(w, code, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var callId string
|
||||||
|
if err := ParseRequest(r, w, &callId); err != nil {
|
||||||
|
ErrResponse(w, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
bridgeRelay.KeepAlive(account.ID, callId);
|
||||||
|
WriteResponse(w, nil);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
38
net/server/internal/api_removeCall.go
Normal file
38
net/server/internal/api_removeCall.go
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package databag
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
//RemoveCall adds an active call with ice signal and relay
|
||||||
|
func RemoveCall(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
var callId string
|
||||||
|
if err := ParseRequest(r, w, &callId); err != nil {
|
||||||
|
ErrResponse(w, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tokenType := ParamTokenType(r)
|
||||||
|
if tokenType == APPTokenAgent {
|
||||||
|
account, code, err := ParamAgentToken(r, false)
|
||||||
|
if err != nil {
|
||||||
|
ErrResponse(w, code, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bridgeRelay.RemoveBridge(account.ID, callId, "");
|
||||||
|
} else if tokenType == APPTokenContact {
|
||||||
|
card, code, err := ParamContactToken(r, false)
|
||||||
|
if err != nil {
|
||||||
|
ErrResponse(w, code, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
bridgeRelay.RemoveBridge(card.Account.ID, callId, card.CardSlot.CardSlotID);
|
||||||
|
} else {
|
||||||
|
err := errors.New("unknown token type")
|
||||||
|
ErrResponse(w, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
WriteResponse(w, nil);
|
||||||
|
}
|
@ -127,6 +127,7 @@ func SetRing(card *store.Card, ring Ring) {
|
|||||||
|
|
||||||
// serialize ring activity
|
// serialize ring activity
|
||||||
var phone Phone
|
var phone Phone
|
||||||
|
phone.CallID = ring.CallID
|
||||||
phone.CalleeToken = ring.CalleeToken
|
phone.CalleeToken = ring.CalleeToken
|
||||||
phone.CardID = card.CardSlot.CardSlotID
|
phone.CardID = card.CardSlot.CardSlotID
|
||||||
var a Activity
|
var a Activity
|
||||||
|
@ -15,8 +15,11 @@ type BridgeStatus struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Bridge struct {
|
type Bridge struct {
|
||||||
|
accountId uint
|
||||||
callId string
|
callId string
|
||||||
|
cardId string
|
||||||
expires int64
|
expires int64
|
||||||
|
closed bool
|
||||||
callerToken string
|
callerToken string
|
||||||
calleeToken string
|
calleeToken string
|
||||||
caller *websocket.Conn
|
caller *websocket.Conn
|
||||||
@ -28,12 +31,14 @@ type BridgeRelay struct {
|
|||||||
bridges []Bridge
|
bridges []Bridge
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BridgeRelay) AddBridge(callId string, callerToken string, calleeToken string) {
|
func (s *BridgeRelay) AddBridge(accountId uint, callId 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,
|
||||||
callId: callId,
|
callId: callId,
|
||||||
expires: time.Now().Unix() + (BridgeKeepAlive * 3),
|
expires: time.Now().Unix() + (BridgeKeepAlive * 3),
|
||||||
|
closed: false,
|
||||||
callerToken: callerToken,
|
callerToken: callerToken,
|
||||||
calleeToken: calleeToken,
|
calleeToken: calleeToken,
|
||||||
}
|
}
|
||||||
@ -54,7 +59,7 @@ func setStatus(bridge Bridge, status string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BridgeRelay) KeepAlive(callId string) {
|
func (s *BridgeRelay) KeepAlive(accountId uint, callId string) {
|
||||||
s.sync.Lock()
|
s.sync.Lock()
|
||||||
defer s.sync.Unlock()
|
defer s.sync.Unlock()
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
@ -62,7 +67,7 @@ func (s *BridgeRelay) KeepAlive(callId string) {
|
|||||||
for _, bridge := range s.bridges {
|
for _, bridge := range s.bridges {
|
||||||
if bridge.expires > now {
|
if bridge.expires > now {
|
||||||
bridges = append(bridges, bridge)
|
bridges = append(bridges, bridge)
|
||||||
if bridge.callId == callId {
|
if bridge.callId == callId && bridge.accountId == accountId {
|
||||||
bridge.expires = now + (BridgeKeepAlive * 3)
|
bridge.expires = now + (BridgeKeepAlive * 3)
|
||||||
if bridge.caller != nil {
|
if bridge.caller != nil {
|
||||||
if err := bridge.caller.WriteMessage(websocket.PingMessage, nil); err != nil {
|
if err := bridge.caller.WriteMessage(websocket.PingMessage, nil); err != nil {
|
||||||
@ -82,12 +87,12 @@ func (s *BridgeRelay) KeepAlive(callId string) {
|
|||||||
s.bridges = bridges
|
s.bridges = bridges
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *BridgeRelay) RemoveBridge(callId string) {
|
func (s *BridgeRelay) RemoveBridge(accountId uint, callId string, cardId string) {
|
||||||
s.sync.Lock()
|
s.sync.Lock()
|
||||||
defer s.sync.Unlock()
|
defer s.sync.Unlock()
|
||||||
var bridges []Bridge
|
var bridges []Bridge
|
||||||
for _, bridge := range s.bridges {
|
for _, bridge := range s.bridges {
|
||||||
if bridge.callId == callId {
|
if bridge.callId == callId && bridge.accountId == accountId && (bridge.cardId == cardId || cardId == "") {
|
||||||
setStatus(bridge, "closed");
|
setStatus(bridge, "closed");
|
||||||
} else {
|
} else {
|
||||||
bridges = append(bridges, bridge)
|
bridges = append(bridges, bridge)
|
||||||
|
@ -415,10 +415,12 @@ type Revision struct {
|
|||||||
Card int64 `json:"card"`
|
Card int64 `json:"card"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Ring from contact initiating call
|
//Phone call indicator from contact initiating call
|
||||||
type Phone struct {
|
type Phone struct {
|
||||||
CardID string `json:"cardId"`
|
CardID string `json:"cardId"`
|
||||||
|
|
||||||
|
CallID string `json:"callId"`
|
||||||
|
|
||||||
CalleeToken string `json:"calleeToken"`
|
CalleeToken string `json:"calleeToken"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,6 +527,8 @@ type Call struct {
|
|||||||
|
|
||||||
type Ring struct {
|
type Ring struct {
|
||||||
|
|
||||||
|
CallID string `json:"callId"`
|
||||||
|
|
||||||
CalleeToken string `json:"calleeToken"`
|
CalleeToken string `json:"calleeToken"`
|
||||||
|
|
||||||
Index int32 `json:"index"`
|
Index int32 `json:"index"`
|
||||||
|
Loading…
Reference in New Issue
Block a user