fix logs, unified session_id.

This commit is contained in:
Miroslav Šedivý 2021-03-13 23:27:28 +01:00
parent cacdd9e20a
commit d83e04e7ec
10 changed files with 37 additions and 40 deletions

View File

@ -84,7 +84,7 @@ func (session *SessionCtx) profileChanged() {
// --- // ---
func (session *SessionCtx) IsHost() bool { 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 { func (session *SessionCtx) IsConnected() bool {

View File

@ -107,7 +107,7 @@ func (manager *WebRTCManagerCtx) ICEServers() []string {
} }
func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID string) (*webrtc.SessionDescription, error) { 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 // Create MediaEngine
engine, err := manager.mediaEngine(videoID) engine, err := manager.mediaEngine(videoID)

View File

@ -7,7 +7,7 @@ import (
) )
func (manager *WebSocketManagerCtx) fileChooserDialogEvents() { func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
var file_chooser_dialog_member types.Session var activeSession types.Session
// when dialog opens, everyone should be notified. // when dialog opens, everyone should be notified.
manager.desktop.OnFileChooserDialogOpened(func() { manager.desktop.OnFileChooserDialogOpened(func() {
@ -20,7 +20,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
return return
} }
file_chooser_dialog_member = host activeSession = host
go manager.sessions.Broadcast(message.MemberID{ go manager.sessions.Broadcast(message.MemberID{
Event: event.FILE_CHOOSER_DIALOG_OPENED, Event: event.FILE_CHOOSER_DIALOG_OPENED,
@ -32,7 +32,7 @@ func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
manager.desktop.OnFileChooserDialogClosed(func() { manager.desktop.OnFileChooserDialogClosed(func() {
manager.logger.Info().Msg("FileChooserDialog closed") manager.logger.Info().Msg("FileChooserDialog closed")
file_chooser_dialog_member = nil activeSession = nil
go manager.sessions.Broadcast(message.MemberID{ go manager.sessions.Broadcast(message.MemberID{
Event: event.FILE_CHOOSER_DIALOG_CLOSED, 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. // when new user joins, and someone holds dialog, he shouldd be notified about it.
manager.sessions.OnConnected(func(session types.Session) { manager.sessions.OnConnected(func(session types.Session) {
if file_chooser_dialog_member == nil { if activeSession == nil {
return return
} }
if err := session.Send(message.MemberID{ if err := session.Send(message.MemberID{
Event: event.FILE_CHOOSER_DIALOG_OPENED, Event: event.FILE_CHOOSER_DIALOG_OPENED,
ID: file_chooser_dialog_member.ID(), ID: activeSession.ID(),
}); err != nil { }); err != nil {
manager.logger.Warn(). manager.logger.Warn().
Str("id", session.ID()). Str("session_id", session.ID()).
Err(err). Err(err).
Msgf("could not send event `%s` to session", event.FILE_CHOOSER_DIALOG_OPENED) 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. // when user, that holds dialog, disconnects, it should be closed.
manager.sessions.OnDisconnected(func(session types.Session) { manager.sessions.OnDisconnected(func(session types.Session) {
if file_chooser_dialog_member == nil { if activeSession == nil || activeSession != session {
return
}
if session.ID() != file_chooser_dialog_member.ID() {
return return
} }

View File

@ -7,12 +7,12 @@ import (
func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message.ClipboardData) error { func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message.ClipboardData) error {
if !session.CanAccessClipboard() { 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 return nil
} }
if !session.IsHost() { 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 return nil
} }

View File

@ -8,12 +8,12 @@ import (
func (h *MessageHandlerCtx) controlRelease(session types.Session) error { func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
if !session.CanHost() { 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 return nil
} }
if !session.IsHost() { 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 return nil
} }
@ -25,12 +25,12 @@ func (h *MessageHandlerCtx) controlRelease(session types.Session) error {
func (h *MessageHandlerCtx) controlRequest(session types.Session) error { func (h *MessageHandlerCtx) controlRequest(session types.Session) error {
if !session.CanHost() { 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 return nil
} }
if session.IsHost() { 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 return nil
} }

View File

@ -7,7 +7,7 @@ import (
func (h *MessageHandlerCtx) keyboardMap(session types.Session, payload *message.KeyboardMap) error { func (h *MessageHandlerCtx) keyboardMap(session types.Session, payload *message.KeyboardMap) error {
if !session.IsHost() { 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 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 { func (h *MessageHandlerCtx) keyboardModifiers(session types.Session, payload *message.KeyboardModifiers) error {
if !session.IsHost() { 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 return nil
} }

View File

@ -9,7 +9,7 @@ import (
func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error { func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error {
receiver, ok := h.sessions.Get(payload.Receiver) receiver, ok := h.sessions.Get(payload.Receiver)
if !ok { 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 return nil
} }

View File

@ -25,8 +25,9 @@ func (h *MessageHandlerCtx) systemInit(session types.Session) error {
members := map[string]message.MemberData{} members := map[string]message.MemberData{}
for _, session := range h.sessions.List() { for _, session := range h.sessions.List() {
members[session.ID()] = message.MemberData{ memberId := session.ID()
ID: session.ID(), members[memberId] = message.MemberData{
ID: memberId,
Profile: session.GetProfile(), Profile: session.GetProfile(),
State: session.GetState(), State: session.GetState(),
} }

View File

@ -46,49 +46,49 @@ type WebSocketManagerCtx struct {
func (manager *WebSocketManagerCtx) Start() { func (manager *WebSocketManagerCtx) Start() {
manager.sessions.OnCreated(func(session types.Session) { manager.sessions.OnCreated(func(session types.Session) {
if err := manager.handler.SessionCreated(session); err != nil { 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 { } 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) { manager.sessions.OnDeleted(func(session types.Session) {
if err := manager.handler.SessionDeleted(session); err != nil { 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 { } 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) { manager.sessions.OnConnected(func(session types.Session) {
if err := manager.handler.SessionConnected(session); err != nil { 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 { } 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) { manager.sessions.OnDisconnected(func(session types.Session) {
if err := manager.handler.SessionDisconnected(session); err != nil { 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 { } 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) { manager.sessions.OnProfileChanged(func(session types.Session) {
if err := manager.handler.SessionProfileChanged(session); err != nil { 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 { } 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) { manager.sessions.OnStateChanged(func(session types.Session) {
if err := manager.handler.SessionStateChanged(session); err != nil { 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 { } 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. manager.logger.
Debug(). Debug().
Str("session", session.ID()). Str("session_id", session.ID()).
Str("address", connection.RemoteAddr().String()). Str("address", connection.RemoteAddr().String()).
Msg("connection started") Msg("connection started")
@ -210,7 +210,7 @@ func (manager *WebSocketManagerCtx) Upgrade(w http.ResponseWriter, r *http.Reque
defer func() { defer func() {
manager.logger. manager.logger.
Debug(). Debug().
Str("session", session.ID()). Str("session_id", session.ID()).
Str("address", connection.RemoteAddr().String()). Str("address", connection.RemoteAddr().String()).
Msg("connection ended") Msg("connection ended")
@ -250,7 +250,7 @@ func (manager *WebSocketManagerCtx) handle(connection *websocket.Conn, session t
select { select {
case raw := <-bytes: case raw := <-bytes:
manager.logger.Debug(). manager.logger.Debug().
Str("session", session.ID()). Str("session_id", session.ID()).
Str("address", connection.RemoteAddr().String()). Str("address", connection.RemoteAddr().String()).
Str("raw", string(raw)). Str("raw", string(raw)).
Msg("received message from client") Msg("received message from client")

View File

@ -30,7 +30,7 @@ func (peer *WebSocketPeerCtx) Send(v interface{}) error {
} }
peer.manager.logger.Debug(). peer.manager.logger.Debug().
Str("session", peer.session.ID()). Str("session_id", peer.session.ID()).
Str("address", peer.connection.RemoteAddr().String()). Str("address", peer.connection.RemoteAddr().String()).
Str("raw", string(raw)). Str("raw", string(raw)).
Msg("sending message to client") Msg("sending message to client")