Skip to content

Commit

Permalink
Add special handling for "forceMute" control event.
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed Jul 31, 2024
1 parent 1ee579e commit 0fc9487
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
14 changes: 14 additions & 0 deletions federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,20 @@ func (c *FederationClient) processMessage(msg *ServerMessage) {
case "control":
c.updateSessionRecipient(msg.Control.Recipient, localSessionId, remoteSessionId)
c.updateSessionSender(msg.Control.Sender, localSessionId, remoteSessionId)
// Special handling for "forceMute" event.
if len(msg.Control.Data) > 0 && msg.Control.Data[0] == '{' {
var data map[string]interface{}
if err := json.Unmarshal(msg.Control.Data, &data); err == nil {
if acton, found := data["action"]; found && acton == "forceMute" {
if peerId, found := data["peerId"]; found && peerId == remoteSessionId {
data["peerId"] = localSessionId
if d, err := json.Marshal(data); err == nil {
msg.Control.Data = d
}
}
}
}
}
case "event":
switch msg.Event.Target {
case "participants":
Expand Down
17 changes: 17 additions & 0 deletions federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,23 @@ func Test_Federation(t *testing.T) {
}
}

// Special handling for the "forceMute" control event.
forceMute := map[string]any{
"action": "forceMute",
"peerId": remoteSessionId,
}
if assert.NoError(client1.SendControl(MessageClientMessageRecipient{
Type: "session",
SessionId: remoteSessionId,
}, forceMute)) {
var payload map[string]any
if assert.NoError(checkReceiveClientControl(ctx, client2, "session", hello1.Hello, &payload)) {
// The sessionId in "peerId" will be replaced with the local one.
forceMute["peerId"] = hello2.Hello.SessionId
assert.Equal(forceMute, payload)
}
}

data3 := "from-2-to-2"
// Clients can't send to their own (local) session id.
if assert.NoError(client2.SendMessage(MessageClientMessageRecipient{
Expand Down

0 comments on commit 0fc9487

Please sign in to comment.