session update mutex logic.

This commit is contained in:
Miroslav Šedivý 2021-09-30 19:42:25 +02:00
parent 325af8fc5a
commit e9502b0d9b

View File

@ -54,7 +54,7 @@ func (session *SessionCtx) IsHost() bool {
}
// ---
// webscoket
// websocket
// ---
func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
@ -69,17 +69,20 @@ func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
func (session *SessionCtx) SetWebSocketConnected(websocketPeer types.WebSocketPeer, connected bool) {
session.websocketMu.Lock()
if websocketPeer != session.websocketPeer {
isCurrentPeer := websocketPeer == session.websocketPeer
session.websocketMu.Unlock()
if !isCurrentPeer {
return
}
session.websocketMu.Unlock()
session.state.IsConnected = connected
if connected {
session.manager.emmiter.Emit("connected", session)
} else {
return
}
session.manager.emmiter.Emit("disconnected", session)
session.websocketMu.Lock()
@ -87,7 +90,6 @@ func (session *SessionCtx) SetWebSocketConnected(websocketPeer types.WebSocketPe
session.websocketPeer = nil
}
session.websocketMu.Unlock()
}
}
func (session *SessionCtx) GetWebSocketPeer() types.WebSocketPeer {
@ -120,22 +122,25 @@ func (session *SessionCtx) SetWebRTCPeer(webrtcPeer types.WebRTCPeer) {
func (session *SessionCtx) SetWebRTCConnected(webrtcPeer types.WebRTCPeer, connected bool) {
session.webrtcMu.Lock()
if webrtcPeer != session.webrtcPeer {
isCurrentPeer := webrtcPeer == session.webrtcPeer
session.webrtcMu.Unlock()
if !isCurrentPeer {
return
}
session.webrtcMu.Unlock()
session.state.IsWatching = connected
session.manager.emmiter.Emit("state_changed", session)
if !connected {
if connected {
return
}
session.webrtcMu.Lock()
if webrtcPeer == session.webrtcPeer {
session.webrtcPeer = nil
}
session.webrtcMu.Unlock()
}
}
func (session *SessionCtx) GetWebRTCPeer() types.WebRTCPeer {