Skip to content

Commit

Permalink
Include room session id in "joined" events.
Browse files Browse the repository at this point in the history
This helps with matching signaling sessions with sessions in Talk.
  • Loading branch information
fancycode committed Dec 17, 2021
1 parent 468470d commit 76ad24c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 4 additions & 3 deletions api_signaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,10 @@ type EventServerMessage struct {
}

type EventServerMessageSessionEntry struct {
SessionId string `json:"sessionid"`
UserId string `json:"userid"`
User *json.RawMessage `json:"user,omitempty"`
SessionId string `json:"sessionid"`
UserId string `json:"userid"`
User *json.RawMessage `json:"user,omitempty"`
RoomSessionId string `json:"roomsessionid,omitempty"`
}

// MCU-related types
Expand Down
8 changes: 6 additions & 2 deletions hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -1186,11 +1186,15 @@ func (h *Hub) notifyUserJoinedRoom(room *Room, session *ClientSession, sessionDa
if sessions := room.AddSession(session, sessionData); len(sessions) > 0 {
events := make([]*EventServerMessageSessionEntry, 0, len(sessions))
for _, s := range sessions {
events = append(events, &EventServerMessageSessionEntry{
entry := &EventServerMessageSessionEntry{
SessionId: s.PublicId(),
UserId: s.UserId(),
User: s.UserData(),
})
}
if s, ok := s.(*ClientSession); ok {
entry.RoomSessionId = s.RoomSessionId()
}
events = append(events, entry)
}
msg := &ServerMessage{
Type: "event",
Expand Down
3 changes: 3 additions & 0 deletions room.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ func (r *Room) PublishSessionJoined(session Session, sessionData *RoomSessionDat
},
},
}
if session, ok := session.(*ClientSession); ok {
message.Event.Join[0].RoomSessionId = session.RoomSessionId()
}
if err := r.publish(message); err != nil {
log.Printf("Could not publish session joined message in room %s: %s", r.Id(), err)
}
Expand Down
2 changes: 2 additions & 0 deletions room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ func TestRoom_RoomSessionData(t *testing.T) {
t.Error(err)
} else if err := client.checkMessageJoinedSession(message, hello.Hello.SessionId, expected); err != nil {
t.Error(err)
} else if message.Event.Join[0].RoomSessionId != roomId+"-"+hello.Hello.SessionId {
t.Errorf("Expected join room session id %s, got %+v", roomId+"-"+hello.Hello.SessionId, message.Event.Join[0])
}

session := hub.GetSessionByPublicId(hello.Hello.SessionId)
Expand Down

0 comments on commit 76ad24c

Please sign in to comment.