From 7fb977faa49ccbb38798474428714dda857c736c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sun, 1 Nov 2020 17:34:47 +0100 Subject: [PATCH] edit broadcast. --- internal/capture/broadcast.go | 14 ++++++++------ internal/capture/manager.go | 2 ++ internal/types/capture.go | 2 +- internal/websocket/handler/broadcast.go | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/capture/broadcast.go b/internal/capture/broadcast.go index 692a2c26..ef7e35b5 100644 --- a/internal/capture/broadcast.go +++ b/internal/capture/broadcast.go @@ -7,14 +7,14 @@ import ( func (manager *CaptureManagerCtx) StartBroadcastPipeline() { var err error - if manager.IsBoradcasting() || manager.broadcast_url == "" { + if manager.broadcast != nil || !manager.BroadcastEnabled() { return } manager.logger.Info(). Str("audio_device", manager.config.Device). Str("video_display", manager.config.Display). - Str("rtmp_pipeline_src", manager.broadcast.Src). + Str("broadcast_pipeline", manager.config.BroadcastPipeline). Msgf("Creating broadcast pipeline...") manager.broadcast, err = gst.CreateRTMPPipeline( @@ -33,26 +33,28 @@ func (manager *CaptureManagerCtx) StartBroadcastPipeline() { } func (manager *CaptureManagerCtx) StopBroadcastPipeline() { - if !manager.IsBoradcasting() { + if manager.broadcast == nil { return } manager.broadcast.DestroyPipeline() + manager.logger.Info().Msgf("Stopping broadcast pipeline...") manager.broadcast = nil } func (manager *CaptureManagerCtx) StartBroadcast(url string) { manager.broadcast_url = url + manager.broadcasting = true manager.StartBroadcastPipeline() } func (manager *CaptureManagerCtx) StopBroadcast() { - manager.broadcast_url = "" + manager.broadcasting = false manager.StopBroadcastPipeline() } -func (manager *CaptureManagerCtx) IsBoradcasting() bool { - return manager.broadcast != nil +func (manager *CaptureManagerCtx) BroadcastEnabled() bool { + return manager.broadcasting } func (manager *CaptureManagerCtx) BroadcastUrl() string { diff --git a/internal/capture/manager.go b/internal/capture/manager.go index 889e3ec1..678d0ecf 100644 --- a/internal/capture/manager.go +++ b/internal/capture/manager.go @@ -21,6 +21,7 @@ type CaptureManagerCtx struct { shutdown chan bool emmiter events.EventEmmiter streaming bool + broadcasting bool broadcast_url string desktop types.DesktopManager } @@ -32,6 +33,7 @@ func New(desktop types.DesktopManager, config *config.Capture) *CaptureManagerCt emmiter: events.New(), config: config, streaming: false, + broadcasting: false, broadcast_url: "", desktop: desktop, } diff --git a/internal/types/capture.go b/internal/types/capture.go index 7ad3dfee..f54f3191 100644 --- a/internal/types/capture.go +++ b/internal/types/capture.go @@ -24,6 +24,6 @@ type CaptureManager interface { // broacast StartBroadcast(url string) StopBroadcast() - IsBoradcasting() bool + BroadcastEnabled() bool BroadcastUrl() string } diff --git a/internal/websocket/handler/broadcast.go b/internal/websocket/handler/broadcast.go index 953c8654..1fa0c766 100644 --- a/internal/websocket/handler/broadcast.go +++ b/internal/websocket/handler/broadcast.go @@ -45,7 +45,7 @@ func (h *MessageHandlerCtx) boradcastStatus(session types.Session) error { if err := session.Send( message.BroadcastStatus{ Event: event.BORADCAST_STATUS, - IsActive: h.capture.IsBoradcasting(), + IsActive: h.capture.BroadcastEnabled(), URL: h.capture.BroadcastUrl(), }); err != nil { h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.BORADCAST_STATUS)