mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Split connected to WebRTC & WebSocket.
This commit is contained in:
parent
bc77c8f8f5
commit
fa54823098
@ -24,7 +24,10 @@ type SessionCtx struct {
|
|||||||
manager *SessionManagerCtx
|
manager *SessionManagerCtx
|
||||||
profile MemberProfile
|
profile MemberProfile
|
||||||
websocket_peer types.WebSocketPeer
|
websocket_peer types.WebSocketPeer
|
||||||
|
websocket_connected bool
|
||||||
webrtc_peer types.WebRTCPeer
|
webrtc_peer types.WebRTCPeer
|
||||||
|
webrtc_connected bool
|
||||||
|
// TODO: Refactor.
|
||||||
connected bool
|
connected bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +60,31 @@ func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer)
|
|||||||
session.manager.emmiter.Emit("created", session)
|
session.manager.emmiter.Emit("created", session)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (session *SessionCtx) SetWebSocketConnected(connected bool) {
|
||||||
|
if connected {
|
||||||
|
session.websocket_connected = true
|
||||||
|
session.manager.emmiter.Emit("websocket_connected", session)
|
||||||
|
} else {
|
||||||
|
session.websocket_connected = false
|
||||||
|
session.manager.emmiter.Emit("websocket_disconnected", session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) {
|
func (session *SessionCtx) SetWebRTCPeer(webrtc_peer types.WebRTCPeer) {
|
||||||
session.webrtc_peer = webrtc_peer
|
session.webrtc_peer = webrtc_peer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (session *SessionCtx) SetWebRTCConnected(connected bool) {
|
||||||
|
if connected {
|
||||||
|
session.webrtc_connected = true
|
||||||
|
session.manager.emmiter.Emit("webrtc_connected", session)
|
||||||
|
} else {
|
||||||
|
session.webrtc_connected = false
|
||||||
|
session.manager.emmiter.Emit("webrtc_disconnected", session)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor.
|
||||||
func (session *SessionCtx) SetConnected(connected bool) {
|
func (session *SessionCtx) SetConnected(connected bool) {
|
||||||
session.connected = connected
|
session.connected = connected
|
||||||
|
|
||||||
@ -76,6 +100,7 @@ func (session *SessionCtx) SetConnected(connected bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) Disconnect(reason string) error {
|
func (session *SessionCtx) Disconnect(reason string) error {
|
||||||
|
// TODO: Refactor.
|
||||||
session.SetConnected(false)
|
session.SetConnected(false)
|
||||||
|
|
||||||
return session.Send(
|
return session.Send(
|
||||||
|
@ -10,7 +10,10 @@ type Session interface {
|
|||||||
Connected() bool
|
Connected() bool
|
||||||
SetName(name string)
|
SetName(name string)
|
||||||
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
||||||
|
SetWebSocketConnected(connected bool)
|
||||||
SetWebRTCPeer(webrtc_peer WebRTCPeer)
|
SetWebRTCPeer(webrtc_peer WebRTCPeer)
|
||||||
|
SetWebRTCConnected(connected bool)
|
||||||
|
// TODO: Refactor.
|
||||||
SetConnected(connected bool)
|
SetConnected(connected bool)
|
||||||
Disconnect(reason string) error
|
Disconnect(reason string) error
|
||||||
Send(v interface{}) error
|
Send(v interface{}) error
|
||||||
|
@ -156,9 +156,11 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (string, bool
|
|||||||
case webrtc.PeerConnectionStateDisconnected:
|
case webrtc.PeerConnectionStateDisconnected:
|
||||||
case webrtc.PeerConnectionStateFailed:
|
case webrtc.PeerConnectionStateFailed:
|
||||||
manager.logger.Info().Str("id", session.ID()).Msg("peer disconnected")
|
manager.logger.Info().Str("id", session.ID()).Msg("peer disconnected")
|
||||||
|
// TODO: Change WebRTC connection state.
|
||||||
session.SetConnected(false)
|
session.SetConnected(false)
|
||||||
case webrtc.PeerConnectionStateConnected:
|
case webrtc.PeerConnectionStateConnected:
|
||||||
manager.logger.Info().Str("id", session.ID()).Msg("peer connected")
|
manager.logger.Info().Str("id", session.ID()).Msg("peer connected")
|
||||||
|
// TODO: Change WebRTC connection state.
|
||||||
session.SetConnected(true)
|
session.SetConnected(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -187,9 +187,13 @@ func (ws *WebSocketManagerCtx) handle(connection *websocket.Conn, session types.
|
|||||||
ticker := time.NewTicker(pingPeriod)
|
ticker := time.NewTicker(pingPeriod)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
// TODO: Change WebSocket connection state.
|
||||||
|
//session.SetConnected(true)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
ws.logger.Debug().Str("address", connection.RemoteAddr().String()).Msg("handle socket ending")
|
ws.logger.Debug().Str("address", connection.RemoteAddr().String()).Msg("handle socket ending")
|
||||||
|
// TODO: Change WebSocket connection state.
|
||||||
session.SetConnected(false)
|
session.SetConnected(false)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user