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
@ -19,13 +19,16 @@ type MemberProfile struct {
|
||||
}
|
||||
|
||||
type SessionCtx struct {
|
||||
id string
|
||||
logger zerolog.Logger
|
||||
manager *SessionManagerCtx
|
||||
profile MemberProfile
|
||||
websocket_peer types.WebSocketPeer
|
||||
webrtc_peer types.WebRTCPeer
|
||||
connected bool
|
||||
id string
|
||||
logger zerolog.Logger
|
||||
manager *SessionManagerCtx
|
||||
profile MemberProfile
|
||||
websocket_peer types.WebSocketPeer
|
||||
websocket_connected bool
|
||||
webrtc_peer types.WebRTCPeer
|
||||
webrtc_connected bool
|
||||
// TODO: Refactor.
|
||||
connected bool
|
||||
}
|
||||
|
||||
func (session *SessionCtx) ID() string {
|
||||
@ -57,10 +60,31 @@ func (session *SessionCtx) SetWebSocketPeer(websocket_peer types.WebSocketPeer)
|
||||
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) {
|
||||
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) {
|
||||
session.connected = connected
|
||||
|
||||
@ -76,6 +100,7 @@ func (session *SessionCtx) SetConnected(connected bool) {
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Disconnect(reason string) error {
|
||||
// TODO: Refactor.
|
||||
session.SetConnected(false)
|
||||
|
||||
return session.Send(
|
||||
|
@ -10,7 +10,10 @@ type Session interface {
|
||||
Connected() bool
|
||||
SetName(name string)
|
||||
SetWebSocketPeer(websocket_peer WebSocketPeer)
|
||||
SetWebSocketConnected(connected bool)
|
||||
SetWebRTCPeer(webrtc_peer WebRTCPeer)
|
||||
SetWebRTCConnected(connected bool)
|
||||
// TODO: Refactor.
|
||||
SetConnected(connected bool)
|
||||
Disconnect(reason string) error
|
||||
Send(v interface{}) error
|
||||
|
@ -156,9 +156,11 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session) (string, bool
|
||||
case webrtc.PeerConnectionStateDisconnected:
|
||||
case webrtc.PeerConnectionStateFailed:
|
||||
manager.logger.Info().Str("id", session.ID()).Msg("peer disconnected")
|
||||
// TODO: Change WebRTC connection state.
|
||||
session.SetConnected(false)
|
||||
case webrtc.PeerConnectionStateConnected:
|
||||
manager.logger.Info().Str("id", session.ID()).Msg("peer connected")
|
||||
// TODO: Change WebRTC connection state.
|
||||
session.SetConnected(true)
|
||||
}
|
||||
})
|
||||
|
@ -187,9 +187,13 @@ func (ws *WebSocketManagerCtx) handle(connection *websocket.Conn, session types.
|
||||
ticker := time.NewTicker(pingPeriod)
|
||||
|
||||
go func() {
|
||||
// TODO: Change WebSocket connection state.
|
||||
//session.SetConnected(true)
|
||||
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
ws.logger.Debug().Str("address", connection.RemoteAddr().String()).Msg("handle socket ending")
|
||||
// TODO: Change WebSocket connection state.
|
||||
session.SetConnected(false)
|
||||
}()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user