mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
session update mutex logic.
This commit is contained in:
parent
325af8fc5a
commit
e9502b0d9b
@ -54,7 +54,7 @@ func (session *SessionCtx) IsHost() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
// webscoket
|
// websocket
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
|
func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
|
||||||
@ -69,25 +69,27 @@ func (session *SessionCtx) SetWebSocketPeer(websocketPeer types.WebSocketPeer) {
|
|||||||
|
|
||||||
func (session *SessionCtx) SetWebSocketConnected(websocketPeer types.WebSocketPeer, connected bool) {
|
func (session *SessionCtx) SetWebSocketConnected(websocketPeer types.WebSocketPeer, connected bool) {
|
||||||
session.websocketMu.Lock()
|
session.websocketMu.Lock()
|
||||||
if websocketPeer != session.websocketPeer {
|
isCurrentPeer := websocketPeer == session.websocketPeer
|
||||||
session.websocketMu.Unlock()
|
session.websocketMu.Unlock()
|
||||||
|
|
||||||
|
if !isCurrentPeer {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.websocketMu.Unlock()
|
|
||||||
|
|
||||||
session.state.IsConnected = connected
|
session.state.IsConnected = connected
|
||||||
|
|
||||||
if connected {
|
if connected {
|
||||||
session.manager.emmiter.Emit("connected", session)
|
session.manager.emmiter.Emit("connected", session)
|
||||||
} else {
|
return
|
||||||
session.manager.emmiter.Emit("disconnected", session)
|
|
||||||
|
|
||||||
session.websocketMu.Lock()
|
|
||||||
if websocketPeer == session.websocketPeer {
|
|
||||||
session.websocketPeer = nil
|
|
||||||
}
|
|
||||||
session.websocketMu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.manager.emmiter.Emit("disconnected", session)
|
||||||
|
|
||||||
|
session.websocketMu.Lock()
|
||||||
|
if websocketPeer == session.websocketPeer {
|
||||||
|
session.websocketPeer = nil
|
||||||
|
}
|
||||||
|
session.websocketMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) GetWebSocketPeer() types.WebSocketPeer {
|
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) {
|
func (session *SessionCtx) SetWebRTCConnected(webrtcPeer types.WebRTCPeer, connected bool) {
|
||||||
session.webrtcMu.Lock()
|
session.webrtcMu.Lock()
|
||||||
if webrtcPeer != session.webrtcPeer {
|
isCurrentPeer := webrtcPeer == session.webrtcPeer
|
||||||
session.webrtcMu.Unlock()
|
session.webrtcMu.Unlock()
|
||||||
|
|
||||||
|
if !isCurrentPeer {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
session.webrtcMu.Unlock()
|
|
||||||
|
|
||||||
session.state.IsWatching = connected
|
session.state.IsWatching = connected
|
||||||
session.manager.emmiter.Emit("state_changed", session)
|
session.manager.emmiter.Emit("state_changed", session)
|
||||||
|
|
||||||
if !connected {
|
if connected {
|
||||||
session.webrtcMu.Lock()
|
return
|
||||||
if webrtcPeer == session.webrtcPeer {
|
|
||||||
session.webrtcPeer = nil
|
|
||||||
}
|
|
||||||
session.webrtcMu.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
session.webrtcMu.Lock()
|
||||||
|
if webrtcPeer == session.webrtcPeer {
|
||||||
|
session.webrtcPeer = nil
|
||||||
|
}
|
||||||
|
session.webrtcMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) GetWebRTCPeer() types.WebRTCPeer {
|
func (session *SessionCtx) GetWebRTCPeer() types.WebRTCPeer {
|
||||||
|
Loading…
Reference in New Issue
Block a user