mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
fix logs, unified session_id.
This commit is contained in:
parent
cacdd9e20a
commit
d83e04e7ec
@ -84,7 +84,7 @@ func (session *SessionCtx) profileChanged() {
|
||||
// ---
|
||||
|
||||
func (session *SessionCtx) IsHost() bool {
|
||||
return session.manager.host != nil && session.manager.host.ID() == session.ID()
|
||||
return session.manager.host != nil && session.manager.host == session
|
||||
}
|
||||
|
||||
func (session *SessionCtx) IsConnected() bool {
|
||||
|
@ -107,7 +107,7 @@ func (manager *WebRTCManagerCtx) ICEServers() []string {
|
||||
}
|
||||
|
||||
func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID string) (*webrtc.SessionDescription, error) {
|
||||
logger := manager.logger.With().Str("id", session.ID()).Logger()
|
||||
logger := manager.logger.With().Str("session_id", session.ID()).Logger()
|
||||
|
||||
// Create MediaEngine
|
||||
engine, err := manager.mediaEngine(videoID)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
||||
var file_chooser_dialog_member types.Session
|
||||
var activeSession types.Session
|
||||
|
||||
// when dialog opens, everyone should be notified.
|
||||
manager.desktop.OnFileChooserDialogOpened(func() {
|
||||
@ -20,7 +20,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
||||
return
|
||||
}
|
||||
|
||||
file_chooser_dialog_member = host
|
||||
activeSession = host
|
||||
|
||||
go manager.sessions.Broadcast(message.MemberID{
|
||||
Event: event.FILE_CHOOSER_DIALOG_OPENED,
|
||||
@ -32,7 +32,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
||||
manager.desktop.OnFileChooserDialogClosed(func() {
|
||||
manager.logger.Info().Msg("FileChooserDialog closed")
|
||||
|
||||
file_chooser_dialog_member = nil
|
||||
activeSession = nil
|
||||
|
||||
go manager.sessions.Broadcast(message.MemberID{
|
||||
Event: event.FILE_CHOOSER_DIALOG_CLOSED,
|
||||
@ -41,16 +41,16 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
||||
|
||||
// when new user joins, and someone holds dialog, he shouldd be notified about it.
|
||||
manager.sessions.OnConnected(func(session types.Session) {
|
||||
if file_chooser_dialog_member == nil {
|
||||
if activeSession == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := session.Send(message.MemberID{
|
||||
Event: event.FILE_CHOOSER_DIALOG_OPENED,
|
||||
ID: file_chooser_dialog_member.ID(),
|
||||
ID: activeSession.ID(),
|
||||
}); err != nil {
|
||||
manager.logger.Warn().
|
||||
Str("id", session.ID()).
|
||||
Str("session_id", session.ID()).
|
||||
Err(err).
|
||||
Msgf("could not send event `%s` to session", event.FILE_CHOOSER_DIALOG_OPENED)
|
||||
}
|
||||
@ -58,11 +58,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
||||
|
||||
// when user, that holds dialog, disconnects, it should be closed.
|
||||
manager.sessions.OnDisconnected(func(session types.Session) {
|
||||
if file_chooser_dialog_member == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if session.ID() != file_chooser_dialog_member.ID() {
|
||||
if activeSession == nil || activeSession != session {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -7,12 +7,12 @@ import (
|
||||
|
||||
func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message.ClipboardData) error {
|
||||
if !session.CanAccessClipboard() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("cannot access clipboard")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("cannot access clipboard")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -8,12 +8,12 @@ import (
|
||||
|
||||
func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
|
||||
if !session.CanHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not allowed to host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is not allowed to host")
|
||||
return nil
|
||||
}
|
||||
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -25,12 +25,12 @@ func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
|
||||
|
||||
func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
|
||||
if !session.CanHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not allowed to host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is not allowed to host")
|
||||
return nil
|
||||
}
|
||||
|
||||
if session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is already the host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is already the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
func (h *MessageHandlerCtx) keyboardMap(session types.Session, payload *message.KeyboardMap) error {
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ func (h *MessageHandlerCtx) keyboardMap(session types.Session, payload *message.
|
||||
|
||||
func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {
|
||||
if !session.IsHost() {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("is not the host")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error {
|
||||
receiver, ok := h.sessions.Get(payload.Receiver)
|
||||
if !ok {
|
||||
h.logger.Debug().Str("id", session.ID()).Msg("receiver ID not found")
|
||||
h.logger.Debug().Str("session_id", session.ID()).Msg("receiver session ID not found")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -25,8 +25,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
|
||||
|
||||
members := map[string]message.MemberData{}
|
||||
for _, session := range h.sessions.List() {
|
||||
members[session.ID()] = message.MemberData{
|
||||
ID: session.ID(),
|
||||
memberId := session.ID()
|
||||
members[memberId] = message.MemberData{
|
||||
ID: memberId,
|
||||
Profile: session.GetProfile(),
|
||||
State: session.GetState(),
|
||||
}
|
||||
|
@ -46,49 +46,49 @@ type WebSocketManagerCtx struct {
|
||||
func (manager *WebSocketManagerCtx) Start() {
|
||||
manager.sessions.OnCreated(func(session types.Session) {
|
||||
if err := manager.handler.SessionCreated(session); err != nil {
|
||||
manager.logger.Warn().Str("id", session.ID()).Err(err).Msg("session created with an error")
|
||||
manager.logger.Warn().Str("session_id", session.ID()).Err(err).Msg("session created with an error")
|
||||
} else {
|
||||
manager.logger.Debug().Str("id", session.ID()).Msg("session created")
|
||||
manager.logger.Debug().Str("session_id", session.ID()).Msg("session created")
|
||||
}
|
||||
})
|
||||
|
||||
manager.sessions.OnDeleted(func(session types.Session) {
|
||||
if err := manager.handler.SessionDeleted(session); err != nil {
|
||||
manager.logger.Warn().Str("id", session.ID()).Err(err).Msg("session deleted with an error")
|
||||
manager.logger.Warn().Str("session_id", session.ID()).Err(err).Msg("session deleted with an error")
|
||||
} else {
|
||||
manager.logger.Debug().Str("id", session.ID()).Msg("session deleted")
|
||||
manager.logger.Debug().Str("session_id", session.ID()).Msg("session deleted")
|
||||
}
|
||||
})
|
||||
|
||||
manager.sessions.OnConnected(func(session types.Session) {
|
||||
if err := manager.handler.SessionConnected(session); err != nil {
|
||||
manager.logger.Warn().Str("id", session.ID()).Err(err).Msg("session connected with an error")
|
||||
manager.logger.Warn().Str("session_id", session.ID()).Err(err).Msg("session connected with an error")
|
||||
} else {
|
||||
manager.logger.Debug().Str("id", session.ID()).Msg("session connected")
|
||||
manager.logger.Debug().Str("session_id", session.ID()).Msg("session connected")
|
||||
}
|
||||
})
|
||||
|
||||
manager.sessions.OnDisconnected(func(session types.Session) {
|
||||
if err := manager.handler.SessionDisconnected(session); err != nil {
|
||||
manager.logger.Warn().Str("id", session.ID()).Err(err).Msg("session disconnected with an error")
|
||||
manager.logger.Warn().Str("session_id", session.ID()).Err(err).Msg("session disconnected with an error")
|
||||
} else {
|
||||
manager.logger.Debug().Str("id", session.ID()).Msg("session disconnected")
|
||||
manager.logger.Debug().Str("session_id", session.ID()).Msg("session disconnected")
|
||||
}
|
||||
})
|
||||
|
||||
manager.sessions.OnProfileChanged(func(session types.Session) {
|
||||
if err := manager.handler.SessionProfileChanged(session); err != nil {
|
||||
manager.logger.Warn().Str("id", session.ID()).Err(err).Msg("session profile changed with an error")
|
||||
manager.logger.Warn().Str("session_id", session.ID()).Err(err).Msg("session profile changed with an error")
|
||||
} else {
|
||||
manager.logger.Debug().Str("id", session.ID()).Msg("session profile changed")
|
||||
manager.logger.Debug().Str("session_id", session.ID()).Msg("session profile changed")
|
||||
}
|
||||
})
|
||||
|
||||
manager.sessions.OnStateChanged(func(session types.Session) {
|
||||
if err := manager.handler.SessionStateChanged(session); err != nil {
|
||||
manager.logger.Warn().Str("id", session.ID()).Err(err).Msg("session state changed with an error")
|
||||
manager.logger.Warn().Str("session_id", session.ID()).Err(err).Msg("session state changed with an error")
|
||||
} else {
|
||||
manager.logger.Debug().Str("id", session.ID()).Msg("session state changed")
|
||||
manager.logger.Debug().Str("session_id", session.ID()).Msg("session state changed")
|
||||
}
|
||||
})
|
||||
|
||||
@ -201,7 +201,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
||||
|
||||
manager.logger.
|
||||
Debug().
|
||||
Str("session", session.ID()).
|
||||
Str("session_id", session.ID()).
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Msg("connection started")
|
||||
|
||||
@ -210,7 +210,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
|
||||
defer func() {
|
||||
manager.logger.
|
||||
Debug().
|
||||
Str("session", session.ID()).
|
||||
Str("session_id", session.ID()).
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Msg("connection ended")
|
||||
|
||||
@ -250,7 +250,7 @@ func (manager *WebSocketManagerCtx) handle(connection *websocket.Conn, session t
|
||||
select {
|
||||
case raw := <-bytes:
|
||||
manager.logger.Debug().
|
||||
Str("session", session.ID()).
|
||||
Str("session_id", session.ID()).
|
||||
Str("address", connection.RemoteAddr().String()).
|
||||
Str("raw", string(raw)).
|
||||
Msg("received message from client")
|
||||
|
@ -30,7 +30,7 @@ func (peer *WebSocketPeerCtx) Send(v interface{}) error {
|
||||
}
|
||||
|
||||
peer.manager.logger.Debug().
|
||||
Str("session", peer.session.ID()).
|
||||
Str("session_id", peer.session.ID()).
|
||||
Str("address", peer.connection.RemoteAddr().String()).
|
||||
Str("raw", string(raw)).
|
||||
Msg("sending message to client")
|
||||
|
Loading…
Reference in New Issue
Block a user