mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
moved capture StopStream to websockets events.
This commit is contained in:
parent
0d2f3405bb
commit
81b3fbd673
@ -13,12 +13,11 @@ import (
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
func New(capture types.CaptureManager, config *config.Session) *SessionManagerCtx {
|
||||
func New(config *config.Session) *SessionManagerCtx {
|
||||
manager := &SessionManagerCtx{
|
||||
logger: log.With().Str("module", "session").Logger(),
|
||||
host: nil,
|
||||
hostMu: sync.Mutex{},
|
||||
capture: capture,
|
||||
config: config,
|
||||
members: make(map[string]*SessionCtx),
|
||||
membersMu: sync.Mutex{},
|
||||
@ -46,7 +45,6 @@ type SessionManagerCtx struct {
|
||||
logger zerolog.Logger
|
||||
host types.Session
|
||||
hostMu sync.Mutex
|
||||
capture types.CaptureManager
|
||||
config *config.Session
|
||||
members map[string]*SessionCtx
|
||||
membersMu sync.Mutex
|
||||
@ -218,22 +216,12 @@ func (manager *SessionManagerCtx) OnHostCleared(listener func(session types.Sess
|
||||
|
||||
func (manager *SessionManagerCtx) OnConnected(listener func(session types.Session)) {
|
||||
manager.emmiter.On("connected", func(payload ...interface{}) {
|
||||
// Start streaming, when first joins
|
||||
if !manager.capture.Streaming() {
|
||||
manager.capture.StartStream()
|
||||
}
|
||||
|
||||
listener(payload[0].(*SessionCtx))
|
||||
})
|
||||
}
|
||||
|
||||
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() && !manager.HasConnectedMembers() {
|
||||
manager.capture.StopStream()
|
||||
}
|
||||
|
||||
listener(payload[0].(*SessionCtx))
|
||||
})
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ type SessionManager interface {
|
||||
GetHost() Session
|
||||
ClearHost()
|
||||
|
||||
HasConnectedMembers() bool
|
||||
Members() []Session
|
||||
Broadcast(v interface{}, exclude interface{})
|
||||
AdminBroadcast(v interface{}, exclude interface{})
|
||||
|
@ -7,6 +7,11 @@ import (
|
||||
)
|
||||
|
||||
func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
// start streaming, when first member connects
|
||||
if !h.capture.Streaming() {
|
||||
h.capture.StartStream()
|
||||
}
|
||||
|
||||
if err := h.systemInit(session); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -30,6 +35,11 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
||||
// Stop streaming, if last member disonnects
|
||||
if h.capture.Streaming() && !h.sessions.HasConnectedMembers() {
|
||||
h.capture.StopStream()
|
||||
}
|
||||
|
||||
// clear host if exists
|
||||
if session.IsHost() {
|
||||
h.desktop.ResetKeys()
|
||||
|
Loading…
Reference in New Issue
Block a user