2021-01-20 23:48:50 +01:00
|
|
|
package websocket
|
|
|
|
|
|
|
|
import (
|
2022-07-14 00:58:22 +02:00
|
|
|
"github.com/demodesk/neko/pkg/types"
|
|
|
|
"github.com/demodesk/neko/pkg/types/event"
|
|
|
|
"github.com/demodesk/neko/pkg/types/message"
|
2021-01-20 23:48:50 +01:00
|
|
|
)
|
|
|
|
|
2021-02-14 17:11:21 +01:00
|
|
|
func (manager *WebSocketManagerCtx) fileChooserDialogEvents() {
|
2021-03-13 23:27:28 +01:00
|
|
|
var activeSession types.Session
|
2021-01-20 23:48:50 +01:00
|
|
|
|
|
|
|
// when dialog opens, everyone should be notified.
|
2021-02-14 17:11:21 +01:00
|
|
|
manager.desktop.OnFileChooserDialogOpened(func() {
|
2021-08-29 18:23:58 +02:00
|
|
|
manager.logger.Info().Msg("file chooser dialog opened")
|
2021-01-20 23:48:50 +01:00
|
|
|
|
2022-08-26 20:16:40 +02:00
|
|
|
host, hasHost := manager.sessions.GetHost()
|
|
|
|
if !hasHost {
|
2021-08-29 18:23:58 +02:00
|
|
|
manager.logger.Warn().Msg("no host for file chooser dialog found, closing")
|
2021-02-14 17:11:21 +01:00
|
|
|
go manager.desktop.CloseFileChooserDialog()
|
2021-01-20 23:48:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-13 23:27:28 +01:00
|
|
|
activeSession = host
|
2021-01-20 23:48:50 +01:00
|
|
|
|
2021-09-01 21:58:39 +02:00
|
|
|
go manager.sessions.Broadcast(
|
|
|
|
event.FILE_CHOOSER_DIALOG_OPENED,
|
|
|
|
message.SessionID{
|
|
|
|
ID: host.ID(),
|
2022-07-28 12:20:20 +02:00
|
|
|
})
|
2021-01-20 23:48:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// when dialog closes, everyone should be notified.
|
2021-02-14 17:11:21 +01:00
|
|
|
manager.desktop.OnFileChooserDialogClosed(func() {
|
2021-08-29 18:23:58 +02:00
|
|
|
manager.logger.Info().Msg("file chooser dialog closed")
|
2021-01-20 23:48:50 +01:00
|
|
|
|
2021-03-13 23:27:28 +01:00
|
|
|
activeSession = nil
|
2021-01-20 23:48:50 +01:00
|
|
|
|
2021-09-01 21:58:39 +02:00
|
|
|
go manager.sessions.Broadcast(
|
|
|
|
event.FILE_CHOOSER_DIALOG_CLOSED,
|
2022-07-28 12:20:20 +02:00
|
|
|
message.SessionID{})
|
2021-01-20 23:48:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// when new user joins, and someone holds dialog, he shouldd be notified about it.
|
2021-02-14 17:11:21 +01:00
|
|
|
manager.sessions.OnConnected(func(session types.Session) {
|
2021-03-13 23:27:28 +01:00
|
|
|
if activeSession == nil {
|
2021-01-20 23:48:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-01 21:58:39 +02:00
|
|
|
manager.logger.Debug().Str("session_id", session.ID()).Msg("sending file chooser dialog status to a new session")
|
2021-08-29 18:23:58 +02:00
|
|
|
|
2021-09-01 21:58:39 +02:00
|
|
|
session.Send(
|
|
|
|
event.FILE_CHOOSER_DIALOG_OPENED,
|
|
|
|
message.SessionID{
|
|
|
|
ID: activeSession.ID(),
|
|
|
|
})
|
2021-01-20 23:48:50 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
// when user, that holds dialog, disconnects, it should be closed.
|
2021-02-14 17:11:21 +01:00
|
|
|
manager.sessions.OnDisconnected(func(session types.Session) {
|
2021-03-13 23:27:28 +01:00
|
|
|
if activeSession == nil || activeSession != session {
|
2021-01-20 23:48:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-29 18:23:58 +02:00
|
|
|
manager.logger.Info().Msg("file chooser dialog owner left, closing")
|
2021-02-14 17:11:21 +01:00
|
|
|
manager.desktop.CloseFileChooserDialog()
|
2021-01-20 23:48:50 +01:00
|
|
|
})
|
|
|
|
}
|