This commit is contained in:
Zack Hoherchak 2022-02-23 19:07:21 -05:00
commit af76f81b36
2 changed files with 10 additions and 7 deletions

View file

@ -21,6 +21,7 @@ const SocketErrors = {
/** /**
* Events * Events
*/ */
//TODO: group these in objects that make sense & rename
const DID_RECEIVE_SETTINGS = 'didReceiveSettings'; const DID_RECEIVE_SETTINGS = 'didReceiveSettings';
const DID_RECEIVE_GLOBAL_SETTINGS = 'didReceiveGlobalSettings'; const DID_RECEIVE_GLOBAL_SETTINGS = 'didReceiveGlobalSettings';
const KEY_DOWN = 'keyDown'; const KEY_DOWN = 'keyDown';

View file

@ -1,6 +1,8 @@
/// <reference path="event-handler.js" /> /// <reference path="event-emitter.js" />
/// <reference path="constants.js" /> /// <reference path="constants.js" />
// TODO: add clearTitle, switchToProfile (see https://elgato.slack.com/archives/D02LPKC0M9D/p1645183819000839 ), swap optional context to be second everywhere
/** /**
* @class StreamDeck * @class StreamDeck
* StreamDeck object containing all required code to establish * StreamDeck object containing all required code to establish
@ -80,7 +82,7 @@ class ELGSDStreamDeck {
this.#websocket.onmessage = (evt) => { this.#websocket.onmessage = (evt) => {
const data = evt?.data ? JSON.parse(evt.data) : {}; const data = evt?.data ? JSON.parse(evt.data) : {};
const {action, event} = data; const { action, event } = data;
const message = action ? `${action}.${event}` : event; const message = action ? `${action}.${event}` : event;
if (message && message !== '') this.#emit(message, data); if (message && message !== '') this.#emit(message, data);
@ -91,7 +93,7 @@ class ELGSDStreamDeck {
* Write to log file * Write to log file
* @param message * @param message
*/ */
log(message) { logMessage(message) {
try { try {
if (this.#websocket) { if (this.#websocket) {
const json = { const json = {
@ -159,7 +161,7 @@ class ELGSDStreamDeck {
* @param payload * @param payload
*/ */
send(context, fn, payload) { send(context, fn, payload) {
const pl = Object.assign({}, {event: fn, context: context}, payload); const pl = Object.assign({}, { event: fn, context: context }, payload);
this.#websocket && this.#websocket.send(JSON.stringify(pl)); this.#websocket && this.#websocket.send(JSON.stringify(pl));
} }
@ -252,7 +254,7 @@ class ELGSDStreamDeck {
* @param context * @param context
* @param payload * @param payload
*/ */
setState(context, payload) { setState(payload, context) {
this.send(context, SET_STATE, { this.send(context, SET_STATE, {
payload: { payload: {
state: 1 - Number(payload === 0), state: 1 - Number(payload === 0),
@ -266,7 +268,7 @@ class ELGSDStreamDeck {
* @param title * @param title
* @param target * @param target
*/ */
setTitle(context, title, target) { setTitle(title, target, context) {
this.send(context, SET_TITLE, { this.send(context, SET_TITLE, {
payload: { payload: {
title: '' + title || '', title: '' + title || '',
@ -280,7 +282,7 @@ class ELGSDStreamDeck {
* @param context * @param context
* @param payload * @param payload
*/ */
sendToPropertyInspector(context, payload) { sendToPropertyInspector(payload, context) {
this.send(context, SEND_TO_PROPERTY_INSPECTOR, { this.send(context, SEND_TO_PROPERTY_INSPECTOR, {
action: this.#actionInfo.action, action: this.#actionInfo.action,
payload: payload, payload: payload,