diff --git a/turn/server.go b/turn/server.go index a7ff5213..945d1f61 100644 --- a/turn/server.go +++ b/turn/server.go @@ -57,7 +57,7 @@ func Start(conf config.Config) (*Server, error) { split := strings.Split(conf.TurnAddress, ":") svr := &Server{ - Port: split[len(split) - 1], + Port: split[len(split)-1], lookup: map[string]Entry{}, strictAuth: conf.TurnStrictAuth, } diff --git a/ws/event_disconnected.go b/ws/event_disconnected.go index 6f6acc99..89d49e7b 100644 --- a/ws/event_disconnected.go +++ b/ws/event_disconnected.go @@ -36,14 +36,14 @@ func (e *Disconnected) Execute(rooms *Rooms, current ClientInfo) error { if ok { host.Write <- outgoing.EndShare(id) } - room.closeSession(id) + room.closeSession(rooms, id) } if bytes.Equal(session.Host.Bytes(), current.ID.Bytes()) { client, ok := room.Users[session.Client] if ok { client.Write <- outgoing.EndShare(id) } - room.closeSession(id) + room.closeSession(rooms, id) } } diff --git a/ws/event_stop_share.go b/ws/event_stop_share.go index ac081211..ddf346b7 100644 --- a/ws/event_stop_share.go +++ b/ws/event_stop_share.go @@ -33,7 +33,7 @@ func (e *StopShare) Execute(rooms *Rooms, current ClientInfo) error { if ok { client.Write <- outgoing.EndShare(id) } - room.closeSession(id) + room.closeSession(rooms, id) } } diff --git a/ws/room.go b/ws/room.go index e0f52924..50d015c1 100644 --- a/ws/room.go +++ b/ws/room.go @@ -88,7 +88,11 @@ func (r *Rooms) address(user *User, prefix string) string { return fmt.Sprintf("%s:%s:%s", prefix, ip, r.turnServer.Port) } -func (r *Room) closeSession(id xid.ID) { +func (r *Room) closeSession(rooms *Rooms, id xid.ID) { + if r.Mode == ConnectionTURN { + rooms.turnServer.Disallow(id.String() + "host") + rooms.turnServer.Disallow(id.String() + "client") + } delete(r.Sessions, id) sessionClosedTotal.Inc() } diff --git a/ws/rooms.go b/ws/rooms.go index f709669c..7234c897 100644 --- a/ws/rooms.go +++ b/ws/rooms.go @@ -79,7 +79,10 @@ func (r *Rooms) closeRoom(roomId string) { return } usersLeftTotal.Add(float64(len(room.Users))) - sessionClosedTotal.Add(float64(len(room.Sessions))) + for id := range room.Sessions { + room.closeSession(r, id) + } + delete(r.Rooms, roomId) roomsClosedTotal.Inc() }