2020-11-02 04:09:48 +13:00
|
|
|
package handler
|
2020-10-23 03:54:50 +13:00
|
|
|
|
|
|
|
import (
|
2020-10-29 07:15:48 +13:00
|
|
|
"demodesk/neko/internal/types"
|
|
|
|
"demodesk/neko/internal/types/event"
|
|
|
|
"demodesk/neko/internal/types/message"
|
2020-10-23 03:54:50 +13:00
|
|
|
)
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) boradcastCreate(session types.Session, payload *message.BroadcastCreate) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
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-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) boradcastDestroy(session types.Session) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
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-10-23 03:54:50 +13:00
|
|
|
}
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
func (h *MessageHandlerCtx) boradcastStatus(session types.Session) error {
|
2020-10-23 03:54:50 +13:00
|
|
|
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(),
|
2020-10-23 03:54:50 +13:00
|
|
|
}); err != nil {
|
|
|
|
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.BORADCAST_STATUS)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|