mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
Broadcast should not return error.
This commit is contained in:
parent
3f4914d260
commit
da7e6f7728
@ -24,13 +24,11 @@ func (h *RoomHandler) ControlRequest(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
if err := h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
||||
}
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
@ -43,14 +41,12 @@ func (h *RoomHandler) ControlRelease(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
h.sessions.ClearHost()
|
||||
|
||||
if err := h.sessions.Broadcast(
|
||||
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_RELEASE,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
||||
}
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
@ -42,16 +42,15 @@ func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.R
|
||||
}
|
||||
|
||||
session := auth.GetSession(r)
|
||||
if err := h.sessions.Broadcast(
|
||||
|
||||
h.sessions.Broadcast(
|
||||
message.ScreenResolution{
|
||||
Event: event.SCREEN_RESOLUTION,
|
||||
ID: session.ID(),
|
||||
Width: data.Width,
|
||||
Height: data.Height,
|
||||
Rate: data.Rate,
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.SCREEN_RESOLUTION)
|
||||
}
|
||||
}, nil)
|
||||
|
||||
utils.HttpSuccess(w, data)
|
||||
}
|
||||
|
@ -142,7 +142,7 @@ func (manager *SessionManagerCtx) Members() []types.Session {
|
||||
return sessions
|
||||
}
|
||||
|
||||
func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{}) error {
|
||||
func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{}) {
|
||||
manager.membersMu.Lock()
|
||||
defer manager.membersMu.Unlock()
|
||||
|
||||
@ -158,11 +158,9 @@ func (manager *SessionManagerCtx) Broadcast(v interface{}, exclude interface{})
|
||||
}
|
||||
|
||||
if err := session.Send(v); err != nil {
|
||||
return err
|
||||
manager.logger.Warn().Err(err).Msgf("broadcasting event has failed")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ---
|
||||
|
@ -67,20 +67,13 @@ func (session *SessionCtx) SetConnected(connected bool) {
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Disconnect(reason string) error {
|
||||
if session.socket == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Refcator
|
||||
if err := session.Send(&message.Disconnect{
|
||||
Event: event.SYSTEM_DISCONNECT,
|
||||
Message: reason,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
session.SetConnected(false)
|
||||
return nil
|
||||
|
||||
return session.Send(
|
||||
message.Disconnect{
|
||||
Event: event.SYSTEM_DISCONNECT,
|
||||
Message: reason,
|
||||
})
|
||||
}
|
||||
|
||||
func (session *SessionCtx) Send(v interface{}) error {
|
||||
|
@ -29,7 +29,7 @@ type SessionManager interface {
|
||||
|
||||
Admins() []Session
|
||||
Members() []Session
|
||||
Broadcast(v interface{}, exclude interface{}) error
|
||||
Broadcast(v interface{}, exclude interface{})
|
||||
|
||||
OnHost(listener func(session Session))
|
||||
OnHostCleared(listener func(session Session))
|
||||
|
@ -19,11 +19,13 @@ func (h *MessageHandlerCtx) adminLock(session types.Session) error {
|
||||
|
||||
h.locked = true
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_LOCK,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) adminUnlock(session types.Session) error {
|
||||
@ -39,11 +41,13 @@ func (h *MessageHandlerCtx) adminUnlock(session types.Session) error {
|
||||
|
||||
h.locked = false
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_UNLOCK,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) adminControl(session types.Session) error {
|
||||
@ -56,19 +60,21 @@ func (h *MessageHandlerCtx) adminControl(session types.Session) error {
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
if host != nil {
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_CONTROL,
|
||||
ID: session.ID(),
|
||||
Target: host.ID(),
|
||||
}, nil)
|
||||
} else {
|
||||
h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_CONTROL,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
}
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_CONTROL,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) adminRelease(session types.Session) error {
|
||||
@ -81,19 +87,21 @@ func (h *MessageHandlerCtx) adminRelease(session types.Session) error {
|
||||
h.sessions.ClearHost()
|
||||
|
||||
if host != nil {
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_RELEASE,
|
||||
ID: session.ID(),
|
||||
Target: host.ID(),
|
||||
}, nil)
|
||||
} else {
|
||||
h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_RELEASE,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
}
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_RELEASE,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Admin) error {
|
||||
@ -110,12 +118,14 @@ func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Ad
|
||||
|
||||
h.sessions.SetHost(target)
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.CONTROL_GIVE,
|
||||
ID: session.ID(),
|
||||
Target: target.ID(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Admin) error {
|
||||
@ -139,10 +149,12 @@ func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Ad
|
||||
return err
|
||||
}
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_KICK,
|
||||
Target: target.ID(),
|
||||
ID: session.ID(),
|
||||
}, []string{payload.ID})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -15,11 +15,13 @@ func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
|
||||
h.logger.Debug().Str("id", session.ID()).Msgf("host called %s", event.CONTROL_RELEASE)
|
||||
h.sessions.ClearHost()
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_RELEASE,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
||||
@ -30,26 +32,30 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
||||
h.sessions.SetHost(session)
|
||||
|
||||
// let everyone know
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: session.ID(),
|
||||
}, nil)
|
||||
} else {
|
||||
// tell session there is a host
|
||||
if err := session.Send(
|
||||
message.Control{
|
||||
Event: event.CONTROL_REQUEST,
|
||||
ID: host.ID(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// tell host session wants to be host
|
||||
return host.Send(
|
||||
message.Control{
|
||||
Event: event.CONTROL_REQUESTING,
|
||||
ID: session.ID(),
|
||||
})
|
||||
}
|
||||
|
||||
// tell session there is a host
|
||||
if err := session.Send(message.Control{
|
||||
Event: event.CONTROL_REQUEST,
|
||||
ID: host.ID(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// tell host session wants to be host
|
||||
return host.Send(message.Control{
|
||||
Event: event.CONTROL_REQUESTING,
|
||||
ID: session.ID(),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.Control) error {
|
||||
@ -66,12 +72,14 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
|
||||
|
||||
h.sessions.SetHost(target)
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.ControlTarget{
|
||||
Event: event.CONTROL_GIVE,
|
||||
ID: session.ID(),
|
||||
Target: target.ID(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *message.Clipboard) error {
|
||||
|
@ -17,7 +17,7 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes
|
||||
return nil
|
||||
}
|
||||
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.ScreenResolution{
|
||||
Event: event.SCREEN_RESOLUTION,
|
||||
ID: session.ID(),
|
||||
@ -25,6 +25,8 @@ func (h *MessageHandlerCtx) screenSizeChange(session types.Session, payload *mes
|
||||
Height: payload.Height,
|
||||
Rate: payload.Rate,
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) screenSize(session types.Session) error {
|
||||
|
@ -39,10 +39,11 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
}
|
||||
|
||||
// send list of members to session
|
||||
if err := session.Send(message.MembersList{
|
||||
Event: event.MEMBER_LIST,
|
||||
Memebers: members,
|
||||
}); err != nil {
|
||||
if err := session.Send(
|
||||
message.MembersList{
|
||||
Event: event.MEMBER_LIST,
|
||||
Memebers: members,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -54,22 +55,25 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
|
||||
// tell session there is a host
|
||||
host := h.sessions.GetHost()
|
||||
if host != nil {
|
||||
if err := session.Send(message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: host.ID(),
|
||||
}); err != nil {
|
||||
if err := session.Send(
|
||||
message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: host.ID(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// let everyone know there is a new session
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Member{
|
||||
Event: event.MEMBER_CONNECTED,
|
||||
ID: session.ID(),
|
||||
Name: session.Name(),
|
||||
Admin: session.Admin(),
|
||||
}, nil)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
||||
@ -77,20 +81,19 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
|
||||
if session.IsHost() {
|
||||
h.sessions.ClearHost()
|
||||
|
||||
// gracefully handle error
|
||||
if err := h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_RELEASE,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
||||
}
|
||||
}, nil)
|
||||
}
|
||||
|
||||
// let everyone know session disconnected
|
||||
return h.sessions.Broadcast(
|
||||
h.sessions.Broadcast(
|
||||
message.MemberDisconnected{
|
||||
Event: event.MEMBER_DISCONNECTED,
|
||||
ID: session.ID(),
|
||||
}, nil);
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -12,13 +12,14 @@ func (h *MessageHandlerCtx) signalProvide(session types.Session) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return session.Send(message.SignalProvide{
|
||||
Event: event.SIGNAL_PROVIDE,
|
||||
ID: session.ID(),
|
||||
SDP: sdp,
|
||||
Lite: lite,
|
||||
ICE: ice,
|
||||
})
|
||||
return session.Send(
|
||||
message.SignalProvide{
|
||||
Event: event.SIGNAL_PROVIDE,
|
||||
ID: session.ID(),
|
||||
SDP: sdp,
|
||||
Lite: lite,
|
||||
ICE: ice,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *MessageHandlerCtx) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
|
||||
|
@ -97,10 +97,11 @@ func (ws *WebSocketManagerCtx) Start() {
|
||||
break
|
||||
}
|
||||
|
||||
if err := session.Send(message.Clipboard{
|
||||
Event: event.CONTROL_CLIPBOARD,
|
||||
Text: text,
|
||||
}); err != nil {
|
||||
if err := session.Send(
|
||||
message.Clipboard{
|
||||
Event: event.CONTROL_CLIPBOARD,
|
||||
Text: text,
|
||||
}); err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("could not sync clipboard")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user