mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix deadlock.
This commit is contained in:
parent
6bd46b438e
commit
137614c087
@ -198,16 +198,13 @@ func (manager *SessionManagerCtx) ClearHost() {
|
||||
// ---
|
||||
|
||||
func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, exclude interface{}) {
|
||||
manager.sessionsMu.Lock()
|
||||
defer manager.sessionsMu.Unlock()
|
||||
|
||||
for id, session := range manager.sessions {
|
||||
for _, session := range manager.List() {
|
||||
if !session.State().IsConnected {
|
||||
continue
|
||||
}
|
||||
|
||||
if exclude != nil {
|
||||
if in, _ := utils.ArrayIn(id, exclude); in {
|
||||
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@ -217,16 +214,13 @@ func (manager *SessionManagerCtx) Broadcast(event string, payload interface{}, e
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) AdminBroadcast(event string, payload interface{}, exclude interface{}) {
|
||||
manager.sessionsMu.Lock()
|
||||
defer manager.sessionsMu.Unlock()
|
||||
|
||||
for id, session := range manager.sessions {
|
||||
for _, session := range manager.List() {
|
||||
if !session.State().IsConnected || !session.Profile().IsAdmin {
|
||||
continue
|
||||
}
|
||||
|
||||
if exclude != nil {
|
||||
if in, _ := utils.ArrayIn(id, exclude); in {
|
||||
if in, _ := utils.ArrayIn(session.ID(), exclude); in {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -68,14 +68,9 @@ func (peer *WebRTCPeerCtx) Destroy() {
|
||||
peer.mu.Lock()
|
||||
defer peer.mu.Unlock()
|
||||
|
||||
if peer.connection == nil || peer.connection.ConnectionState() != webrtc.PeerConnectionStateConnected {
|
||||
return
|
||||
if peer.connection != nil {
|
||||
err := peer.connection.Close()
|
||||
peer.logger.Err(err).Msg("peer connection destroyed")
|
||||
peer.connection = nil
|
||||
}
|
||||
|
||||
// TODO: Send webrtc disconnect event via websocket.
|
||||
|
||||
err := peer.connection.Close()
|
||||
peer.logger.Err(err).Msg("peer connection destroyed")
|
||||
|
||||
peer.connection = nil
|
||||
}
|
||||
|
@ -67,21 +67,18 @@ func (peer *WebSocketPeerCtx) Send(event string, payload interface{}) {
|
||||
}
|
||||
|
||||
func (peer *WebSocketPeerCtx) Destroy(reason string) {
|
||||
peer.mu.Lock()
|
||||
defer peer.mu.Unlock()
|
||||
|
||||
if peer.connection == nil {
|
||||
return
|
||||
}
|
||||
|
||||
peer.Send(
|
||||
event.SYSTEM_DISCONNECT,
|
||||
message.SystemDisconnect{
|
||||
Message: reason,
|
||||
})
|
||||
|
||||
err := peer.connection.Close()
|
||||
peer.logger.Err(err).Msg("peer connection destroyed")
|
||||
peer.mu.Lock()
|
||||
defer peer.mu.Unlock()
|
||||
|
||||
peer.connection = nil
|
||||
if peer.connection != nil {
|
||||
err := peer.connection.Close()
|
||||
peer.logger.Err(err).Msg("peer connection destroyed")
|
||||
peer.connection = nil
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user