Update entry if room session id changes.

This commit is contained in:
Joachim Bauch 2023-09-05 15:23:19 +02:00
parent bc7dba17c1
commit 92690f4613
No known key found for this signature in database
GPG key ID: 77C1D22D53E15F02
2 changed files with 24 additions and 0 deletions

View file

@ -56,6 +56,14 @@ func (r *BuiltinRoomSessions) SetRoomSession(session Session, roomSessionId stri
r.mu.Lock()
defer r.mu.Unlock()
if prev, found := r.sessionIdToRoomSession[sid]; found {
if prev == roomSessionId {
return nil
}
delete(r.roomSessionToSessionid, prev)
}
r.sessionIdToRoomSession[sid] = roomSessionId
r.roomSessionToSessionid[roomSessionId] = sid
}

View file

@ -23,6 +23,7 @@ package signaling
import (
"encoding/json"
"errors"
"net/url"
"testing"
"time"
@ -145,4 +146,19 @@ func testRoomSessions(t *testing.T, sessions RoomSessions) {
} else if sid != s2.PublicId() {
t.Errorf("Expected session id %s, got %s", s2.PublicId(), sid)
}
if err := sessions.SetRoomSession(s2, "room-session2"); err != nil {
t.Error(err)
}
if sid, err := sessions.GetSessionId("room-session"); err == nil {
t.Errorf("expected error %s, got sid %s", ErrNoSuchRoomSession, sid)
} else if !errors.Is(err, ErrNoSuchRoomSession) {
t.Errorf("expected %s, got %s", ErrNoSuchRoomSession, err)
}
if sid, err := sessions.GetSessionId("room-session2"); err != nil {
t.Errorf("Expected session id %s, got error %s", s2.PublicId(), err)
} else if sid != s2.PublicId() {
t.Errorf("Expected session id %s, got %s", s2.PublicId(), sid)
}
}