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
SYSTEM: {
INIT: 'system/init',
DISCONNECT: 'system/disconnect',
ERROR: 'system/error',
},

View File

@ -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<NekoEvents> {
/////////////////////////////
// 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()

View File

@ -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<string, string>
}
// system/disconnect
// system/error
export interface SystemMessage extends WebSocketMessage, SystemMessagePayload {

View File

@ -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
},
})