moved capture StopStream to websockets events.

This commit is contained in:
Miroslav Šedivý 2020-12-02 17:36:06 +01:00
parent 0d2f3405bb
commit 81b3fbd673
4 changed files with 12 additions and 14 deletions

View File

@ -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))
})
}

View File

@ -51,6 +51,7 @@ type SessionManager interface {
GetHost() Session
ClearHost()
HasConnectedMembers() bool
Members() []Session
Broadcast(v interface{}, exclude interface{})
AdminBroadcast(v interface{}, exclude interface{})

View File

@ -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()

View File

@ -148,7 +148,6 @@ func (neko *Neko) Start() {
neko.webRTCManager.Start()
neko.sessionManager = session.New(
neko.captureManager,
neko.Configs.Session,
)