mirror of
https://github.com/strukturag/nextcloud-spreed-signaling
synced 2024-05-02 22:03:09 +02:00
Pass along dialout status through transient data.
This commit is contained in:
parent
e1273a3c52
commit
3a7b4c48dc
14
api_async.go
14
api_async.go
|
@ -21,7 +21,11 @@
|
|||
*/
|
||||
package signaling
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
type AsyncMessage struct {
|
||||
SendTime time.Time `json:"sendtime"`
|
||||
|
@ -41,6 +45,14 @@ type AsyncMessage struct {
|
|||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func (m *AsyncMessage) String() string {
|
||||
data, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("Could not serialize %#v: %s", m, err)
|
||||
}
|
||||
return string(data)
|
||||
}
|
||||
|
||||
type AsyncRoomMessage struct {
|
||||
Type string `json:"type"`
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ import (
|
|||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -107,6 +108,8 @@ type BackendServerRoomRequest struct {
|
|||
|
||||
Dialout *BackendRoomDialoutRequest `json:"dialout,omitempty"`
|
||||
|
||||
Transient *BackendRoomTransientRequest `json:"transient,omitempty"`
|
||||
|
||||
// Internal properties
|
||||
ReceivedTime int64 `json:"received,omitempty"`
|
||||
}
|
||||
|
@ -200,6 +203,20 @@ func (r *BackendRoomDialoutRequest) ValidateNumber() *Error {
|
|||
return nil
|
||||
}
|
||||
|
||||
type TransientAction string
|
||||
|
||||
const (
|
||||
TransientActionSet TransientAction = "set"
|
||||
TransientActionDelete TransientAction = "delete"
|
||||
)
|
||||
|
||||
type BackendRoomTransientRequest struct {
|
||||
Action TransientAction `json:"action"`
|
||||
Key string `json:"key"`
|
||||
Value interface{} `json:"value,omitempty"`
|
||||
TTL time.Duration `json:"ttl,omitempty"`
|
||||
}
|
||||
|
||||
type BackendServerRoomResponse struct {
|
||||
Type string `json:"type"`
|
||||
|
||||
|
|
39
hub.go
39
hub.go
|
@ -97,6 +97,9 @@ var (
|
|||
|
||||
// Delay after which a screen publisher should be cleaned up.
|
||||
cleanupScreenPublisherDelay = time.Second
|
||||
|
||||
// Delay after which a "cleared" / "rejected" dialout status should be removed.
|
||||
removeCallStatusTTL = 5 * time.Second
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -1942,14 +1945,34 @@ func (h *Hub) processInternalMsg(client *Client, message *ClientMessage) {
|
|||
case "dialout":
|
||||
roomId := msg.Dialout.RoomId
|
||||
msg.Dialout.RoomId = "" // Don't send room id to recipients.
|
||||
if err := h.events.PublishRoomMessage(roomId, session.Backend(), &AsyncMessage{
|
||||
Type: "message",
|
||||
Message: &ServerMessage{
|
||||
Type: "dialout",
|
||||
Dialout: msg.Dialout,
|
||||
},
|
||||
}); err != nil {
|
||||
log.Printf("Error publishing dialout message %+v to room %s", msg.Dialout, roomId)
|
||||
if msg.Dialout.Type == "status" {
|
||||
asyncMessage := &AsyncMessage{
|
||||
Type: "room",
|
||||
Room: &BackendServerRoomRequest{
|
||||
Type: "transient",
|
||||
Transient: &BackendRoomTransientRequest{
|
||||
Action: TransientActionSet,
|
||||
Key: "callstatus_" + msg.Dialout.Status.CallId,
|
||||
Value: msg.Dialout.Status,
|
||||
},
|
||||
},
|
||||
}
|
||||
if msg.Dialout.Status.Status == DialoutStatusCleared || msg.Dialout.Status.Status == DialoutStatusRejected {
|
||||
asyncMessage.Room.Transient.TTL = removeCallStatusTTL
|
||||
}
|
||||
if err := h.events.PublishBackendRoomMessage(roomId, session.Backend(), asyncMessage); err != nil {
|
||||
log.Printf("Error publishing dialout message %+v to room %s", msg.Dialout, roomId)
|
||||
}
|
||||
} else {
|
||||
if err := h.events.PublishRoomMessage(roomId, session.Backend(), &AsyncMessage{
|
||||
Type: "message",
|
||||
Message: &ServerMessage{
|
||||
Type: "dialout",
|
||||
Dialout: msg.Dialout,
|
||||
},
|
||||
}); err != nil {
|
||||
log.Printf("Error publishing dialout message %+v to room %s", msg.Dialout, roomId)
|
||||
}
|
||||
}
|
||||
default:
|
||||
log.Printf("Ignore unsupported internal message %+v from %s", msg, session.PublicId())
|
||||
|
|
9
room.go
9
room.go
|
@ -244,6 +244,15 @@ func (r *Room) processBackendRoomRequestRoom(message *BackendServerRoomRequest)
|
|||
r.publishRoomMessage(message.Message)
|
||||
case "switchto":
|
||||
r.publishSwitchTo(message.SwitchTo)
|
||||
case "transient":
|
||||
switch message.Transient.Action {
|
||||
case TransientActionSet:
|
||||
r.SetTransientDataTTL(message.Transient.Key, message.Transient.Value, message.Transient.TTL)
|
||||
case TransientActionDelete:
|
||||
r.RemoveTransientData(message.Transient.Key)
|
||||
default:
|
||||
log.Printf("Unsupported transient action in room %s: %+v", r.Id(), message.Transient)
|
||||
}
|
||||
default:
|
||||
log.Printf("Unsupported backend room request with type %s in %s: %+v", message.Type, r.Id(), message)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue