mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Connected / Disconnected refactor.
This commit is contained in:
parent
e51541fe01
commit
51c6e0091f
@ -168,7 +168,7 @@ func (manager *SessionManagerCtx) OnConnected(listener func(session types.Sessio
|
||||
func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Session)) {
|
||||
manager.emmiter.On("disconnected", func(payload ...interface{}) {
|
||||
// Stop streaming, if everyone left
|
||||
if manager.capture.Streaming() && len(manager.members) == 0 {
|
||||
if manager.capture.Streaming() && len(manager.Members()) == 0 {
|
||||
manager.capture.StopStream()
|
||||
}
|
||||
|
||||
|
@ -69,19 +69,19 @@ func (session *SessionCtx) SetPeer(peer types.Peer) {
|
||||
session.peer = peer
|
||||
}
|
||||
|
||||
func (session *SessionCtx) SetConnected() {
|
||||
session.connected = true
|
||||
session.manager.emmiter.Emit("connected", session)
|
||||
}
|
||||
func (session *SessionCtx) SetConnected(connected bool) {
|
||||
session.connected = connected
|
||||
|
||||
func (session *SessionCtx) SetDisconnected() {
|
||||
session.connected = false
|
||||
if connected {
|
||||
session.manager.emmiter.Emit("connected", session)
|
||||
} else {
|
||||
session.manager.emmiter.Emit("disconnected", session)
|
||||
session.socket = nil
|
||||
|
||||
// TODO: Refactor.
|
||||
session.manager.Destroy(session.id)
|
||||
}
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Disconnect(reason string) error {
|
||||
if session.socket == nil {
|
||||
@ -96,7 +96,7 @@ func (session *SessionCtx) Disconnect(reason string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
session.SetDisconnected()
|
||||
session.SetConnected(false)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -14,8 +14,7 @@ type Session interface {
|
||||
SetName(name string)
|
||||
SetSocket(socket WebSocket)
|
||||
SetPeer(peer Peer)
|
||||
SetConnected()
|
||||
SetDisconnected()
|
||||
SetConnected(connected bool)
|
||||
Disconnect(reason string) error
|
||||
Send(v interface{}) error
|
||||
SignalAnswer(sdp string) error
|
||||
|
@ -156,10 +156,10 @@ 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")
|
||||
session.SetDisconnected()
|
||||
session.SetConnected(false)
|
||||
case webrtc.PeerConnectionStateConnected:
|
||||
manager.logger.Info().Str("id", session.ID()).Msg("peer connected")
|
||||
session.SetConnected()
|
||||
session.SetConnected(true)
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -197,7 +197,7 @@ func (ws *WebSocketManagerCtx) handle(connection *websocket.Conn, session types.
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
ws.logger.Debug().Str("address", connection.RemoteAddr().String()).Msg("handle socket ending")
|
||||
session.SetDisconnected()
|
||||
session.SetConnected(false)
|
||||
}()
|
||||
|
||||
for {
|
||||
|
Loading…
Reference in New Issue
Block a user