error handling todo

This commit is contained in:
Zack Hoherchak 2022-03-10 12:49:53 -05:00
commit 7cb1ad84a4
2 changed files with 28 additions and 16 deletions

View file

@ -6,7 +6,9 @@
*/ */
class ELGSDAction { class ELGSDAction {
UUID; UUID;
#on = EventEmitter.on; on = EventEmitter.on;
emit = EventEmitter.emit;
constructor(UUID) { constructor(UUID) {
this.UUID = UUID; this.UUID = UUID;

View file

@ -15,8 +15,8 @@ class ELGSDStreamDeck {
language; language;
localization; localization;
appInfo; appInfo;
#on = EventEmitter.on; on = EventEmitter.on;
#emit = EventEmitter.emit; emit = EventEmitter.emit;
constructor() { constructor() {
if (ELGSDStreamDeck.__instance) { if (ELGSDStreamDeck.__instance) {
@ -57,7 +57,7 @@ class ELGSDStreamDeck {
this.websocket.send(JSON.stringify(json)); this.websocket.send(JSON.stringify(json));
this.#emit(Events.connected, { this.emit(Events.connected, {
connection: this.websocket, connection: this.websocket,
port: this.port, port: this.port,
uuid: this.uuid, uuid: this.uuid,
@ -82,7 +82,7 @@ class ELGSDStreamDeck {
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);
}; };
} }
@ -277,15 +277,25 @@ class ELGSDStreamDeck {
this.setTitle(null, context, target || Constants.hardwareAndSoftware); this.setTitle(null, context, target || Constants.hardwareAndSoftware);
} }
// TODO; add error handling like this with nice messages for all methods for the template
/** /**
* Send payload to property inspector * Send payload to property inspector
* @param {string} actionUUID
* @param {object} payload * @param {object} payload
* @param {string} context * @param {string} context
*/ */
sendToPropertyInspector(context, payload) { sendToPropertyInspector(actionUUID, context, payload) {
if (typeof actionUUID != 'string') {
throw 'sendToPropertyInspector requires an actionUUID string';
}
if (typeof context != 'string') {
throw 'sendToPropertyInspector requires a key context string';
}
this.send(Events.sendToPropertyInspector, context, { this.send(Events.sendToPropertyInspector, context, {
action: this?.actionInfo?.action, action: actionUUID,
payload: payload || {}, payload: payload || null,
}); });
} }
@ -319,7 +329,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onConnected(fn) { onConnected(fn) {
this.#on(Events.connected, (jsn) => fn(jsn)); this.on(Events.connected, (jsn) => fn(jsn));
return this; return this;
} }
@ -330,7 +340,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onSendToPropertyInspector(fn, actionUUID) { onSendToPropertyInspector(fn, actionUUID) {
this.#on(`${actionUUID}.${Events.sendToPropertyInspector}`, (jsn) => fn(jsn)); this.on(`${actionUUID}.${Events.sendToPropertyInspector}`, (jsn) => fn(jsn));
return this; return this;
} }
@ -340,7 +350,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onDeviceDidConnect(fn) { onDeviceDidConnect(fn) {
this.#on(Events.deviceDidConnect, (jsn) => fn(jsn)); this.on(Events.deviceDidConnect, (jsn) => fn(jsn));
return this; return this;
} }
@ -350,7 +360,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onDeviceDidDisconnect(fn) { onDeviceDidDisconnect(fn) {
this.#on(Events.deviceDidDisconnect, (jsn) => fn(jsn)); this.on(Events.deviceDidDisconnect, (jsn) => fn(jsn));
return this; return this;
} }
@ -360,7 +370,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onApplicationDidLaunch(fn) { onApplicationDidLaunch(fn) {
this.#on(Events.applicationDidLaunch, (jsn) => fn(jsn)); this.on(Events.applicationDidLaunch, (jsn) => fn(jsn));
return this; return this;
} }
@ -370,7 +380,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onApplicationDidTerminate(fn) { onApplicationDidTerminate(fn) {
this.#on(Events.applicationDidTerminate, (jsn) => fn(jsn)); this.on(Events.applicationDidTerminate, (jsn) => fn(jsn));
return this; return this;
} }
@ -380,7 +390,7 @@ class ELGSDStreamDeck {
* @returns ELGSDStreamDeck * @returns ELGSDStreamDeck
*/ */
onSystemDidWakeUp(fn) { onSystemDidWakeUp(fn) {
this.#on(Events.systemDidWakeUp, (jsn) => fn(jsn)); this.on(Events.systemDidWakeUp, (jsn) => fn(jsn));
return this; return this;
} }
@ -389,7 +399,7 @@ class ELGSDStreamDeck {
* @param {function} fn * @param {function} fn
*/ */
onDidReceiveGlobalSettings(fn) { onDidReceiveGlobalSettings(fn) {
this.#on(Events.didReceiveGlobalSettings, (jsn) => fn(jsn)); this.on(Events.didReceiveGlobalSettings, (jsn) => fn(jsn));
return this; return this;
} }
} }