diff --git a/doc/api.oa3 b/doc/api.oa3 index 89b53fef..a544eca0 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -3745,7 +3745,12 @@ paths: description: account disabled '500': description: internal server error - + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/Ring' + /talk/signal: get: tags: @@ -4599,7 +4604,18 @@ components: type: integer format: int32 - + Ring: + type: object + required: + - calleeToken + - index + properties: + calleeToken: + type: string + index: + type: integer + format: int32 + securitySchemes: basicAuth: diff --git a/net/server/internal/api_addRing.go b/net/server/internal/api_addRing.go index 2a87b698..880e5df8 100644 --- a/net/server/internal/api_addRing.go +++ b/net/server/internal/api_addRing.go @@ -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) +} diff --git a/net/server/internal/api_status.go b/net/server/internal/api_status.go index de3ce209..8a1d5ffa 100644 --- a/net/server/internal/api_status.go +++ b/net/server/internal/api_status.go @@ -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) { diff --git a/net/server/internal/models.go b/net/server/internal/models.go index c2cc708c..13c55f8b 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -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"` +}