Skip to content

Commit

Permalink
Include "federated" in "join" events for fed. sessions.
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed Jul 25, 2024
1 parent f064471 commit fc0591b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api_signaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ type EventServerMessageSessionEntry struct {
UserId string `json:"userid"`
User json.RawMessage `json:"user,omitempty"`
RoomSessionId string `json:"roomsessionid,omitempty"`
Federated bool `json:"federated,omitempty"`
}

func (e *EventServerMessageSessionEntry) Clone() *EventServerMessageSessionEntry {
Expand All @@ -1061,6 +1062,7 @@ func (e *EventServerMessageSessionEntry) Clone() *EventServerMessageSessionEntry
UserId: e.UserId,
User: e.User,
RoomSessionId: e.RoomSessionId,
Federated: e.Federated,
}
}

Expand Down
4 changes: 4 additions & 0 deletions docs/standalone-signaling-api-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@ Room event session object:
}
}

If a session is federated, an additional entry `"federated": true` will be
available.


Message format (Server -> Client, user(s) left):

{
Expand Down
7 changes: 7 additions & 0 deletions federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func Test_Federation(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}

// The client2 will see its own session id, not the one from the remote server.
Expand Down Expand Up @@ -183,6 +184,7 @@ func Test_Federation(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}
assert.NoError(client2.RunUntilJoined(ctx, hello1.Hello, hello2.Hello))

Expand Down Expand Up @@ -347,6 +349,7 @@ func Test_Federation(t *testing.T) {
remoteSessionId4 = evt.SessionId
assert.NotEqual(hello4.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"4", evt.UserId)
assert.True(evt.Federated)
}

assert.NoError(client2.RunUntilJoined(ctx, &HelloServerMessage{
Expand Down Expand Up @@ -449,6 +452,7 @@ func Test_FederationMedia(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}

// The client2 will see its own session id, not the one from the remote server.
Expand Down Expand Up @@ -540,6 +544,7 @@ func Test_FederationResume(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(testDefaultUserId+"2", evt.UserId)
assert.True(evt.Federated)
}

// The client2 will see its own session id, not the one from the remote server.
Expand Down Expand Up @@ -667,6 +672,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(hello2.Hello.UserId, evt.UserId)
assert.True(evt.Federated)
}

// The client2 will see its own session id, not the one from the remote server.
Expand Down Expand Up @@ -708,6 +714,7 @@ func Test_FederationResumeNewSession(t *testing.T) {
remoteSessionId = evt.SessionId
assert.NotEqual(hello2.Hello.SessionId, remoteSessionId)
assert.Equal(hello2.Hello.UserId, evt.UserId)
assert.True(evt.Federated)
}

// client2 will join the room again after the reconnect with the new
Expand Down
2 changes: 2 additions & 0 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ func (r *Room) notifySessionJoined(sessionId string) {
}
if s, ok := s.(*ClientSession); ok {
entry.RoomSessionId = s.RoomSessionId()
entry.Federated = s.ClientType() == HelloClientTypeFederation
}
events = append(events, entry)
}
Expand Down Expand Up @@ -535,6 +536,7 @@ func (r *Room) PublishSessionJoined(session Session, sessionData *RoomSessionDat
}
if session, ok := session.(*ClientSession); ok {
message.Event.Join[0].RoomSessionId = session.RoomSessionId()
message.Event.Join[0].Federated = session.ClientType() == HelloClientTypeFederation
}
if err := r.publish(message); err != nil {
log.Printf("Could not publish session joined message in room %s: %s", r.Id(), err)
Expand Down

0 comments on commit fc0591b

Please sign in to comment.