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
|
|
|
|
}
|
|
|
|
|
2020-11-17 06:12:25 +13:00
|
|
|
return session.Send(
|
2020-10-23 03:54:50 +13:00
|
|
|
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
|
|
|
})
|
2020-10-23 03:54:50 +13:00
|
|
|
}
|