neko/internal/websocket/handler/broadcast.go

42 lines
959 B
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
}
2020-11-17 06:12:25 +13:00
return 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-11-17 06:12:25 +13:00
})
}