diff --git a/client/src/neko/events.ts b/client/src/neko/events.ts index a29f5805..7b637a69 100644 --- a/client/src/neko/events.ts +++ b/client/src/neko/events.ts @@ -10,6 +10,7 @@ export const EVENT = { // Websocket Events SYSTEM: { + INIT: 'system/init', DISCONNECT: 'system/disconnect', ERROR: 'system/error', }, diff --git a/client/src/neko/index.ts b/client/src/neko/index.ts index b1563183..35f057fb 100644 --- a/client/src/neko/index.ts +++ b/client/src/neko/index.ts @@ -22,6 +22,8 @@ import { AdminPayload, AdminTargetPayload, AdminLockMessage, + SystemInitPayload, + AdminLockResource, } from './messages' interface NekoEvents extends BaseEvents {} @@ -131,6 +133,18 @@ export class NekoClient extends BaseClient implements EventEmitter { ///////////////////////////// // System Events ///////////////////////////// + protected [EVENT.SYSTEM.INIT]({ implicit_hosting, locks }: SystemInitPayload) { + this.$accessor.remote.setImplicitHosting(implicit_hosting) + + for (const resource in locks) { + this[EVENT.ADMIN.LOCK]({ + event: EVENT.ADMIN.LOCK, + resource: resource as AdminLockResource, + id: locks[resource], + }) + } + } + protected [EVENT.SYSTEM.DISCONNECT]({ message }: SystemMessagePayload) { if (message == 'kicked') { this.$accessor.logout() diff --git a/client/src/neko/messages.ts b/client/src/neko/messages.ts index 2fa31cd3..65c3969b 100644 --- a/client/src/neko/messages.ts +++ b/client/src/neko/messages.ts @@ -52,6 +52,15 @@ export interface WebSocketMessage { /* SYSTEM MESSAGES/PAYLOADS */ +// system/init +export interface SystemInit extends WebSocketMessage, SystemInitPayload { + event: typeof EVENT.SYSTEM.INIT +} +export interface SystemInitPayload { + implicit_hosting: boolean + locks: Record +} + // system/disconnect // system/error export interface SystemMessage extends WebSocketMessage, SystemMessagePayload { diff --git a/client/src/store/remote.ts b/client/src/store/remote.ts index b76b7503..3e0daff6 100644 --- a/client/src/store/remote.ts +++ b/client/src/store/remote.ts @@ -12,7 +12,7 @@ export const state = () => ({ id: '', clipboard: '', locked: false, - + implicitHosting: true, keyboardModifierState: -1, }) @@ -49,10 +49,15 @@ export const mutations = mutationTree(state, { state.locked = locked }, + setImplicitHosting(state, val: boolean) { + state.implicitHosting = val + }, + reset(state) { state.id = '' state.clipboard = '' state.locked = false + state.implicitHosting = false state.keyboardModifierState = -1 }, }) diff --git a/server/internal/types/event/events.go b/server/internal/types/event/events.go index c9c9ec15..fca67f8a 100644 --- a/server/internal/types/event/events.go +++ b/server/internal/types/event/events.go @@ -1,6 +1,7 @@ package event const ( + SYSTEM_INIT = "system/init" SYSTEM_DISCONNECT = "system/disconnect" SYSTEM_ERROR = "system/error" ) diff --git a/server/internal/types/message/messages.go b/server/internal/types/message/messages.go index 4c40caa1..5d8944f3 100644 --- a/server/internal/types/message/messages.go +++ b/server/internal/types/message/messages.go @@ -10,6 +10,12 @@ type Message struct { Event string `json:"event"` } +type SystemInit struct { + Event string `json:"event"` + ImplicitHosting bool `json:"implicit_hosting"` + Locks map[string]string `json:"locks"` +} + type SystemMessage struct { Event string `json:"event"` Title string `json:"title"` diff --git a/server/internal/websocket/session.go b/server/internal/websocket/session.go index 534f0e43..3b246506 100644 --- a/server/internal/websocket/session.go +++ b/server/internal/websocket/session.go @@ -12,16 +12,14 @@ func (h *MessageHandler) SessionCreated(id string, session types.Session) error return err } - // notify all about what is locked - for resource, id := range h.locked { - if err := session.Send(message.AdminLock{ - Event: event.ADMIN_LOCK, - ID: id, - Resource: resource, - }); err != nil { - h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.ADMIN_LOCK) - return err - } + // send initialization information + if err := session.Send(message.SystemInit{ + Event: event.SYSTEM_INIT, + ImplicitHosting: true, + Locks: h.locked, + }); err != nil { + h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.SYSTEM_INIT) + return err } if session.Admin() {