mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
remove code duplication.
This commit is contained in:
parent
db706097f6
commit
234b0a2e06
@ -77,101 +77,93 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
switch header.Event {
|
switch header.Event {
|
||||||
// Signal Events
|
// Signal Events
|
||||||
case event.SIGNAL_ANSWER:
|
case event.SIGNAL_ANSWER:
|
||||||
payload := &message.SignalAnswer{}
|
payload := &message.SignalAnswer{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.signalAnswer(session, payload)
|
return h.signalAnswer(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
|
|
||||||
// Control Events
|
// Control Events
|
||||||
case event.CONTROL_RELEASE:
|
case event.CONTROL_RELEASE:
|
||||||
return errors.Wrapf(h.controlRelease(session), "%s failed", header.Event)
|
err = h.controlRelease(session)
|
||||||
case event.CONTROL_REQUEST:
|
case event.CONTROL_REQUEST:
|
||||||
return errors.Wrapf(h.controlRequest(session), "%s failed", header.Event)
|
err = h.controlRequest(session)
|
||||||
case event.CONTROL_GIVE:
|
case event.CONTROL_GIVE:
|
||||||
payload := &message.Control{}
|
payload := &message.Control{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.controlGive(session, payload)
|
return h.controlGive(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.CONTROL_CLIPBOARD:
|
case event.CONTROL_CLIPBOARD:
|
||||||
payload := &message.Clipboard{}
|
payload := &message.Clipboard{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.controlClipboard(session, payload)
|
return h.controlClipboard(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.CONTROL_KEYBOARD:
|
case event.CONTROL_KEYBOARD:
|
||||||
payload := &message.Keyboard{}
|
payload := &message.Keyboard{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.controlKeyboard(session, payload)
|
return h.controlKeyboard(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
|
|
||||||
// Screen Events
|
// Screen Events
|
||||||
case event.SCREEN_RESOLUTION:
|
case event.SCREEN_RESOLUTION:
|
||||||
return errors.Wrapf(h.screenResolution(session), "%s failed", header.Event)
|
err = h.screenResolution(session)
|
||||||
case event.SCREEN_CONFIGURATIONS:
|
case event.SCREEN_CONFIGURATIONS:
|
||||||
return errors.Wrapf(h.screenConfigurations(session), "%s failed", header.Event)
|
err = h.screenConfigurations(session)
|
||||||
case event.SCREEN_SET:
|
case event.SCREEN_SET:
|
||||||
payload := &message.ScreenResolution{}
|
payload := &message.ScreenResolution{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.screenSet(session, payload)
|
return h.screenSet(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
|
|
||||||
// Boradcast Events
|
// Boradcast Events
|
||||||
case event.BORADCAST_CREATE:
|
case event.BORADCAST_CREATE:
|
||||||
payload := &message.BroadcastCreate{}
|
payload := &message.BroadcastCreate{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.boradcastCreate(session, payload)
|
return h.boradcastCreate(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.BORADCAST_DESTROY:
|
case event.BORADCAST_DESTROY:
|
||||||
return errors.Wrapf(h.boradcastDestroy(session), "%s failed", header.Event)
|
err = h.boradcastDestroy(session)
|
||||||
|
|
||||||
// Admin Events
|
// Admin Events
|
||||||
case event.ADMIN_LOCK:
|
case event.ADMIN_LOCK:
|
||||||
return errors.Wrapf(h.adminLock(session), "%s failed", header.Event)
|
err = h.adminLock(session)
|
||||||
case event.ADMIN_UNLOCK:
|
case event.ADMIN_UNLOCK:
|
||||||
return errors.Wrapf(h.adminUnlock(session), "%s failed", header.Event)
|
err = h.adminUnlock(session)
|
||||||
case event.ADMIN_CONTROL:
|
case event.ADMIN_CONTROL:
|
||||||
return errors.Wrapf(h.adminControl(session), "%s failed", header.Event)
|
err = h.adminControl(session)
|
||||||
case event.ADMIN_RELEASE:
|
case event.ADMIN_RELEASE:
|
||||||
return errors.Wrapf(h.adminRelease(session), "%s failed", header.Event)
|
err = h.adminRelease(session)
|
||||||
case event.ADMIN_GIVE:
|
case event.ADMIN_GIVE:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.adminGive(session, payload)
|
return h.adminGive(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.ADMIN_BAN:
|
case event.ADMIN_BAN:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.adminBan(session, payload)
|
return h.adminBan(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.ADMIN_KICK:
|
case event.ADMIN_KICK:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.adminKick(session, payload)
|
return h.adminKick(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.ADMIN_MUTE:
|
case event.ADMIN_MUTE:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.adminMute(session, payload)
|
return h.adminMute(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
case event.ADMIN_UNMUTE:
|
case event.ADMIN_UNMUTE:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.adminUnmute(session, payload)
|
return h.adminUnmute(session, payload)
|
||||||
}), "%s failed", header.Event)
|
})
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("unknown message event %s", header.Event)
|
return errors.Errorf("unknown message event %s", header.Event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return errors.Wrapf(err, "%s failed", header.Event)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user