neko/internal/websocket/handler/broadcast.go
2020-11-18 21:34:39 +01:00

45 lines
1000 B
Go

package handler
import (
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
func (h *MessageHandlerCtx) boradcastCreate(session types.Session, payload *message.BroadcastCreate) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
if err := h.capture.StartBroadcast(payload.URL); err != nil {
return err
}
return h.boradcastStatus(session)
}
func (h *MessageHandlerCtx) boradcastDestroy(session types.Session) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
h.capture.StopBroadcast()
return h.boradcastStatus(session)
}
func (h *MessageHandlerCtx) boradcastStatus(session types.Session) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
return session.Send(
message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
IsActive: h.capture.BroadcastEnabled(),
URL: h.capture.BroadcastUrl(),
})
}