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"
|
||||
)
|
||||
|
||||
func (h *MessageHandler) adminLock(id string, session types.Session) error {
|
||||
func (h *MessageHandler) adminLock(session types.Session) error {
|
||||
if !session.Admin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -24,7 +24,7 @@ func (h *MessageHandler) adminLock(id string, session types.Session) error {
|
||||
if err := h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_LOCK,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_LOCK)
|
||||
return err
|
||||
@ -33,7 +33,7 @@ func (h *MessageHandler) adminLock(id string, session types.Session) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) adminUnlock(id string, session types.Session) error {
|
||||
func (h *MessageHandler) adminUnlock(session types.Session) error {
|
||||
if !session.Admin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -49,7 +49,7 @@ func (h *MessageHandler) adminUnlock(id string, session types.Session) error {
|
||||
if err := h.sessions.Broadcast(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_UNLOCK,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNLOCK)
|
||||
return err
|
||||
@ -58,7 +58,7 @@ func (h *MessageHandler) adminUnlock(id string, session types.Session) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
||||
func (h *MessageHandler) adminControl(session types.Session) error {
|
||||
if !session.Admin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -66,7 +66,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
||||
|
||||
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")
|
||||
return err
|
||||
}
|
||||
@ -75,7 +75,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
||||
if err := h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_CONTROL,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
Target: host.ID(),
|
||||
}, nil); err != nil {
|
||||
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(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_CONTROL,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_CONTROL)
|
||||
return err
|
||||
@ -95,7 +95,7 @@ func (h *MessageHandler) adminControl(id string, session types.Session) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
||||
func (h *MessageHandler) adminRelease(session types.Session) error {
|
||||
if !session.Admin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -109,7 +109,7 @@ func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
||||
if err := h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_RELEASE,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
Target: host.ID(),
|
||||
}, nil); err != nil {
|
||||
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(
|
||||
message.Admin{
|
||||
Event: event.ADMIN_RELEASE,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_RELEASE)
|
||||
return err
|
||||
@ -129,7 +129,7 @@ func (h *MessageHandler) adminRelease(id string, session types.Session) error {
|
||||
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() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -150,7 +150,7 @@ func (h *MessageHandler) adminGive(id string, session types.Session, payload *me
|
||||
if err := h.sessions.Broadcast(
|
||||
message.AdminTarget{
|
||||
Event: event.CONTROL_GIVE,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
Target: payload.ID,
|
||||
}, nil); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -183,7 +183,7 @@ func (h *MessageHandler) adminMute(id string, session types.Session, payload *me
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_MUTE,
|
||||
Target: target.ID(),
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
|
||||
return err
|
||||
@ -192,7 +192,7 @@ func (h *MessageHandler) adminMute(id string, session types.Session, payload *me
|
||||
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() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -210,7 +210,7 @@ func (h *MessageHandler) adminUnmute(id string, session types.Session, payload *
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_UNMUTE,
|
||||
Target: target.ID(),
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.ADMIN_UNMUTE)
|
||||
return err
|
||||
@ -219,7 +219,7 @@ func (h *MessageHandler) adminUnmute(id string, session types.Session, payload *
|
||||
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() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -244,7 +244,7 @@ func (h *MessageHandler) adminKick(id string, session types.Session, payload *me
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_KICK,
|
||||
Target: target.ID(),
|
||||
ID: 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
|
||||
@ -253,7 +253,7 @@ func (h *MessageHandler) adminKick(id string, session types.Session, payload *me
|
||||
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() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -294,7 +294,7 @@ func (h *MessageHandler) adminBan(id string, session types.Session, payload *mes
|
||||
message.AdminTarget{
|
||||
Event: event.ADMIN_BAN,
|
||||
Target: target.ID(),
|
||||
ID: 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
|
||||
|
@ -6,23 +6,22 @@ import (
|
||||
"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
|
||||
if !h.sessions.IsHost(id) {
|
||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
||||
// tell everyone
|
||||
if err := h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_RELEASE,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_RELEASE)
|
||||
return err
|
||||
@ -31,11 +30,11 @@ func (h *MessageHandler) controlRelease(id string, session types.Session) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) controlRequest(id string, session types.Session) error {
|
||||
func (h *MessageHandler) controlRequest(session types.Session) error {
|
||||
// check for host
|
||||
if !h.sessions.HasHost() {
|
||||
// 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")
|
||||
return err
|
||||
}
|
||||
@ -44,7 +43,7 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
|
||||
if err := h.sessions.Broadcast(
|
||||
message.Control{
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.CONTROL_LOCKED)
|
||||
return err
|
||||
@ -62,14 +61,14 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
|
||||
Event: event.CONTROL_REQUEST,
|
||||
ID: host.ID(),
|
||||
}); 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
|
||||
}
|
||||
|
||||
// tell host session wants to be host
|
||||
if err := host.Send(message.Control{
|
||||
Event: event.CONTROL_REQUESTING,
|
||||
ID: id,
|
||||
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
|
||||
@ -79,10 +78,10 @@ func (h *MessageHandler) controlRequest(id string, session types.Session) error
|
||||
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
|
||||
if !h.sessions.IsHost(id) {
|
||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -101,7 +100,7 @@ func (h *MessageHandler) controlGive(id string, session types.Session, payload *
|
||||
if err := h.sessions.Broadcast(
|
||||
message.ControlTarget{
|
||||
Event: event.CONTROL_GIVE,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
Target: payload.ID,
|
||||
}, nil); err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
if !h.sessions.IsHost(id) {
|
||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -122,10 +121,10 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
|
||||
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
|
||||
if !h.sessions.IsHost(id) {
|
||||
h.logger.Debug().Str("id", id).Msg("is not the host")
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -70,43 +70,43 @@ func (h *MessageHandler) Message(id string, raw []byte) error {
|
||||
payload := &message.SignalAnswer{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.signalAnswer(id, session, payload)
|
||||
return h.signalAnswer(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
|
||||
// Control Events
|
||||
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:
|
||||
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:
|
||||
payload := &message.Control{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.controlGive(id, session, payload)
|
||||
return h.controlGive(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
case event.CONTROL_CLIPBOARD:
|
||||
payload := &message.Clipboard{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.controlClipboard(id, session, payload)
|
||||
return h.controlClipboard(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
case event.CONTROL_KEYBOARD:
|
||||
payload := &message.Keyboard{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.controlKeyboard(id, session, payload)
|
||||
return h.controlKeyboard(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
|
||||
// Screen Events
|
||||
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:
|
||||
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:
|
||||
payload := &message.ScreenResolution{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.screenSet(id, session, payload)
|
||||
return h.screenSet(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
|
||||
// Boradcast Events
|
||||
@ -121,42 +121,42 @@ func (h *MessageHandler) Message(id string, raw []byte) error {
|
||||
|
||||
// Admin Events
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
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:
|
||||
payload := &message.Admin{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminGive(id, session, payload)
|
||||
return h.adminGive(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
case event.ADMIN_BAN:
|
||||
payload := &message.Admin{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminBan(id, session, payload)
|
||||
return h.adminBan(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
case event.ADMIN_KICK:
|
||||
payload := &message.Admin{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminKick(id, session, payload)
|
||||
return h.adminKick(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
case event.ADMIN_MUTE:
|
||||
payload := &message.Admin{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminMute(id, session, payload)
|
||||
return h.adminMute(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
case event.ADMIN_UNMUTE:
|
||||
payload := &message.Admin{}
|
||||
return errors.Wrapf(
|
||||
utils.Unmarshal(payload, raw, func() error {
|
||||
return h.adminUnmute(id, session, payload)
|
||||
return h.adminUnmute(session, payload)
|
||||
}), "%s failed", header.Event)
|
||||
default:
|
||||
return errors.Errorf("unknown message event %s", header.Event)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"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() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
@ -18,7 +18,7 @@ func (h *MessageHandler) screenSet(id string, session types.Session, payload *me
|
||||
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)
|
||||
return err
|
||||
}
|
||||
@ -26,7 +26,7 @@ func (h *MessageHandler) screenSet(id string, session types.Session, payload *me
|
||||
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 err := session.Send(message.ScreenResolution{
|
||||
Event: event.SCREEN_RESOLUTION,
|
||||
@ -42,7 +42,7 @@ func (h *MessageHandler) screenResolution(id string, session types.Session) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) screenConfigurations(id string, session types.Session) error {
|
||||
func (h *MessageHandler) screenConfigurations(session types.Session) error {
|
||||
if !session.Admin() {
|
||||
h.logger.Debug().Msg("user not admin")
|
||||
return nil
|
||||
|
@ -6,15 +6,15 @@ import (
|
||||
"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
|
||||
if err := h.signalProvide(id, session); err != nil {
|
||||
if err := h.signalProvide(session); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if session.Admin() {
|
||||
// send screen configurations if admin
|
||||
if err := h.screenConfigurations(id, session); err != nil {
|
||||
if err := h.screenConfigurations(session); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -27,18 +27,18 @@ func (h *MessageHandler) SessionCreated(id string, session types.Session) error
|
||||
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
|
||||
if err := session.Send(message.MembersList{
|
||||
Event: event.MEMBER_LIST,
|
||||
Memebers: h.sessions.Members(),
|
||||
}); 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
|
||||
}
|
||||
|
||||
// send screen current resolution
|
||||
if err := h.screenResolution(id, session); err != nil {
|
||||
if err := h.screenResolution(session); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -49,7 +49,7 @@ func (h *MessageHandler) SessionConnected(id string, session types.Session) erro
|
||||
Event: event.CONTROL_LOCKED,
|
||||
ID: host.ID(),
|
||||
}); 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
|
||||
}
|
||||
}
|
||||
|
@ -6,15 +6,15 @@ import (
|
||||
"demodesk/neko/internal/types/message"
|
||||
)
|
||||
|
||||
func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
||||
sdp, lite, ice, err := h.webrtc.CreatePeer(id, session)
|
||||
func (h *MessageHandler) signalProvide(session types.Session) error {
|
||||
sdp, lite, ice, err := h.webrtc.CreatePeer(session.ID(), session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := session.Send(message.SignalProvide{
|
||||
Event: event.SIGNAL_PROVIDE,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
SDP: sdp,
|
||||
Lite: lite,
|
||||
ICE: ice,
|
||||
@ -25,7 +25,7 @@ func (h *MessageHandler) signalProvide(id string, session types.Session) error {
|
||||
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)
|
||||
|
||||
if err := session.SignalAnswer(payload.SDP); err != nil {
|
||||
|
@ -56,7 +56,7 @@ type WebSocketHandler struct {
|
||||
|
||||
func (ws *WebSocketHandler) Start() {
|
||||
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")
|
||||
} else {
|
||||
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) {
|
||||
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")
|
||||
} else {
|
||||
ws.logger.Debug().Str("id", id).Msg("session connected")
|
||||
|
Loading…
Reference in New Issue
Block a user