neko/internal/websocket/handler/broadcast.go

47 lines
1.1 KiB
Go
Raw Normal View History

2020-11-02 04:09:48 +13:00
package handler
import (
2020-10-29 07:15:48 +13:00
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
)
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) boradcastCreate(session types.Session, payload *message.BroadcastCreate) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
2020-11-02 04:09:48 +13:00
h.capture.StartBroadcast(payload.URL)
2020-11-15 04:09:00 +13:00
return h.boradcastStatus(session)
}
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) boradcastDestroy(session types.Session) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
2020-11-02 04:09:48 +13:00
h.capture.StopBroadcast()
2020-11-15 04:09:00 +13:00
return h.boradcastStatus(session)
}
2020-11-02 04:09:48 +13:00
func (h *MessageHandlerCtx) boradcastStatus(session types.Session) error {
if !session.Admin() {
h.logger.Debug().Msg("user not admin")
return nil
}
if err := session.Send(
message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
2020-11-02 05:34:47 +13:00
IsActive: h.capture.BroadcastEnabled(),
2020-11-02 04:09:48 +13:00
URL: h.capture.BroadcastUrl(),
}); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.BORADCAST_STATUS)
return err
}
return nil
}