mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
refactor session remove redundant IDs.
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
|
||||
func (h *MessageHandler) controlRelease(session types.Session) error {
|
||||
// check if session is host
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
@ -80,7 +80,7 @@ func (h *MessageHandler) controlRequest(session types.Session) error {
|
||||
|
||||
func (h *MessageHandler) controlGive(session types.Session, payload *message.Control) error {
|
||||
// check if session is host
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
@ -112,7 +112,7 @@ func (h *MessageHandler) controlGive(session types.Session, payload *message.Con
|
||||
|
||||
func (h *MessageHandler) controlClipboard(session types.Session, payload *message.Clipboard) error {
|
||||
// check if session is host
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
@ -123,7 +123,7 @@ func (h *MessageHandler) controlClipboard(session types.Session, payload *messag
|
||||
|
||||
func (h *MessageHandler) controlKeyboard(session types.Session, payload *message.Keyboard) error {
|
||||
// check if session is host
|
||||
if !h.sessions.IsHost(session.ID()) {
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
@ -67,13 +67,13 @@ func (h *MessageHandler) SessionConnected(session types.Session) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *MessageHandler) SessionDestroyed(id string) error {
|
||||
func (h *MessageHandler) SessionDestroyed(session types.Session) error {
|
||||
// clear host if exists
|
||||
if h.sessions.IsHost(id) {
|
||||
if session.IsHost() {
|
||||
h.sessions.ClearHost()
|
||||
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)
|
||||
}
|
||||
@ -83,7 +83,7 @@ func (h *MessageHandler) SessionDestroyed(id string) error {
|
||||
if err := h.sessions.Broadcast(
|
||||
message.MemberDisconnected{
|
||||
Event: event.MEMBER_DISCONNECTED,
|
||||
ID: id,
|
||||
ID: session.ID(),
|
||||
}, nil); err != nil {
|
||||
h.logger.Warn().Err(err).Msgf("broadcasting event %s has failed", event.MEMBER_DISCONNECTED)
|
||||
return err
|
||||
|
@ -55,27 +55,27 @@ type WebSocketHandler struct {
|
||||
}
|
||||
|
||||
func (ws *WebSocketHandler) Start() {
|
||||
ws.sessions.OnCreated(func(id string, session types.Session) {
|
||||
ws.sessions.OnCreated(func(session types.Session) {
|
||||
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", session.ID()).Err(err).Msg("session created with and error")
|
||||
} else {
|
||||
ws.logger.Debug().Str("id", id).Msg("session created")
|
||||
ws.logger.Debug().Str("id", session.ID()).Msg("session created")
|
||||
}
|
||||
})
|
||||
|
||||
ws.sessions.OnConnected(func(id string, session types.Session) {
|
||||
ws.sessions.OnConnected(func(session types.Session) {
|
||||
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", session.ID()).Err(err).Msg("session connected with and error")
|
||||
} else {
|
||||
ws.logger.Debug().Str("id", id).Msg("session connected")
|
||||
ws.logger.Debug().Str("id", session.ID()).Msg("session connected")
|
||||
}
|
||||
})
|
||||
|
||||
ws.sessions.OnDestroy(func(id string, session types.Session) {
|
||||
if err := ws.handler.SessionDestroyed(id); err != nil {
|
||||
ws.logger.Warn().Str("id", id).Err(err).Msg("session destroyed with and error")
|
||||
ws.sessions.OnBeforeDestroy(func(session types.Session) {
|
||||
if err := ws.handler.SessionDestroyed(session); err != nil {
|
||||
ws.logger.Warn().Str("id", session.ID()).Err(err).Msg("session destroyed with and error")
|
||||
} else {
|
||||
ws.logger.Debug().Str("id", id).Msg("session destroyed")
|
||||
ws.logger.Debug().Str("id", session.ID()).Msg("session destroyed")
|
||||
}
|
||||
})
|
||||
|
||||
|
Reference in New Issue
Block a user