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)) {
|
func (manager *SessionManagerCtx) OnDisconnected(listener func(session types.Session)) {
|
||||||
manager.emmiter.On("disconnected", func(payload ...interface{}) {
|
manager.emmiter.On("disconnected", func(payload ...interface{}) {
|
||||||
// Stop streaming, if everyone left
|
// Stop streaming, if everyone left
|
||||||
if manager.capture.Streaming() && len(manager.members) == 0 {
|
if manager.capture.Streaming() && len(manager.Members()) == 0 {
|
||||||
manager.capture.StopStream()
|
manager.capture.StopStream()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,18 +69,18 @@ func (session *SessionCtx) SetPeer(peer types.Peer) {
|
|||||||
session.peer = peer
|
session.peer = peer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) SetConnected() {
|
func (session *SessionCtx) SetConnected(connected bool) {
|
||||||
session.connected = true
|
session.connected = connected
|
||||||
session.manager.emmiter.Emit("connected", session)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (session *SessionCtx) SetDisconnected() {
|
if connected {
|
||||||
session.connected = false
|
session.manager.emmiter.Emit("connected", session)
|
||||||
|
} else {
|
||||||
session.manager.emmiter.Emit("disconnected", session)
|
session.manager.emmiter.Emit("disconnected", session)
|
||||||
session.socket = nil
|
session.socket = nil
|
||||||
|
|
||||||
// TODO: Refactor.
|
// TODO: Refactor.
|
||||||
session.manager.Destroy(session.id)
|
session.manager.Destroy(session.id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (session *SessionCtx) Disconnect(reason string) error {
|
func (session *SessionCtx) Disconnect(reason string) error {
|
||||||
@ -96,7 +96,7 @@ func (session *SessionCtx) Disconnect(reason string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
session.SetDisconnected()
|
session.SetConnected(false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@ type Session interface {
|
|||||||
SetName(name string)
|
SetName(name string)
|
||||||
SetSocket(socket WebSocket)
|
SetSocket(socket WebSocket)
|
||||||
SetPeer(peer Peer)
|
SetPeer(peer Peer)
|
||||||
SetConnected()
|
SetConnected(connected bool)
|
||||||
SetDisconnected()
|
|
||||||
Disconnect(reason string) error
|
Disconnect(reason string) error
|
||||||
Send(v interface{}) error
|
Send(v interface{}) error
|
||||||
SignalAnswer(sdp string) error
|
SignalAnswer(sdp string) error
|
||||||
|
@ -156,10 +156,10 @@ 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")
|
||||||
session.SetDisconnected()
|
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")
|
||||||
session.SetConnected()
|
session.SetConnected(true)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ func (ws *WebSocketManagerCtx) handle(connection *websocket.Conn, session types.
|
|||||||
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")
|
||||||
session.SetDisconnected()
|
session.SetConnected(false)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
Loading…
Reference in New Issue
Block a user