Archived
2
0

implement system init.

This commit is contained in:
Miroslav Šedivý 2021-12-04 22:44:13 +01:00
parent 8217321ecb
commit 8db06a7625
7 changed files with 45 additions and 11 deletions

View File

@ -10,6 +10,7 @@ export const EVENT = {
// Websocket Events // Websocket Events
SYSTEM: { SYSTEM: {
INIT: 'system/init',
DISCONNECT: 'system/disconnect', DISCONNECT: 'system/disconnect',
ERROR: 'system/error', ERROR: 'system/error',
}, },

View File

@ -22,6 +22,8 @@ import {
AdminPayload, AdminPayload,
AdminTargetPayload, AdminTargetPayload,
AdminLockMessage, AdminLockMessage,
SystemInitPayload,
AdminLockResource,
} from './messages' } from './messages'
interface NekoEvents extends BaseEvents {} interface NekoEvents extends BaseEvents {}
@ -131,6 +133,18 @@ export class NekoClient extends BaseClient implements EventEmitter<NekoEvents> {
///////////////////////////// /////////////////////////////
// System Events // 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) { protected [EVENT.SYSTEM.DISCONNECT]({ message }: SystemMessagePayload) {
if (message == 'kicked') { if (message == 'kicked') {
this.$accessor.logout() this.$accessor.logout()

View File

@ -52,6 +52,15 @@ export interface WebSocketMessage {
/* /*
SYSTEM MESSAGES/PAYLOADS SYSTEM MESSAGES/PAYLOADS
*/ */
// system/init
export interface SystemInit extends WebSocketMessage, SystemInitPayload {
event: typeof EVENT.SYSTEM.INIT
}
export interface SystemInitPayload {
implicit_hosting: boolean
locks: Record<string, string>
}
// system/disconnect // system/disconnect
// system/error // system/error
export interface SystemMessage extends WebSocketMessage, SystemMessagePayload { export interface SystemMessage extends WebSocketMessage, SystemMessagePayload {

View File

@ -12,7 +12,7 @@ export const state = () => ({
id: '', id: '',
clipboard: '', clipboard: '',
locked: false, locked: false,
implicitHosting: true,
keyboardModifierState: -1, keyboardModifierState: -1,
}) })
@ -49,10 +49,15 @@ export const mutations = mutationTree(state, {
state.locked = locked state.locked = locked
}, },
setImplicitHosting(state, val: boolean) {
state.implicitHosting = val
},
reset(state) { reset(state) {
state.id = '' state.id = ''
state.clipboard = '' state.clipboard = ''
state.locked = false state.locked = false
state.implicitHosting = false
state.keyboardModifierState = -1 state.keyboardModifierState = -1
}, },
}) })

View File

@ -1,6 +1,7 @@
package event package event
const ( const (
SYSTEM_INIT = "system/init"
SYSTEM_DISCONNECT = "system/disconnect" SYSTEM_DISCONNECT = "system/disconnect"
SYSTEM_ERROR = "system/error" SYSTEM_ERROR = "system/error"
) )

View File

@ -10,6 +10,12 @@ type Message struct {
Event string `json:"event"` 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 { type SystemMessage struct {
Event string `json:"event"` Event string `json:"event"`
Title string `json:"title"` Title string `json:"title"`

View File

@ -12,17 +12,15 @@ func (h *MessageHandler) SessionCreated(id string, session types.Session) error
return err return err
} }
// notify all about what is locked // send initialization information
for resource, id := range h.locked { if err := session.Send(message.SystemInit{
if err := session.Send(message.AdminLock{ Event: event.SYSTEM_INIT,
Event: event.ADMIN_LOCK, ImplicitHosting: true,
ID: id, Locks: h.locked,
Resource: resource,
}); err != nil { }); err != nil {
h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.ADMIN_LOCK) h.logger.Warn().Str("id", id).Err(err).Msgf("sending event %s has failed", event.SYSTEM_INIT)
return err return err
} }
}
if session.Admin() { if session.Admin() {
// send screen configurations if admin // send screen configurations if admin