Skip to content

Commit 81ec22d

Browse files
author
Marius Gassen
committed
fix: Return Disconnected room ConnectionState if engine is nil
- With the refactoring of reading the connection state directly from the engine there the non-exposed disconnected engine cannot be guarded and will panic: return disconnected if the engine is nil
1 parent 02cea80 commit 81ec22d

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

room.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ func (r *Room) ConnectionState() ConnectionState {
536536
r.lock.RLock()
537537
defer r.lock.RUnlock()
538538

539+
if r.engine == nil {
540+
return ConnectionStateDisconnected
541+
}
542+
539543
switch r.engine.currentState() {
540544
case connectionManagerStateInitial, connectionManagerStateClosed:
541545
return ConnectionStateDisconnected

room_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,8 @@ func TestOnRoomUpdateDeliversLateSID(t *testing.T) {
116116
return room.SID() == "RM_late"
117117
}, time.Second, 10*time.Millisecond, "SID() never returned the SID delivered via OnRoomUpdate")
118118
}
119+
120+
func TestConnectionStateWithoutEngine(t *testing.T) {
121+
room := NewRoom(nil)
122+
require.Equal(t, ConnectionStateDisconnected, room.ConnectionState())
123+
}

0 commit comments

Comments
 (0)