Skip to content

Commit

Permalink
Merge pull request #859 from strukturag/recipient-call
Browse files Browse the repository at this point in the history
Support recipient "call".
  • Loading branch information
fancycode authored Nov 7, 2024
2 parents 54ed641 + da4c9d8 commit 119b1ff
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 10 deletions.
7 changes: 7 additions & 0 deletions api_signaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ const (
ServerFeatureSwitchTo = "switchto"
ServerFeatureDialout = "dialout"
ServerFeatureFederation = "federation"
ServerFeatureRecipientCall = "recipient-call"

// Features to send to internal clients only.
ServerFeatureInternalVirtualSessions = "virtual-sessions"
Expand All @@ -549,6 +550,7 @@ var (
ServerFeatureSwitchTo,
ServerFeatureDialout,
ServerFeatureFederation,
ServerFeatureRecipientCall,
}
DefaultFeaturesInternal = []string{
ServerFeatureInternalVirtualSessions,
Expand All @@ -559,6 +561,7 @@ var (
ServerFeatureSwitchTo,
ServerFeatureDialout,
ServerFeatureFederation,
ServerFeatureRecipientCall,
}
DefaultWelcomeFeatures = []string{
ServerFeatureAudioVideoPermissions,
Expand All @@ -570,6 +573,7 @@ var (
ServerFeatureSwitchTo,
ServerFeatureDialout,
ServerFeatureFederation,
ServerFeatureRecipientCall,
}
)

Expand Down Expand Up @@ -671,6 +675,7 @@ const (
RecipientTypeSession = "session"
RecipientTypeUser = "user"
RecipientTypeRoom = "room"
RecipientTypeCall = "call"
)

type MessageClientMessageRecipient struct {
Expand Down Expand Up @@ -740,6 +745,8 @@ func (m *MessageClientMessage) CheckValid() error {
}
switch m.Recipient.Type {
case RecipientTypeRoom:
fallthrough
case RecipientTypeCall:
// No additional checks required.
case RecipientTypeSession:
if m.Recipient.SessionId == "" {
Expand Down
36 changes: 26 additions & 10 deletions clientsession.go
Original file line number Diff line number Diff line change
Expand Up @@ -1362,18 +1362,34 @@ func (s *ClientSession) filterAsyncMessage(msg *AsyncMessage) *ServerMessage {

switch msg.Message.Type {
case "message":
if msg.Message.Message != nil &&
msg.Message.Message.Sender != nil &&
msg.Message.Message.Sender.SessionId == s.PublicId() {
// Don't send message back to sender (can happen if sent to user or room)
return nil
if msg.Message.Message != nil {
if sender := msg.Message.Message.Sender; sender != nil {
if sender.SessionId == s.PublicId() {
// Don't send message back to sender (can happen if sent to user or room)
return nil
}
if sender.Type == RecipientTypeCall {
if room := s.GetRoom(); room == nil || !room.IsSessionInCall(s) {
// Session is not in call, so discard.
return nil
}
}
}
}
case "control":
if msg.Message.Control != nil &&
msg.Message.Control.Sender != nil &&
msg.Message.Control.Sender.SessionId == s.PublicId() {
// Don't send message back to sender (can happen if sent to user or room)
return nil
if msg.Message.Control != nil {
if sender := msg.Message.Control.Sender; sender != nil {
if sender.SessionId == s.PublicId() {
// Don't send message back to sender (can happen if sent to user or room)
return nil
}
if sender.Type == RecipientTypeCall {
if room := s.GetRoom(); room == nil || !room.IsSessionInCall(s) {
// Session is not in call, so discard.
return nil
}
}
}
}
case "event":
if msg.Message.Event.Target == "room" {
Expand Down
18 changes: 18 additions & 0 deletions docs/standalone-signaling-api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,24 @@ Message format (Client -> Server, to all sessions in the same room):
}
}

Message format (Client -> Server, to all sessions in the same call):

{
"id": "unique-request-id",
"type": "message",
"message": {
"recipient": {
"type": "call"
},
"data": {
...object containing the data to send...
}
}
}

Sending to the same call is only available if the feature flag `recipient-call`
is present.

Message format (Server -> Client, receive message)

{
Expand Down
8 changes: 8 additions & 0 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,8 @@ func (h *Hub) processMessageMsg(sess Session, message *ClientMessage) {
subject = GetSubjectForUserId(msg.Recipient.UserId, session.Backend())
}
case RecipientTypeRoom:
fallthrough
case RecipientTypeCall:
if session != nil {
if room = session.GetRoom(); room != nil {
subject = GetSubjectForRoomId(room.Id(), room.Backend())
Expand Down Expand Up @@ -2130,6 +2132,8 @@ func (h *Hub) processMessageMsg(sess Session, message *ClientMessage) {
case RecipientTypeUser:
err = h.events.PublishUserMessage(msg.Recipient.UserId, session.Backend(), async)
case RecipientTypeRoom:
fallthrough
case RecipientTypeCall:
err = h.events.PublishRoomMessage(room.Id(), session.Backend(), async)
default:
err = fmt.Errorf("unsupported recipient type: %s", msg.Recipient.Type)
Expand Down Expand Up @@ -2217,6 +2221,8 @@ func (h *Hub) processControlMsg(session Session, message *ClientMessage) {
subject = GetSubjectForUserId(msg.Recipient.UserId, session.Backend())
}
case RecipientTypeRoom:
fallthrough
case RecipientTypeCall:
if session != nil {
if room = session.GetRoom(); room != nil {
subject = GetSubjectForRoomId(room.Id(), room.Backend())
Expand Down Expand Up @@ -2254,6 +2260,8 @@ func (h *Hub) processControlMsg(session Session, message *ClientMessage) {
case RecipientTypeUser:
err = h.events.PublishUserMessage(msg.Recipient.UserId, session.Backend(), async)
case RecipientTypeRoom:
fallthrough
case RecipientTypeCall:
err = h.events.PublishRoomMessage(room.Id(), room.Backend(), async)
default:
err = fmt.Errorf("unsupported recipient type: %s", msg.Recipient.Type)
Expand Down
Loading

0 comments on commit 119b1ff

Please sign in to comment.