mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
filechooser websocket handler.
This commit is contained in:
parent
dbbbc85c18
commit
64dd31844b
@ -51,3 +51,8 @@ const (
|
|||||||
const (
|
const (
|
||||||
BORADCAST_STATUS = "broadcast/status"
|
BORADCAST_STATUS = "broadcast/status"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
FILE_CHOOSER_DIALOG_OPENED = "file_chooser_dialog/opened"
|
||||||
|
FILE_CHOOSER_DIALOG_CLOSED = "file_chooser_dialog/closed"
|
||||||
|
)
|
||||||
|
72
internal/websocket/filechooserdialog.go
Normal file
72
internal/websocket/filechooserdialog.go
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
package websocket
|
||||||
|
|
||||||
|
import (
|
||||||
|
"demodesk/neko/internal/types"
|
||||||
|
"demodesk/neko/internal/types/event"
|
||||||
|
"demodesk/neko/internal/types/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (ws *WebSocketManagerCtx) fileChooserDialogEvents() {
|
||||||
|
var file_chooser_dialog_member types.Session
|
||||||
|
|
||||||
|
// when dialog opens, everyone should be notified.
|
||||||
|
ws.desktop.OnFileChooserDialogOpened(func() {
|
||||||
|
ws.logger.Info().Msg("FileChooserDialog opened")
|
||||||
|
|
||||||
|
host := ws.sessions.GetHost()
|
||||||
|
if host == nil {
|
||||||
|
ws.logger.Warn().Msg("no host for FileChooserDialog found, closing")
|
||||||
|
go ws.desktop.CloseFileChooserDialog()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
file_chooser_dialog_member = host
|
||||||
|
|
||||||
|
go ws.sessions.Broadcast(message.MemberID{
|
||||||
|
Event: event.FILE_CHOOSER_DIALOG_OPENED,
|
||||||
|
ID: host.ID(),
|
||||||
|
}, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
// when dialog closes, everyone should be notified.
|
||||||
|
ws.desktop.OnFileChooserDialogClosed(func() {
|
||||||
|
ws.logger.Info().Msg("FileChooserDialog closed")
|
||||||
|
|
||||||
|
file_chooser_dialog_member = nil
|
||||||
|
|
||||||
|
go ws.sessions.Broadcast(message.MemberID{
|
||||||
|
Event: event.FILE_CHOOSER_DIALOG_CLOSED,
|
||||||
|
}, nil)
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// when new user joins, and someone holds dialog, he shouldd be notified about it.
|
||||||
|
ws.sessions.OnConnected(func(session types.Session) {
|
||||||
|
if file_chooser_dialog_member == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := session.Send(message.MemberID{
|
||||||
|
Event: event.FILE_CHOOSER_DIALOG_OPENED,
|
||||||
|
ID: file_chooser_dialog_member.ID(),
|
||||||
|
}); err != nil {
|
||||||
|
ws.logger.Warn().
|
||||||
|
Str("id", session.ID()).
|
||||||
|
Err(err).
|
||||||
|
Msgf("could not send event `%s` to session", event.FILE_CHOOSER_DIALOG_OPENED)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// when user, that holds dialog, disconnects, it should be closed.
|
||||||
|
ws.sessions.OnDisconnected(func(session types.Session) {
|
||||||
|
if file_chooser_dialog_member == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if session.ID() != file_chooser_dialog_member.ID() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.desktop.CloseFileChooserDialog()
|
||||||
|
})
|
||||||
|
}
|
@ -134,17 +134,7 @@ func (ws *WebSocketManagerCtx) Start() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ws.desktop.OnFileChooserDialogOpened(func() {
|
ws.fileChooserDialogEvents()
|
||||||
// TODO: Implement.
|
|
||||||
ws.logger.Info().
|
|
||||||
Msg("FileChooserDialog opened")
|
|
||||||
})
|
|
||||||
|
|
||||||
ws.desktop.OnFileChooserDialogClosed(func() {
|
|
||||||
// TODO: Implement.
|
|
||||||
ws.logger.Info().
|
|
||||||
Msg("FileChooserDialog closed")
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ws *WebSocketManagerCtx) Shutdown() error {
|
func (ws *WebSocketManagerCtx) Shutdown() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user