mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
remove redundant ID parameter in websockets.
This commit is contained in:
parent
b6393c4396
commit
b61495ac0b
@ -8,7 +8,7 @@ import (
|
|||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandler) adminLock(id string, session types.Session) error {
|
func (h *MessageHandler) adminLock(session types.Session) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -24,7 +24,7 @@ func (h *MessageHandler) adminLock(id string, session types.Session) error {
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.Admin{
|
message.Admin{
|
||||||
Event: event.ADMIN_LOCK,
|
Event: event.ADMIN_LOCK,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_LOCK)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_LOCK)
|
||||||
return err
|
return err
|
||||||
@ -33,7 +33,7 @@ func (h *MessageHandler) adminLock(id string, session types.Session) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminUnlock(id string, session types.Session) error {
|
func (h *MessageHandler) adminUnlock(session types.Session) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -49,7 +49,7 @@ func (h *MessageHandler) adminUnlock(id string, session types.Session) error {
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.Admin{
|
message.Admin{
|
||||||
Event: event.ADMIN_UNLOCK,
|
Event: event.ADMIN_UNLOCK,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNLOCK)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNLOCK)
|
||||||
return err
|
return err
|
||||||
@ -58,7 +58,7 @@ func (h *MessageHandler) adminUnlock(id string, session types.Session) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
func (h *MessageHandler) adminControl(session types.Session) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -66,7 +66,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
|||||||
|
|
||||||
host, ok := h.sessions.GetHost()
|
host, ok := h.sessions.GetHost()
|
||||||
|
|
||||||
if err := h.sessions.SetHost(id); err != nil {
|
if err := h.sessions.SetHost(session.ID()); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("SetHost failed")
|
h.logger.Warn().Err(err).Msgf("SetHost failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -75,7 +75,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.ADMIN_CONTROL,
|
Event: event.ADMIN_CONTROL,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
Target: host.ID(),
|
Target: host.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
|
||||||
@ -85,7 +85,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.Admin{
|
message.Admin{
|
||||||
Event: event.ADMIN_CONTROL,
|
Event: event.ADMIN_CONTROL,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
|
||||||
return err
|
return err
|
||||||
@ -95,7 +95,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
func (h *MessageHandler) adminRelease(session types.Session) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -109,7 +109,7 @@ func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.ADMIN_RELEASE,
|
Event: event.ADMIN_RELEASE,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
Target: host.ID(),
|
Target: host.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
|
||||||
@ -119,7 +119,7 @@ func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.Admin{
|
message.Admin{
|
||||||
Event: event.ADMIN_RELEASE,
|
Event: event.ADMIN_RELEASE,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
|
||||||
return err
|
return err
|
||||||
@ -129,7 +129,7 @@ func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminGive(id string, session types.Session, payload *message.Admin) error {
|
func (h *MessageHandler) adminGive(session types.Session, payload *message.Admin) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -150,7 +150,7 @@ func (h *MessageHandler) adminGive(id string, session types.Session, payload *me
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.CONTROL_GIVE,
|
Event: event.CONTROL_GIVE,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
Target: payload.ID,
|
Target: payload.ID,
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
||||||
@ -160,7 +160,7 @@ func (h *MessageHandler) adminGive(id string, session types.Session, payload *me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminMute(id string, session types.Session, payload *message.Admin) error {
|
func (h *MessageHandler) adminMute(session types.Session, payload *message.Admin) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -183,7 +183,7 @@ func (h *MessageHandler) adminMute(id string, session types.Session, payload *me
|
|||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.ADMIN_MUTE,
|
Event: event.ADMIN_MUTE,
|
||||||
Target: target.ID(),
|
Target: target.ID(),
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
|
||||||
return err
|
return err
|
||||||
@ -192,7 +192,7 @@ func (h *MessageHandler) adminMute(id string, session types.Session, payload *me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminUnmute(id string, session types.Session, payload *message.Admin) error {
|
func (h *MessageHandler) adminUnmute(session types.Session, payload *message.Admin) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -210,7 +210,7 @@ func (h *MessageHandler) adminUnmute(id string, session types.Session, payload *
|
|||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.ADMIN_UNMUTE,
|
Event: event.ADMIN_UNMUTE,
|
||||||
Target: target.ID(),
|
Target: target.ID(),
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
|
||||||
return err
|
return err
|
||||||
@ -219,7 +219,7 @@ func (h *MessageHandler) adminUnmute(id string, session types.Session, payload *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminKick(id string, session types.Session, payload *message.Admin) error {
|
func (h *MessageHandler) adminKick(session types.Session, payload *message.Admin) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -244,7 +244,7 @@ func (h *MessageHandler) adminKick(id string, session types.Session, payload *me
|
|||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.ADMIN_KICK,
|
Event: event.ADMIN_KICK,
|
||||||
Target: target.ID(),
|
Target: target.ID(),
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, []string{payload.ID}); err != nil {
|
}, []string{payload.ID}); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_KICK)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_KICK)
|
||||||
return err
|
return err
|
||||||
@ -253,7 +253,7 @@ func (h *MessageHandler) adminKick(id string, session types.Session, payload *me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) adminBan(id string, session types.Session, payload *message.Admin) error {
|
func (h *MessageHandler) adminBan(session types.Session, payload *message.Admin) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -294,7 +294,7 @@ func (h *MessageHandler) adminBan(id string, session types.Session, payload *mes
|
|||||||
message.AdminTarget{
|
message.AdminTarget{
|
||||||
Event: event.ADMIN_BAN,
|
Event: event.ADMIN_BAN,
|
||||||
Target: target.ID(),
|
Target: target.ID(),
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, []string{payload.ID}); err != nil {
|
}, []string{payload.ID}); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_BAN)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_BAN)
|
||||||
return err
|
return err
|
||||||
|
@ -6,23 +6,22 @@ import (
|
|||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandler) controlRelease(id string, session types.Session) error {
|
func (h *MessageHandler) controlRelease(session types.Session) error {
|
||||||
|
|
||||||
// check if session is host
|
// check if session is host
|
||||||
if !h.sessions.IsHost(id) {
|
if !h.sessions.IsHost(session.ID()) {
|
||||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// release host
|
// release host
|
||||||
h.logger.Debug().Str("id", id).Msgf("host called %s", event.CONTROL_RELEASE)
|
h.logger.Debug().Str("id", session.ID()).Msgf("host called %s", event.CONTROL_RELEASE)
|
||||||
h.sessions.ClearHost()
|
h.sessions.ClearHost()
|
||||||
|
|
||||||
// tell everyone
|
// tell everyone
|
||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.Control{
|
message.Control{
|
||||||
Event: event.CONTROL_RELEASE,
|
Event: event.CONTROL_RELEASE,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
||||||
return err
|
return err
|
||||||
@ -31,11 +30,11 @@ func (h *MessageHandler) controlRelease(id string, session types.Session) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) controlRequest(id string, session types.Session) error {
|
func (h *MessageHandler) controlRequest(session types.Session) error {
|
||||||
// check for host
|
// check for host
|
||||||
if !h.sessions.HasHost() {
|
if !h.sessions.HasHost() {
|
||||||
// set host
|
// set host
|
||||||
if err := h.sessions.SetHost(id); err != nil {
|
if err := h.sessions.SetHost(session.ID()); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("SetHost failed")
|
h.logger.Warn().Err(err).Msgf("SetHost failed")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -44,7 +43,7 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.Control{
|
message.Control{
|
||||||
Event: event.CONTROL_LOCKED,
|
Event: event.CONTROL_LOCKED,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
||||||
return err
|
return err
|
||||||
@ -62,14 +61,14 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
|
|||||||
Event: event.CONTROL_REQUEST,
|
Event: event.CONTROL_REQUEST,
|
||||||
ID: host.ID(),
|
ID: host.ID(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
h.logger.Warn().Err(err).Str("id", id).Msgf("sending event %s has failed", event.CONTROL_REQUEST)
|
h.logger.Warn().Err(err).Str("id", session.ID()).Msgf("sending event %s has failed", event.CONTROL_REQUEST)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// tell host session wants to be host
|
// tell host session wants to be host
|
||||||
if err := host.Send(message.Control{
|
if err := host.Send(message.Control{
|
||||||
Event: event.CONTROL_REQUESTING,
|
Event: event.CONTROL_REQUESTING,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
h.logger.Warn().Err(err).Str("id", host.ID()).Msgf("sending event %s has failed", event.CONTROL_REQUESTING)
|
h.logger.Warn().Err(err).Str("id", host.ID()).Msgf("sending event %s has failed", event.CONTROL_REQUESTING)
|
||||||
return err
|
return err
|
||||||
@ -79,10 +78,10 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) controlGive(id string, session types.Session, payload *message.Control) error {
|
func (h *MessageHandler) controlGive(session types.Session, payload *message.Control) error {
|
||||||
// check if session is host
|
// check if session is host
|
||||||
if !h.sessions.IsHost(id) {
|
if !h.sessions.IsHost(session.ID()) {
|
||||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +100,7 @@ func (h *MessageHandler) controlGive(id string, session types.Session, payload *
|
|||||||
if err := h.sessions.Broadcast(
|
if err := h.sessions.Broadcast(
|
||||||
message.ControlTarget{
|
message.ControlTarget{
|
||||||
Event: event.CONTROL_GIVE,
|
Event: event.CONTROL_GIVE,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
Target: payload.ID,
|
Target: payload.ID,
|
||||||
}, nil); err != nil {
|
}, nil); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
||||||
@ -111,10 +110,10 @@ func (h *MessageHandler) controlGive(id string, session types.Session, payload *
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) controlClipboard(id string, session types.Session, payload *message.Clipboard) error {
|
func (h *MessageHandler) controlClipboard(session types.Session, payload *message.Clipboard) error {
|
||||||
// check if session is host
|
// check if session is host
|
||||||
if !h.sessions.IsHost(id) {
|
if !h.sessions.IsHost(session.ID()) {
|
||||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,10 +121,10 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
|
func (h *MessageHandler) controlKeyboard(session types.Session, payload *message.Keyboard) error {
|
||||||
// check if session is host
|
// check if session is host
|
||||||
if !h.sessions.IsHost(id) {
|
if !h.sessions.IsHost(session.ID()) {
|
||||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,43 +70,43 @@ func (h *MessageHandler) Message(id string, raw []byte) error {
|
|||||||
payload := &message.SignalAnswer{}
|
payload := &message.SignalAnswer{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.signalAnswer(id, session, payload)
|
return h.signalAnswer(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
|
|
||||||
// Control Events
|
// Control Events
|
||||||
case event.CONTROL_RELEASE:
|
case event.CONTROL_RELEASE:
|
||||||
return errors.Wrapf(h.controlRelease(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.controlRelease(session), "%s failed", header.Event)
|
||||||
case event.CONTROL_REQUEST:
|
case event.CONTROL_REQUEST:
|
||||||
return errors.Wrapf(h.controlRequest(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.controlRequest(session), "%s failed", header.Event)
|
||||||
case event.CONTROL_GIVE:
|
case event.CONTROL_GIVE:
|
||||||
payload := &message.Control{}
|
payload := &message.Control{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.controlGive(id, session, payload)
|
return h.controlGive(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
case event.CONTROL_CLIPBOARD:
|
case event.CONTROL_CLIPBOARD:
|
||||||
payload := &message.Clipboard{}
|
payload := &message.Clipboard{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.controlClipboard(id, session, payload)
|
return h.controlClipboard(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
case event.CONTROL_KEYBOARD:
|
case event.CONTROL_KEYBOARD:
|
||||||
payload := &message.Keyboard{}
|
payload := &message.Keyboard{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.controlKeyboard(id, session, payload)
|
return h.controlKeyboard(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
|
|
||||||
// Screen Events
|
// Screen Events
|
||||||
case event.SCREEN_RESOLUTION:
|
case event.SCREEN_RESOLUTION:
|
||||||
return errors.Wrapf(h.screenResolution(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.screenResolution(session), "%s failed", header.Event)
|
||||||
case event.SCREEN_CONFIGURATIONS:
|
case event.SCREEN_CONFIGURATIONS:
|
||||||
return errors.Wrapf(h.screenConfigurations(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.screenConfigurations(session), "%s failed", header.Event)
|
||||||
case event.SCREEN_SET:
|
case event.SCREEN_SET:
|
||||||
payload := &message.ScreenResolution{}
|
payload := &message.ScreenResolution{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.screenSet(id, session, payload)
|
return h.screenSet(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
|
|
||||||
// Boradcast Events
|
// Boradcast Events
|
||||||
@ -121,42 +121,42 @@ func (h *MessageHandler) Message(id string, raw []byte) error {
|
|||||||
|
|
||||||
// Admin Events
|
// Admin Events
|
||||||
case event.ADMIN_LOCK:
|
case event.ADMIN_LOCK:
|
||||||
return errors.Wrapf(h.adminLock(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.adminLock(session), "%s failed", header.Event)
|
||||||
case event.ADMIN_UNLOCK:
|
case event.ADMIN_UNLOCK:
|
||||||
return errors.Wrapf(h.adminUnlock(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.adminUnlock(session), "%s failed", header.Event)
|
||||||
case event.ADMIN_CONTROL:
|
case event.ADMIN_CONTROL:
|
||||||
return errors.Wrapf(h.adminControl(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.adminControl(session), "%s failed", header.Event)
|
||||||
case event.ADMIN_RELEASE:
|
case event.ADMIN_RELEASE:
|
||||||
return errors.Wrapf(h.adminRelease(id, session), "%s failed", header.Event)
|
return errors.Wrapf(h.adminRelease(session), "%s failed", header.Event)
|
||||||
case event.ADMIN_GIVE:
|
case event.ADMIN_GIVE:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.adminGive(id, session, payload)
|
return h.adminGive(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
case event.ADMIN_BAN:
|
case event.ADMIN_BAN:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.adminBan(id, session, payload)
|
return h.adminBan(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
case event.ADMIN_KICK:
|
case event.ADMIN_KICK:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.adminKick(id, session, payload)
|
return h.adminKick(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
case event.ADMIN_MUTE:
|
case event.ADMIN_MUTE:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.adminMute(id, session, payload)
|
return h.adminMute(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
case event.ADMIN_UNMUTE:
|
case event.ADMIN_UNMUTE:
|
||||||
payload := &message.Admin{}
|
payload := &message.Admin{}
|
||||||
return errors.Wrapf(
|
return errors.Wrapf(
|
||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.adminUnmute(id, session, payload)
|
return h.adminUnmute(session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
default:
|
default:
|
||||||
return errors.Errorf("unknown message event %s", header.Event)
|
return errors.Errorf("unknown message event %s", header.Event)
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"demodesk/neko/internal/websocket/broadcast"
|
"demodesk/neko/internal/websocket/broadcast"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandler) screenSet(id string, session types.Session, payload *message.ScreenResolution) error {
|
func (h *MessageHandler) screenSet(session types.Session, payload *message.ScreenResolution) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
@ -18,7 +18,7 @@ func (h *MessageHandler) screenSet(id string, session types.Session, payload *me
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := broadcast.ScreenConfiguration(h.sessions, id, payload.Width, payload.Height, payload.Rate); err != nil {
|
if err := broadcast.ScreenConfiguration(h.sessions, session.ID(), payload.Width, payload.Height, payload.Rate); err != nil {
|
||||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.SCREEN_RESOLUTION)
|
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.SCREEN_RESOLUTION)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -26,7 +26,7 @@ func (h *MessageHandler) screenSet(id string, session types.Session, payload *me
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) screenResolution(id string, session types.Session) error {
|
func (h *MessageHandler) screenResolution(session types.Session) error {
|
||||||
if size := h.remote.GetScreenSize(); size != nil {
|
if size := h.remote.GetScreenSize(); size != nil {
|
||||||
if err := session.Send(message.ScreenResolution{
|
if err := session.Send(message.ScreenResolution{
|
||||||
Event: event.SCREEN_RESOLUTION,
|
Event: event.SCREEN_RESOLUTION,
|
||||||
@ -42,7 +42,7 @@ func (h *MessageHandler) screenResolution(id string, session types.Session) erro
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) screenConfigurations(id string, session types.Session) error {
|
func (h *MessageHandler) screenConfigurations(session types.Session) error {
|
||||||
if !session.Admin() {
|
if !session.Admin() {
|
||||||
h.logger.Debug().Msg("user not admin")
|
h.logger.Debug().Msg("user not admin")
|
||||||
return nil
|
return nil
|
||||||
|
@ -6,15 +6,15 @@ import (
|
|||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandler) SessionCreated(id string, session types.Session) error {
|
func (h *MessageHandler) SessionCreated(session types.Session) error {
|
||||||
// send sdp and id over to client
|
// send sdp and id over to client
|
||||||
if err := h.signalProvide(id, session); err != nil {
|
if err := h.signalProvide(session); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if session.Admin() {
|
if session.Admin() {
|
||||||
// send screen configurations if admin
|
// send screen configurations if admin
|
||||||
if err := h.screenConfigurations(id, session); err != nil {
|
if err := h.screenConfigurations(session); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,18 +27,18 @@ func (h *MessageHandler) SessionCreated(id string, session types.Session) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) SessionConnected(id string, session types.Session) error {
|
func (h *MessageHandler) SessionConnected(session types.Session) error {
|
||||||
// send list of members to session
|
// send list of members to session
|
||||||
if err := session.Send(message.MembersList{
|
if err := session.Send(message.MembersList{
|
||||||
Event: event.MEMBER_LIST,
|
Event: event.MEMBER_LIST,
|
||||||
Memebers: h.sessions.Members(),
|
Memebers: h.sessions.Members(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.MEMBER_LIST)
|
h.logger.Warn().Str("id", session.ID()).Err(err).Msgf("sending event %s has failed", event.MEMBER_LIST)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// send screen current resolution
|
// send screen current resolution
|
||||||
if err := h.screenResolution(id, session); err != nil {
|
if err := h.screenResolution(session); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ func (h *MessageHandler) SessionConnected(id string, session types.Session) erro
|
|||||||
Event: event.CONTROL_LOCKED,
|
Event: event.CONTROL_LOCKED,
|
||||||
ID: host.ID(),
|
ID: host.ID(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.CONTROL_LOCKED)
|
h.logger.Warn().Str("id", session.ID()).Err(err).Msgf("sending event %s has failed", event.CONTROL_LOCKED)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,15 @@ import (
|
|||||||
"demodesk/neko/internal/types/message"
|
"demodesk/neko/internal/types/message"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
func (h *MessageHandler) signalProvide(session types.Session) error {
|
||||||
sdp, lite, ice, err := h.webrtc.CreatePeer(id, session)
|
sdp, lite, ice, err := h.webrtc.CreatePeer(session.ID(), session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := session.Send(message.SignalProvide{
|
if err := session.Send(message.SignalProvide{
|
||||||
Event: event.SIGNAL_PROVIDE,
|
Event: event.SIGNAL_PROVIDE,
|
||||||
ID: id,
|
ID: session.ID(),
|
||||||
SDP: sdp,
|
SDP: sdp,
|
||||||
Lite: lite,
|
Lite: lite,
|
||||||
ICE: ice,
|
ICE: ice,
|
||||||
@ -25,7 +25,7 @@ func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandler) signalAnswer(id string, session types.Session, payload *message.SignalAnswer) error {
|
func (h *MessageHandler) signalAnswer(session types.Session, payload *message.SignalAnswer) error {
|
||||||
session.SetName(payload.DisplayName)
|
session.SetName(payload.DisplayName)
|
||||||
|
|
||||||
if err := session.SignalAnswer(payload.SDP); err != nil {
|
if err := session.SignalAnswer(payload.SDP); err != nil {
|
||||||
|
@ -56,7 +56,7 @@ type WebSocketHandler struct {
|
|||||||
|
|
||||||
func (ws *WebSocketHandler) Start() {
|
func (ws *WebSocketHandler) Start() {
|
||||||
ws.sessions.OnCreated(func(id string, session types.Session) {
|
ws.sessions.OnCreated(func(id string, session types.Session) {
|
||||||
if err := ws.handler.SessionCreated(id, session); err != nil {
|
if err := ws.handler.SessionCreated(session); err != nil {
|
||||||
ws.logger.Warn().Str("id", id).Err(err).Msg("session created with and error")
|
ws.logger.Warn().Str("id", id).Err(err).Msg("session created with and error")
|
||||||
} else {
|
} else {
|
||||||
ws.logger.Debug().Str("id", id).Msg("session created")
|
ws.logger.Debug().Str("id", id).Msg("session created")
|
||||||
@ -64,7 +64,7 @@ func (ws *WebSocketHandler) Start() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ws.sessions.OnConnected(func(id string, session types.Session) {
|
ws.sessions.OnConnected(func(id string, session types.Session) {
|
||||||
if err := ws.handler.SessionConnected(id, session); err != nil {
|
if err := ws.handler.SessionConnected(session); err != nil {
|
||||||
ws.logger.Warn().Str("id", id).Err(err).Msg("session connected with and error")
|
ws.logger.Warn().Str("id", id).Err(err).Msg("session connected with and error")
|
||||||
} else {
|
} else {
|
||||||
ws.logger.Debug().Str("id", id).Msg("session connected")
|
ws.logger.Debug().Str("id", id).Msg("session connected")
|
||||||
|
Loading…
Reference in New Issue
Block a user