mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
add new WS keyboard event
This commit is contained in:
parent
56bd6acf10
commit
6206fbbadd
@ -27,6 +27,7 @@ export const EVENT = {
|
|||||||
REQUESTING: 'control/requesting',
|
REQUESTING: 'control/requesting',
|
||||||
CLIPBOARD: 'control/clipboard',
|
CLIPBOARD: 'control/clipboard',
|
||||||
GIVE: 'control/give',
|
GIVE: 'control/give',
|
||||||
|
KEYBOARD: 'control/keyboard'
|
||||||
},
|
},
|
||||||
CHAT: {
|
CHAT: {
|
||||||
MESSAGE: 'chat/message',
|
MESSAGE: 'chat/message',
|
||||||
@ -67,6 +68,7 @@ export type ControlEvents =
|
|||||||
| typeof EVENT.CONTROL.REQUEST
|
| typeof EVENT.CONTROL.REQUEST
|
||||||
| typeof EVENT.CONTROL.GIVE
|
| typeof EVENT.CONTROL.GIVE
|
||||||
| typeof EVENT.CONTROL.CLIPBOARD
|
| typeof EVENT.CONTROL.CLIPBOARD
|
||||||
|
| typeof EVENT.CONTROL.KEYBOARD
|
||||||
|
|
||||||
export type SystemEvents = typeof EVENT.SYSTEM.DISCONNECT
|
export type SystemEvents = typeof EVENT.SYSTEM.DISCONNECT
|
||||||
export type MemberEvents = typeof EVENT.MEMBER.LIST | typeof EVENT.MEMBER.CONNECTED | typeof EVENT.MEMBER.DISCONNECTED
|
export type MemberEvents = typeof EVENT.MEMBER.LIST | typeof EVENT.MEMBER.CONNECTED | typeof EVENT.MEMBER.DISCONNECTED
|
||||||
|
@ -31,6 +31,7 @@ export type WebSocketPayloads =
|
|||||||
| ControlPayload
|
| ControlPayload
|
||||||
| ControlRequestPayload
|
| ControlRequestPayload
|
||||||
| ControlClipboardPayload
|
| ControlClipboardPayload
|
||||||
|
| ControlKeyboardPayload
|
||||||
| ChatPayload
|
| ChatPayload
|
||||||
| ChatSendPayload
|
| ChatSendPayload
|
||||||
| EmojiSendPayload
|
| EmojiSendPayload
|
||||||
@ -125,6 +126,10 @@ export interface ControlClipboardPayload {
|
|||||||
text: string
|
text: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ControlKeyboardPayload {
|
||||||
|
layout: string
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
CHAT PAYLOADS
|
CHAT PAYLOADS
|
||||||
*/
|
*/
|
||||||
|
@ -133,5 +133,13 @@ export const actions = actionTree(
|
|||||||
|
|
||||||
$client.sendMessage(EVENT.ADMIN.GIVE, { id: member.id })
|
$client.sendMessage(EVENT.ADMIN.GIVE, { id: member.id })
|
||||||
},
|
},
|
||||||
|
|
||||||
|
changeKeyboard({ getters }) {
|
||||||
|
if (!accessor.connected || !getters.hosting) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$client.sendMessage(EVENT.CONTROL.KEYBOARD, { layout: accessor.settings.keyboard_layout })
|
||||||
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -22,6 +22,7 @@ const (
|
|||||||
CONTROL_REQUESTING = "control/requesting"
|
CONTROL_REQUESTING = "control/requesting"
|
||||||
CONTROL_GIVE = "control/give"
|
CONTROL_GIVE = "control/give"
|
||||||
CONTROL_CLIPBOARD = "control/clipboard"
|
CONTROL_CLIPBOARD = "control/clipboard"
|
||||||
|
CONTROL_KEYBOARD = "control/keyboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -46,6 +46,11 @@ type Clipboard struct {
|
|||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Keyboard struct {
|
||||||
|
Event string `json:"event"`
|
||||||
|
Layout string `json:"layout"`
|
||||||
|
}
|
||||||
|
|
||||||
type Control struct {
|
type Control struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
@ -119,3 +119,14 @@ func (h *MessageHandler) controlClipboard(id string, session types.Session, payl
|
|||||||
h.remote.WriteClipboard(payload.Text)
|
h.remote.WriteClipboard(payload.Text)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *MessageHandler) controlKeyboard(id string, session types.Session, payload *message.Keyboard) error {
|
||||||
|
// check if session is host
|
||||||
|
if !h.sessions.IsHost(id) {
|
||||||
|
h.logger.Debug().Str("id", id).Msg("is not the host")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h.remote.SetKeyboard(payload.Layout)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -93,6 +93,13 @@ func (h *MessageHandler) Message(id string, raw []byte) error {
|
|||||||
utils.Unmarshal(payload, raw, func() error {
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.controlClipboard(id, session, payload)
|
return h.controlClipboard(id, session, payload)
|
||||||
}), "%s failed", header.Event)
|
}), "%s failed", header.Event)
|
||||||
|
case event.CONTROL_KEYBOARD:
|
||||||
|
payload := &message.Keyboard{}
|
||||||
|
return errors.Wrapf(
|
||||||
|
utils.Unmarshal(payload, raw, func() error {
|
||||||
|
return h.controlKeyboard(id, session, payload)
|
||||||
|
}), "%s failed", header.Event)
|
||||||
|
|
||||||
|
|
||||||
// Chat Events
|
// Chat Events
|
||||||
case event.CHAT_MESSAGE:
|
case event.CHAT_MESSAGE:
|
||||||
|
Loading…
Reference in New Issue
Block a user