implemented contact ring endpoint

This commit is contained in:
Roland Osborne 2023-03-20 06:47:54 -07:00
parent 016154bdf1
commit 123227ce05
4 changed files with 93 additions and 6 deletions

View File

@ -3745,6 +3745,11 @@ paths:
description: account disabled
'500':
description: internal server error
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Ring'
/talk/signal:
get:
@ -4599,6 +4604,17 @@ components:
type: integer
format: int32
Ring:
type: object
required:
- calleeToken
- index
properties:
calleeToken:
type: string
index:
type: integer
format: int32
securitySchemes:

View File

@ -4,6 +4,27 @@ import (
"net/http"
)
//AddRing adds ring event from contact
//AddRing notifies users of requested call
func AddRing(w http.ResponseWriter, r *http.Request) {
card, code, err := ParamContactToken(r, false)
if err != nil {
ErrResponse(w, code, err)
return
}
var ring Ring
if err := ParseRequest(r, w, &ring); err != nil {
ErrResponse(w, http.StatusBadRequest, err)
return
}
// push event on first ring
if ring.Index == 0 {
SendPushEvent(card.Account, "ring");
}
SetRing(card, ring);
WriteResponse(w, nil)
}

View File

@ -122,6 +122,34 @@ func ExitStatus() {
wsExit <- true
}
//SetRing sends ring object on all account websockets
func SetRing(card *store.Card, ring Ring) {
// serialize ring activity
var phone Phone
phone.CalleeToken = ring.CalleeToken
phone.CardID = card.CardSlot.CardSlotID
var a Activity
a.Phone = phone;
msg, err := json.Marshal(a)
if err != nil {
ErrMsg(err);
return
}
// lock access to statusListener
wsSync.Lock()
defer wsSync.Unlock()
// notify all listeners
chs, ok := statusListener[card.Account.ID]
if ok {
for _, ch := range chs {
ch <- msg
}
}
}
//SetStatus sends revision object on all account websockets
func SetStatus(account *store.Account) {

View File

@ -397,7 +397,7 @@ type ProfileData struct {
type Activity struct {
Revision Revision `json:"revision,emitempty"`
Ring Ring `json:"ring",omitempty"`
Phone Phone `json:"ring",omitempty"`
}
//Revision revision of each account module
@ -416,7 +416,7 @@ type Revision struct {
}
//Ring from contact initiating call
type Ring struct {
type Phone struct {
CardID string `json:"cardId"`
CalleeToken string `json:"calleeToken"`
@ -507,3 +507,25 @@ type TopicDetail struct {
Transform string `json:"transform,omitempty"`
}
type Call struct {
Id string `json:"id"`
CardId string `json:"cardId"`
CallerToken string `json:"callerToken"`
CalleeToken string `json:"calleeToken"`
KeepAlive int32 `json:"keepAlive"`
SturnPort int32 `json:"sturnPort"`
}
type Ring struct {
CalleeToken string `json:"calleeToken"`
Index int32 `json:"index"`
}