implement system init.
This commit is contained in:
parent
8217321ecb
commit
8db06a7625
@ -10,6 +10,7 @@ export const EVENT = {
|
||||
|
||||
// Websocket Events
|
||||
SYSTEM: {
|
||||
INIT: 'system/init',
|
||||
DISCONNECT: 'system/disconnect',
|
||||
ERROR: 'system/error',
|
||||
},
|
||||
|
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
},
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
package event
|
||||
|
||||
const (
|
||||
SYSTEM_INIT = "system/init"
|
||||
SYSTEM_DISCONNECT = "system/disconnect"
|
||||
SYSTEM_ERROR = "system/error"
|
||||
)
|
||||
|
@ -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"`
|
||||
|
@ -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() {
|
||||
|
Reference in New Issue
Block a user