remove duplicate error logging.

This commit is contained in:
Miroslav Šedivý 2020-11-16 18:12:25 +01:00
parent b411675108
commit 316533dab0
5 changed files with 70 additions and 168 deletions

View File

@ -21,16 +21,11 @@ func (h *MessageHandlerCtx) adminLock(session types.Session) error {
h.locked = true
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.Admin{
Event: event.ADMIN_LOCK,
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_LOCK)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) adminUnlock(session types.Session) error {
@ -46,16 +41,11 @@ func (h *MessageHandlerCtx) adminUnlock(session types.Session) error {
h.locked = false
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.Admin{
Event: event.ADMIN_UNLOCK,
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNLOCK)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) adminControl(session types.Session) error {
@ -68,27 +58,19 @@ func (h *MessageHandlerCtx) adminControl(session types.Session) error {
h.sessions.SetHost(session)
if host != nil {
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.ADMIN_CONTROL,
ID: session.ID(),
Target: host.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
return err
}
} else {
if err := h.sessions.Broadcast(
message.Admin{
Event: event.ADMIN_CONTROL,
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
return err
}
}, nil)
}
return nil
return h.sessions.Broadcast(
message.Admin{
Event: event.ADMIN_CONTROL,
ID: session.ID(),
}, nil)
}
func (h *MessageHandlerCtx) adminRelease(session types.Session) error {
@ -101,27 +83,19 @@ func (h *MessageHandlerCtx) adminRelease(session types.Session) error {
h.sessions.ClearHost()
if host != nil {
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.ADMIN_RELEASE,
ID: session.ID(),
Target: host.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
return err
}
} else {
if err := h.sessions.Broadcast(
message.Admin{
Event: event.ADMIN_RELEASE,
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
return err
}
}, nil)
}
return nil
return h.sessions.Broadcast(
message.Admin{
Event: event.ADMIN_RELEASE,
ID: session.ID(),
}, nil)
}
func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Admin) error {
@ -138,17 +112,12 @@ func (h *MessageHandlerCtx) adminGive(session types.Session, payload *message.Ad
h.sessions.SetHost(target)
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.CONTROL_GIVE,
ID: session.ID(),
Target: target.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) adminMute(session types.Session, payload *message.Admin) error {
@ -170,17 +139,12 @@ func (h *MessageHandlerCtx) adminMute(session types.Session, payload *message.Ad
target.SetMuted(true)
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.ADMIN_MUTE,
Target: target.ID(),
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) adminUnmute(session types.Session, payload *message.Admin) error {
@ -197,17 +161,12 @@ func (h *MessageHandlerCtx) adminUnmute(session types.Session, payload *message.
target.SetMuted(false)
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.ADMIN_UNMUTE,
Target: target.ID(),
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Admin) error {
@ -231,17 +190,12 @@ func (h *MessageHandlerCtx) adminKick(session types.Session, payload *message.Ad
return err
}
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.ADMIN_KICK,
Target: target.ID(),
ID: session.ID(),
}, []string{payload.ID}); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_KICK)
return err
}
return nil
}, []string{payload.ID})
}
func (h *MessageHandlerCtx) adminBan(session types.Session, payload *message.Admin) error {
@ -281,15 +235,10 @@ func (h *MessageHandlerCtx) adminBan(session types.Session, payload *message.Adm
return err
}
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.AdminTarget{
Event: event.ADMIN_BAN,
Target: target.ID(),
ID: session.ID(),
}, []string{payload.ID}); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_BAN)
return err
}
return nil
}, []string{payload.ID})
}

View File

@ -32,15 +32,10 @@ func (h *MessageHandlerCtx) boradcastStatus(session types.Session) error {
return nil
}
if err := session.Send(
return session.Send(
message.BroadcastStatus{
Event: event.BORADCAST_STATUS,
IsActive: h.capture.BroadcastEnabled(),
URL: h.capture.BroadcastUrl(),
}); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.BORADCAST_STATUS)
return err
}
return nil
})
}

View File

@ -15,16 +15,11 @@ 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()
if err := h.sessions.Broadcast(
return 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)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
@ -35,35 +30,26 @@ func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
h.sessions.SetHost(session)
// let everyone know
if err := h.sessions.Broadcast(
return 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)
return err
}
} else {
// tell session there is a host
if err := session.Send(message.Control{
Event: event.CONTROL_REQUEST,
ID: host.ID(),
}); err != nil {
h.logger.Warn().Err(err).Str("id", session.ID()).Msgf("sending event %s has failed", event.CONTROL_REQUEST)
return err
}
// tell host session wants to be host
if err := host.Send(message.Control{
Event: event.CONTROL_REQUESTING,
ID: session.ID(),
}); err != nil {
h.logger.Warn().Err(err).Str("id", host.ID()).Msgf("sending event %s has failed", event.CONTROL_REQUESTING)
return err
}
}, nil)
}
return nil
// 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(),
})
}
func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.Control) error {
@ -80,17 +66,12 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
h.sessions.SetHost(target)
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.ControlTarget{
Event: event.CONTROL_GIVE,
ID: session.ID(),
Target: target.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *message.Clipboard) error {

View File

@ -14,22 +14,17 @@ func (h *MessageHandlerCtx) screenSet(session types.Session, payload *message.Sc
if err := h.desktop.ChangeScreenSize(payload.Width, payload.Height, payload.Rate); err != nil {
h.logger.Warn().Err(err).Msgf("unable to change screen size")
return err
return nil
}
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
ID: session.ID(),
Width: payload.Width,
Height: payload.Height,
Rate: payload.Rate,
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) screenResolution(session types.Session) error {
@ -39,17 +34,13 @@ func (h *MessageHandlerCtx) screenResolution(session types.Session) error {
return nil
}
if err := session.Send(message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
Width: size.Width,
Height: size.Height,
Rate: int(size.Rate),
}); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_RESOLUTION)
return err
}
return nil
return session.Send(
message.ScreenResolution{
Event: event.SCREEN_RESOLUTION,
Width: size.Width,
Height: size.Height,
Rate: int(size.Rate),
})
}
func (h *MessageHandlerCtx) screenConfigurations(session types.Session) error {
@ -58,13 +49,9 @@ func (h *MessageHandlerCtx) screenConfigurations(session types.Session) error {
return nil
}
if err := session.Send(message.ScreenConfigurations{
Event: event.SCREEN_CONFIGURATIONS,
Configurations: h.desktop.ScreenConfigurations(),
}); err != nil {
h.logger.Warn().Err(err).Msgf("sending event %s has failed", event.SCREEN_CONFIGURATIONS)
return err
}
return nil
return session.Send(
message.ScreenConfigurations{
Event: event.SCREEN_CONFIGURATIONS,
Configurations: h.desktop.ScreenConfigurations(),
})
}

View File

@ -44,7 +44,6 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
Event: event.MEMBER_LIST,
Memebers: members,
}); err != nil {
h.logger.Warn().Str("id", session.ID()).Err(err).Msgf("sending event %s has failed", event.MEMBER_LIST)
return err
}
@ -60,31 +59,27 @@ func (h *MessageHandlerCtx) SessionConnected(session types.Session) error {
Event: event.CONTROL_LOCKED,
ID: host.ID(),
}); err != nil {
h.logger.Warn().Str("id", session.ID()).Err(err).Msgf("sending event %s has failed", event.CONTROL_LOCKED)
return err
}
}
// let everyone know there is a new session
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.Member{
Event: event.MEMBER_CONNECTED,
ID: session.ID(),
Name: session.Name(),
Admin: session.Admin(),
Muted: session.Muted(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
return err
}
return nil
}, nil)
}
func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
// clear host if exists
if session.IsHost() {
h.sessions.ClearHost()
// gracefully handle error
if err := h.sessions.Broadcast(
message.Control{
Event: event.CONTROL_RELEASE,
@ -95,14 +90,9 @@ func (h *MessageHandlerCtx) SessionDisconnected(session types.Session) error {
}
// let everyone know session disconnected
if err := h.sessions.Broadcast(
return h.sessions.Broadcast(
message.MemberDisconnected{
Event: event.MEMBER_DISCONNECTED,
ID: session.ID(),
}, nil); err != nil {
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.MEMBER_DISCONNECTED)
return err
}
return nil
}, nil);
}