@adcops/autocore-react 3.0.10 → 3.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/EventEmitterContext.d.ts +1 -1
- package/dist/core/EventEmitterContext.js +1 -1
- package/dist/hub/HubBase.d.ts +3 -2
- package/dist/hub/HubBase.js +1 -1
- package/dist/hub/HubSimulate.d.ts +1 -1
- package/dist/hub/HubSimulate.js +1 -1
- package/dist/hub/HubTauri.d.ts +1 -1
- package/dist/hub/HubTauri.js +1 -1
- package/dist/hub/HubWebSocket.d.ts +37 -0
- package/dist/hub/HubWebSocket.js +1 -0
- package/dist/hub/index.d.ts +2 -2
- package/dist/hub/index.js +1 -1
- package/package.json +1 -1
- package/src/core/EventEmitterContext.tsx +4 -3
- package/src/hub/HubBase.ts +5 -4
- package/src/hub/HubSimulate.ts +3 -2
- package/src/hub/HubTauri.ts +7 -3
- package/src/hub/HubWebSocket.ts +153 -0
- package/src/hub/index.ts +20 -6
- package/dist/hub/HubSocketIo.d.ts +0 -101
- package/dist/hub/HubSocketIo.js +0 -1
- package/src/hub/HubSocketIo.ts +0 -166
|
@@ -76,7 +76,7 @@ export interface EventEmitterContextType {
|
|
|
76
76
|
* Invoke/send a message to the back end.
|
|
77
77
|
* This does NOT get published to the front end.
|
|
78
78
|
*/
|
|
79
|
-
invoke(fname: string, payload?: object): Promise<object>;
|
|
79
|
+
invoke(domain: string, fname: string, payload?: object): Promise<object>;
|
|
80
80
|
/**
|
|
81
81
|
* Subscribe to events identified by the topic.
|
|
82
82
|
* @param topic The subscription topic.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s)=>Promise.resolve({}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=t=>{e((s=>{const e={...s.subscriptions};for(const s in e)e.hasOwnProperty(s)&&(e[s]=e[s].filter((s=>s.id!==t)),0===e[s].length&&delete e[s]);return{...s,subscriptions:e}}))},c=t=>t?s.subscriptions[t]||[]:s.subscriptions,u=useMemo((()=>({state:s,dispatch:r,subscribe:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{createContext,useState,useMemo}from"react";import{createHub,Hub}from"../hub";export{Hub};let globalSubscriptionId=1;export const EventEmitterContext=createContext({state:{subscriptions:{},nextSubscriptionId:1},dispatch:()=>{},subscribe:()=>0,invoke:async(t,s,e)=>Promise.resolve({}),unsubscribe:t=>{},hub:null,getSubscriptions:()=>[]});export const EventEmitterProvider=({children:t})=>{const[s,e]=useState({subscriptions:{},nextSubscriptionId:1}),i=useMemo((()=>createHub()),[]),r=t=>{const{topic:s,payload:i}=t;e((t=>(t.subscriptions[s]?.forEach((t=>t.callback(i))),{...t,eventData:i})))},o=(t,s)=>{globalSubscriptionId+=1;const i=globalSubscriptionId;return e((e=>({...e,subscriptions:{...e.subscriptions,[t]:[...e.subscriptions[t]||[],{id:i,callback:s}]},nextSubscriptionId:globalSubscriptionId+1}))),i},n=t=>{e((s=>{const e={...s.subscriptions};for(const s in e)e.hasOwnProperty(s)&&(e[s]=e[s].filter((s=>s.id!==t)),0===e[s].length&&delete e[s]);return{...s,subscriptions:e}}))},c=t=>t?s.subscriptions[t]||[]:s.subscriptions,u=useMemo((()=>({state:s,dispatch:r,subscribe:o,unsubscribe:n,invoke:i.invoke,hub:i,getSubscriptions:c})),[s,i]);return i.setContext(u),_jsx(EventEmitterContext.Provider,{value:u,children:t})};
|
package/dist/hub/HubBase.d.ts
CHANGED
|
@@ -98,16 +98,17 @@ export declare abstract class HubBase {
|
|
|
98
98
|
* Invoke/send a message to the back end.
|
|
99
99
|
* This does NOT get published to the front end.
|
|
100
100
|
*/
|
|
101
|
-
abstract invoke(fname: string, payload?: object): Promise<object>;
|
|
101
|
+
abstract invoke(domain: string, fname: string, payload?: object): Promise<object>;
|
|
102
102
|
/**
|
|
103
103
|
* Convenience function to invoke a command with an optional topic and optional value.
|
|
104
104
|
* This will invoke the specified command in the backend. It does not broadcast the
|
|
105
105
|
* value within the local frontend.
|
|
106
|
+
* @param domain string The domain of the command that will be invoked.
|
|
106
107
|
* @param fname string Function name
|
|
107
108
|
* @param topic string Topic
|
|
108
109
|
* @param value any data payload
|
|
109
110
|
*/
|
|
110
|
-
invokeTopic(fname: string, topic: string | null, value?: any): Promise<object>;
|
|
111
|
+
invokeTopic(domain: string, fname: string, topic: string | null, value?: any): Promise<object>;
|
|
111
112
|
/**
|
|
112
113
|
* Pubish a topic throughout the web app using the
|
|
113
114
|
* Global EventEmitterContext. This will broadcast within the local frontend.
|
package/dist/hub/HubBase.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"localFNameToBackendFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendFNameToLocalFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null})}setContext(a){this.context=a}invokeTopic(a,e,o){const
|
|
1
|
+
export class HubBase{constructor(){Object.defineProperty(this,"localTopicToBackendTopicMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendTopicToLocalMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"localFNameToBackendFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"backendFNameToLocalFNameMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"context",{enumerable:!0,configurable:!0,writable:!0,value:null})}setContext(a){this.context=a}invokeTopic(a,e,o,c){const t={topic:o,data:c};return this.invoke(a,e,t)}publish(a,e){const o=this.toLocalTopic(a);this.context?.dispatch({topic:o,payload:e})}mapTopic(a,e){this.localTopicToBackendTopicMap.set(a,e),this.backendTopicToLocalMap.set(e,a)}unmapTopic(a){if(this.localTopicToBackendTopicMap.has(a)){const e=this.localTopicToBackendTopicMap.get(a);this.localTopicToBackendTopicMap.delete(a),null!=e&&this.backendTopicToLocalMap.has(e)&&this.backendTopicToLocalMap.delete(e)}}mapFName(a,e){this.localFNameToBackendFNameMap.set(a,e),this.backendFNameToLocalFNameMap.set(e,a)}unmapFName(a){if(this.localFNameToBackendFNameMap.has(a)){const e=this.localFNameToBackendFNameMap.get(a);this.localFNameToBackendFNameMap.delete(a),null!=e&&this.backendFNameToLocalFNameMap.has(e)&&this.backendFNameToLocalFNameMap.delete(e)}}toBackendTopic(a){if(this.localTopicToBackendTopicMap.has(a)){const e=this.localTopicToBackendTopicMap.get(a);return null!=e?e:a}return a}toBackendFName(a){if(this.localFNameToBackendFNameMap.has(a)){const e=this.localFNameToBackendFNameMap.get(a);return null!=e?e:a}return a}toLocalTopic(a){if(this.backendTopicToLocalMap.has(a)){const e=this.backendTopicToLocalMap.get(a);return null!=e?e:a}return a}toLocalFName(a){if(this.backendFNameToLocalFNameMap.has(a)){const e=this.backendFNameToLocalFNameMap.get(a);return null!=e?e:a}return a}}export default HubBase;
|
|
@@ -15,6 +15,6 @@ export declare class HubSimulate extends HubBase {
|
|
|
15
15
|
* @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
|
|
16
16
|
* @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
|
|
17
17
|
*/
|
|
18
|
-
invoke(fname: string, payload?: object, timeout?: number): Promise<object>;
|
|
18
|
+
invoke(domain: string, fname: string, payload?: object, timeout?: number): Promise<object>;
|
|
19
19
|
}
|
|
20
20
|
export default HubSimulate;
|
package/dist/hub/HubSimulate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,t,u=20){return new Promise(((e,
|
|
1
|
+
import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,t,u,r=20){return new Promise(((e,t)=>{setTimeout((()=>{e({data:u})}),r)}))}}export default HubSimulate;
|
package/dist/hub/HubTauri.d.ts
CHANGED
|
@@ -82,5 +82,5 @@ export declare class HubTauri extends HubBase {
|
|
|
82
82
|
* @param payload Optional data payload
|
|
83
83
|
* @returns The return value of the backend method.
|
|
84
84
|
*/
|
|
85
|
-
invoke(fname: string, payload?: object | undefined): Promise<object>;
|
|
85
|
+
invoke(domain: string, fname: string, payload?: object | undefined): Promise<object>;
|
|
86
86
|
}
|
package/dist/hub/HubTauri.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HubBase}from"./HubBase";import{event,invoke}from"@tauri-apps/api";export class HubTauri extends HubBase{constructor(){super(),event.listen("autocore://broadcast_event",(o=>{let e=JSON.parse(o.payload);void 0!==e.topic&&null!==e.topic&&(void 0!==e.payload&&null!==e.payload?this.publish(e.topic,e.payload):this.publish(e.topic,void 0))}))}invoke(o,e){return
|
|
1
|
+
import{HubBase}from"./HubBase";import{event,invoke}from"@tauri-apps/api";export class HubTauri extends HubBase{constructor(){super(),event.listen("autocore://broadcast_event",(o=>{let e=JSON.parse(o.payload);void 0!==e.topic&&null!==e.topic&&(void 0!==e.payload&&null!==e.payload?this.publish(e.topic,e.payload):this.publish(e.topic,void 0))}))}invoke(o,e,i){if(null!=i){return invoke(`${o}_${e}`,i)}return invoke(e)}}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** @file
|
|
2
|
+
*
|
|
3
|
+
* ## broadcast messages
|
|
4
|
+
* The result field of CommandMessages used for broadcast must have
|
|
5
|
+
* success set to true, and must contain the field "topic." The topic field, along
|
|
6
|
+
* with the domain field of the CommandMessage will be combined for the topic used
|
|
7
|
+
* by the websocket client.
|
|
8
|
+
*
|
|
9
|
+
* broadcast topic = `${CommandMessage.domain}/${CommandMessage.result["topic"]}
|
|
10
|
+
*
|
|
11
|
+
* So, to subscribe to a broadcast topic for GM.fReal that is served by the ADS client, the
|
|
12
|
+
* topic will be: "ADS/GM.fReal"
|
|
13
|
+
*/
|
|
14
|
+
import { HubBase } from './HubBase';
|
|
15
|
+
interface CommandMessageResult {
|
|
16
|
+
data: any;
|
|
17
|
+
success: boolean;
|
|
18
|
+
error_message: string;
|
|
19
|
+
}
|
|
20
|
+
interface CommandMessage {
|
|
21
|
+
request_id: number;
|
|
22
|
+
domain: string;
|
|
23
|
+
fname: string;
|
|
24
|
+
args?: any;
|
|
25
|
+
result?: CommandMessageResult;
|
|
26
|
+
}
|
|
27
|
+
export declare class HubWebSocket extends HubBase {
|
|
28
|
+
private socket;
|
|
29
|
+
private requestId;
|
|
30
|
+
private pendingRequests;
|
|
31
|
+
constructor();
|
|
32
|
+
invoke: (domain: string, fname: string, payload?: object) => Promise<object>;
|
|
33
|
+
handleUnsolicitedMessage: (msg: CommandMessage) => void;
|
|
34
|
+
disconnect: () => void;
|
|
35
|
+
protected emit: (eventName: string, payload?: object) => void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{HubBase}from"./HubBase";export class HubWebSocket extends HubBase{constructor(){super(),Object.defineProperty(this,"socket",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"requestId",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(this,"pendingRequests",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"invoke",{enumerable:!0,configurable:!0,writable:!0,value:(e,t,s)=>new Promise(((i,n)=>{const r=++this.requestId;this.pendingRequests.set(r,{resolve:i,reject:n});let o={request_id:r,domain:e,fname:t,args:s,result:void 0};this.socket.send(JSON.stringify(o))}))}),Object.defineProperty(this,"handleUnsolicitedMessage",{enumerable:!0,configurable:!0,writable:!0,value:e=>{if("BROADCAST"===e.fname&&e.domain.length>=1&&void 0!==e.result&&null!==e.result&&void 0!==e.result.data&&null!==e.result.data){let t=`${e.domain}/${e.result.data.topic}`;this.publish(t,e.result.data)}}}),Object.defineProperty(this,"disconnect",{enumerable:!0,configurable:!0,writable:!0,value:()=>{this.socket.close()}}),Object.defineProperty(this,"emit",{enumerable:!0,configurable:!0,writable:!0,value:(e,t)=>{this.socket.send(JSON.stringify({eventName:e,payload:t}))}});const e=window.location.hostname,t=window.location.port,s=`${"https:"===window.location.protocol?"wss://":"ws://"}${e}${t?":"+t:""}/ws/`;this.socket=new WebSocket(s);let i=this;this.socket.onopen=function(){i.publish("HUB/connected",!0)},this.socket.onmessage=e=>{const t=JSON.parse(e.data);if(t.request_id&&this.pendingRequests.has(t.request_id)){const{resolve:e,reject:s}=this.pendingRequests.get(t.request_id);t.result?.success?e(t):s(new Error(t.result?.error_message)),this.pendingRequests.delete(t.request_id)}else this.handleUnsolicitedMessage(t)},this.socket.onerror=e=>{},this.socket.onclose=()=>{}}}
|
package/dist/hub/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HubBase as Hub } from './HubBase';
|
|
2
2
|
import { HubTauri } from './HubTauri';
|
|
3
|
-
import {
|
|
3
|
+
import { HubWebSocket } from "./HubWebSocket";
|
|
4
4
|
import { HubSimulate } from "./HubSimulate";
|
|
5
5
|
/**
|
|
6
6
|
* Creates a connection to the backend.
|
|
@@ -9,5 +9,5 @@ import { HubSimulate } from "./HubSimulate";
|
|
|
9
9
|
export declare function createHub(): Hub;
|
|
10
10
|
export { HubBase as Hub } from './HubBase';
|
|
11
11
|
export { HubTauri };
|
|
12
|
-
export {
|
|
12
|
+
export { HubWebSocket };
|
|
13
13
|
export { HubSimulate };
|
package/dist/hub/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HubTauri}from"./HubTauri";import{
|
|
1
|
+
import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";export function createHub(){return void 0!==window.__TAURI__&&null!==window.__TAURI__?new HubTauri:void 0!==window.location.port&&window.location.port.length>0&&"80"!==window.location.port&&"8080"!==window.location.port&&"443"!==window.location.port?new HubSimulate:new HubWebSocket}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
|
|
3
3
|
* Created Date: 2024-01-17 11:45:10
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-
|
|
5
|
+
* Last Modified: 2024-04-23 11:53:43
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -103,7 +103,7 @@ export interface EventEmitterContextType {
|
|
|
103
103
|
* Invoke/send a message to the back end.
|
|
104
104
|
* This does NOT get published to the front end.
|
|
105
105
|
*/
|
|
106
|
-
invoke(fname: string, payload? : object) : Promise<object>;
|
|
106
|
+
invoke( domain: string, fname: string, payload? : object) : Promise<object>;
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
109
|
* Subscribe to events identified by the topic.
|
|
@@ -264,7 +264,8 @@ export const EventEmitterContext = createContext<EventEmitterContextType>({
|
|
|
264
264
|
state: { subscriptions: {}, nextSubscriptionId : 1 },
|
|
265
265
|
dispatch: () => { },
|
|
266
266
|
subscribe: () => { return 0; }, // Placeholder for subscription logic
|
|
267
|
-
invoke: async (fname: string, payload?: object) => {
|
|
267
|
+
invoke: async (domain: string, fname: string, payload?: object) => {
|
|
268
|
+
domain;
|
|
268
269
|
fname;
|
|
269
270
|
payload;
|
|
270
271
|
// Placeholder for invoke logic
|
package/src/hub/HubBase.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Created Date: 2023-12-15 14:21:33
|
|
4
4
|
* Author: Thomas C. Bitsky Jr.
|
|
5
5
|
* -----
|
|
6
|
-
* Last Modified: 2024-
|
|
6
|
+
* Last Modified: 2024-04-23 11:19:03
|
|
7
7
|
* Modified By: ADC
|
|
8
8
|
* -----
|
|
9
9
|
*
|
|
@@ -122,23 +122,24 @@ export abstract class HubBase {
|
|
|
122
122
|
* Invoke/send a message to the back end.
|
|
123
123
|
* This does NOT get published to the front end.
|
|
124
124
|
*/
|
|
125
|
-
abstract invoke(fname: string, payload? : object) : Promise<object>;
|
|
125
|
+
abstract invoke(domain: string, fname: string, payload? : object) : Promise<object>;
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* Convenience function to invoke a command with an optional topic and optional value.
|
|
130
130
|
* This will invoke the specified command in the backend. It does not broadcast the
|
|
131
131
|
* value within the local frontend.
|
|
132
|
+
* @param domain string The domain of the command that will be invoked.
|
|
132
133
|
* @param fname string Function name
|
|
133
134
|
* @param topic string Topic
|
|
134
135
|
* @param value any data payload
|
|
135
136
|
*/
|
|
136
|
-
invokeTopic( fname : string, topic : string | null, value? : any ) : Promise<object> {
|
|
137
|
+
invokeTopic( domain: string, fname : string, topic : string | null, value? : any ) : Promise<object> {
|
|
137
138
|
const msg = {
|
|
138
139
|
topic : topic,
|
|
139
140
|
data : value
|
|
140
141
|
};
|
|
141
|
-
return this.invoke(fname, msg);
|
|
142
|
+
return this.invoke(domain, fname, msg);
|
|
142
143
|
}
|
|
143
144
|
|
|
144
145
|
/**
|
package/src/hub/HubSimulate.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2023 Automated Design Corp. All Rights Reserved.
|
|
3
3
|
* Created Date: 2023-12-17 10:38:21
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-
|
|
5
|
+
* Last Modified: 2024-04-23 11:23:27
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -31,7 +31,8 @@ export class HubSimulate extends HubBase {
|
|
|
31
31
|
* @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
|
|
32
32
|
* @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
|
|
33
33
|
*/
|
|
34
|
-
invoke(fname: string, payload?: object, timeout: number = 20): Promise<object> {
|
|
34
|
+
invoke(domain : string, fname: string, payload?: object, timeout: number = 20): Promise<object> {
|
|
35
|
+
domain; // Not using for simulator
|
|
35
36
|
fname; // Not using for simulator
|
|
36
37
|
return new Promise((resolve, reject) => {
|
|
37
38
|
reject; // not using for simulator
|
package/src/hub/HubTauri.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Created Date: 2023-12-17 09:50:23
|
|
4
4
|
* Author: Thomas C. Bitsky Jr.
|
|
5
5
|
* -----
|
|
6
|
-
* Last Modified: 2024-
|
|
6
|
+
* Last Modified: 2024-04-23 11:21:45
|
|
7
7
|
* Modified By: ADC
|
|
8
8
|
* -----
|
|
9
9
|
*
|
|
@@ -128,13 +128,17 @@ export class HubTauri extends HubBase {
|
|
|
128
128
|
* @param payload Optional data payload
|
|
129
129
|
* @returns The return value of the backend method.
|
|
130
130
|
*/
|
|
131
|
-
invoke(fname: string, payload?: object | undefined): Promise<object> {
|
|
131
|
+
invoke(domain : string, fname: string, payload?: object | undefined): Promise<object> {
|
|
132
132
|
|
|
133
133
|
console.log(JSON.stringify(event));
|
|
134
134
|
|
|
135
135
|
if (payload !== undefined && payload !== null) {
|
|
136
136
|
console.log(`Payload: ${JSON.stringify(payload)}`);
|
|
137
|
-
|
|
137
|
+
|
|
138
|
+
// todo! This should probably always been the same function, and then that function
|
|
139
|
+
// in the backend routes the command.
|
|
140
|
+
let topic = `${domain}_${fname}`;
|
|
141
|
+
return invoke(topic, payload as InvokeArgs);
|
|
138
142
|
}
|
|
139
143
|
else {
|
|
140
144
|
return invoke(fname);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-04-17 09:13:07
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-04-23 18:48:23
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @file
|
|
11
|
+
*
|
|
12
|
+
* ## broadcast messages
|
|
13
|
+
* The result field of CommandMessages used for broadcast must have
|
|
14
|
+
* success set to true, and must contain the field "topic." The topic field, along
|
|
15
|
+
* with the domain field of the CommandMessage will be combined for the topic used
|
|
16
|
+
* by the websocket client.
|
|
17
|
+
*
|
|
18
|
+
* broadcast topic = `${CommandMessage.domain}/${CommandMessage.result["topic"]}
|
|
19
|
+
*
|
|
20
|
+
* So, to subscribe to a broadcast topic for GM.fReal that is served by the ADS client, the
|
|
21
|
+
* topic will be: "ADS/GM.fReal"
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { HubBase } from './HubBase';
|
|
25
|
+
|
|
26
|
+
/// The result portion of a CommandMessage. The server will
|
|
27
|
+
/// place the result of a command in this portion of the message.
|
|
28
|
+
interface CommandMessageResult {
|
|
29
|
+
/// The JSON object of the result.
|
|
30
|
+
data: any;
|
|
31
|
+
/// If true, the command was processed successfully.
|
|
32
|
+
success : boolean,
|
|
33
|
+
/// If success is false, this should contain a corresponding error message.
|
|
34
|
+
error_message: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/// CommandMessage is the object passed between the client and server for making requests and
|
|
38
|
+
/// responses.
|
|
39
|
+
interface CommandMessage {
|
|
40
|
+
/// An id to identify the request. The request ID is managed by the client and will be reflected back.
|
|
41
|
+
/// The server will never change the request ID.
|
|
42
|
+
request_id: number;
|
|
43
|
+
/// The command domain/servelet in which this command/function to invoke belongs.
|
|
44
|
+
domain: string;
|
|
45
|
+
/// The name of the function to invoke.
|
|
46
|
+
fname: string;
|
|
47
|
+
/// A JSON object of the arguments to the function.
|
|
48
|
+
args?: any;
|
|
49
|
+
/// The result of the command, reflected back from the server
|
|
50
|
+
result?: CommandMessageResult;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Function to parse the JSON string received from the server into a CommandMessage object
|
|
54
|
+
// function parseCommandMessage(jsonString: string): CommandMessage {
|
|
55
|
+
// const parsed: CommandMessage = JSON.parse(jsonString);
|
|
56
|
+
// // Assuming the JSON structure directly matches the TypeScript interfaces
|
|
57
|
+
// return parsed;
|
|
58
|
+
// }
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
interface RequestRecord {
|
|
62
|
+
resolve: (value?: any) => void;
|
|
63
|
+
reject: (reason?: any) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
export class HubWebSocket extends HubBase {
|
|
68
|
+
private socket: WebSocket;
|
|
69
|
+
private requestId = 0;
|
|
70
|
+
private pendingRequests = new Map<number, RequestRecord>();
|
|
71
|
+
|
|
72
|
+
constructor() {
|
|
73
|
+
super();
|
|
74
|
+
|
|
75
|
+
const host = window.location.hostname; // Get the hostname from the address bar
|
|
76
|
+
const port = window.location.port; // Get the port from the address bar, if any
|
|
77
|
+
const proto = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; // Determine the protocol
|
|
78
|
+
const wsUrl = `${proto}${host}${port ? ':' + port : ''}/ws/`; // Construct WebSocket URL
|
|
79
|
+
|
|
80
|
+
this.socket = new WebSocket(wsUrl);
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
let self = this;
|
|
84
|
+
this.socket.onopen = function() {
|
|
85
|
+
console.log("WebSocket connection established.");
|
|
86
|
+
self.publish("HUB/connected", true);
|
|
87
|
+
//ws.send("Hello, server!"); // Send a message to the server
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
this.socket.onmessage = (event) => {
|
|
92
|
+
const data: CommandMessage = JSON.parse(event.data);
|
|
93
|
+
if (data.request_id && this.pendingRequests.has(data.request_id)) {
|
|
94
|
+
const { resolve, reject } = this.pendingRequests.get(data.request_id)!;
|
|
95
|
+
if (!data.result?.success) {
|
|
96
|
+
reject(new Error(data.result?.error_message));
|
|
97
|
+
} else {
|
|
98
|
+
resolve(data);
|
|
99
|
+
}
|
|
100
|
+
this.pendingRequests.delete(data.request_id);
|
|
101
|
+
} else {
|
|
102
|
+
this.handleUnsolicitedMessage(data);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
this.socket.onerror = (error: Event) => {
|
|
107
|
+
console.error('WebSocket error:', error);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
this.socket.onclose = () => {
|
|
111
|
+
console.log('WebSocket connection closed.');
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
invoke = (domain : string, fname: string, payload?: object): Promise<object> => {
|
|
116
|
+
|
|
117
|
+
return new Promise((resolve, reject) => {
|
|
118
|
+
const id = ++this.requestId; // Increment and use the request ID
|
|
119
|
+
this.pendingRequests.set(id, { resolve, reject });
|
|
120
|
+
|
|
121
|
+
let cm : CommandMessage = {
|
|
122
|
+
request_id: id,
|
|
123
|
+
domain: domain,
|
|
124
|
+
fname: fname,
|
|
125
|
+
args: payload,
|
|
126
|
+
result: undefined
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
this.socket.send(JSON.stringify(cm));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
handleUnsolicitedMessage = (msg: CommandMessage) => {
|
|
134
|
+
// Handle messages that do not correspond to a pending request
|
|
135
|
+
|
|
136
|
+
if (msg.fname === "BROADCAST"
|
|
137
|
+
&& msg.domain.length >= 1
|
|
138
|
+
&& msg.result !== undefined && msg.result !== null
|
|
139
|
+
&& msg.result.data !== undefined && msg.result.data !== null
|
|
140
|
+
) {
|
|
141
|
+
let topic = `${msg.domain}/${msg.result.data["topic"]}`;
|
|
142
|
+
this.publish(topic, msg.result.data);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
disconnect= (): void => {
|
|
147
|
+
this.socket.close();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
protected emit = (eventName: string, payload?: object): void => {
|
|
151
|
+
this.socket.send(JSON.stringify({ eventName, payload }));
|
|
152
|
+
}
|
|
153
|
+
}
|
package/src/hub/index.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
|
|
3
3
|
* Created Date: 2024-01-16 21:07:29
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-
|
|
5
|
+
* Last Modified: 2024-04-23 14:54:08
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { HubBase as Hub } from './HubBase';
|
|
12
12
|
import { HubTauri } from './HubTauri';
|
|
13
|
-
import {
|
|
13
|
+
import { HubWebSocket } from "./HubWebSocket";
|
|
14
14
|
import {HubSimulate} from "./HubSimulate"
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -18,17 +18,31 @@ import {HubSimulate} from "./HubSimulate"
|
|
|
18
18
|
* @returns Hub
|
|
19
19
|
*/
|
|
20
20
|
export function createHub(): Hub {
|
|
21
|
-
|
|
21
|
+
|
|
22
|
+
console.log("HELLOW THERRE!!!");
|
|
23
|
+
|
|
24
|
+
if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
|
|
25
|
+
// Standalone Tauri application
|
|
26
|
+
console.log("HUB: Starting link to Tauri backend.");
|
|
22
27
|
return new HubTauri();
|
|
23
28
|
}
|
|
24
|
-
else if (
|
|
29
|
+
else if (
|
|
30
|
+
window.location.port !== undefined
|
|
31
|
+
&& window.location.port.length > 0
|
|
32
|
+
&& window.location.port !== '80'
|
|
33
|
+
&& window.location.port !== '8080'
|
|
34
|
+
&& window.location.port !== '443'
|
|
35
|
+
) {
|
|
25
36
|
|
|
26
37
|
// We're loaded in some development environment
|
|
38
|
+
console.log("HUB: Starting HUB SIMULATOR.");
|
|
27
39
|
return new HubSimulate();
|
|
28
40
|
|
|
29
41
|
}
|
|
30
42
|
else {
|
|
31
|
-
|
|
43
|
+
// A web-app that must communicate with a backend in another process.
|
|
44
|
+
console.log("HUB: Starting websocket connection.");
|
|
45
|
+
return new HubWebSocket();
|
|
32
46
|
}
|
|
33
47
|
}
|
|
34
48
|
|
|
@@ -37,5 +51,5 @@ export function createHub(): Hub {
|
|
|
37
51
|
// application.
|
|
38
52
|
export {HubBase as Hub} from './HubBase';
|
|
39
53
|
export {HubTauri}
|
|
40
|
-
export {
|
|
54
|
+
export {HubWebSocket}
|
|
41
55
|
export {HubSimulate}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { HubBase } from './HubBase';
|
|
2
|
-
/**
|
|
3
|
-
* Hub for integrating with a webserver/backend using Socket.IO as the pipeline.
|
|
4
|
-
*
|
|
5
|
-
* The socket-io connection is expected to broadcast messages on the event
|
|
6
|
-
* name: 'autocore://broadcast_event'
|
|
7
|
-
*
|
|
8
|
-
* This hub will capture those messages and dispatch them globally to any
|
|
9
|
-
* listeners in the web app.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* Example: Listen to an event 'xarm-position':
|
|
13
|
-
* ```
|
|
14
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
15
|
-
* useEffect(() => {
|
|
16
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
17
|
-
* // The rust backend sent a JSON object of 3D position values.
|
|
18
|
-
* setX(value.x);
|
|
19
|
-
* setY(value.y);
|
|
20
|
-
* setZ(value.z);
|
|
21
|
-
* setA(value.roll);
|
|
22
|
-
* setB(value.yaw);
|
|
23
|
-
* setC(value.pitch);
|
|
24
|
-
* });
|
|
25
|
-
*
|
|
26
|
-
* return () => {
|
|
27
|
-
* unsubscribe(unsubscripeMp);
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* }, [] );
|
|
31
|
-
*
|
|
32
|
-
* ```
|
|
33
|
-
*
|
|
34
|
-
* The hub should also be used for invoking events in the Tauri backend.
|
|
35
|
-
* This example will call the function "update_count" in the rust backend, passing
|
|
36
|
-
* the expected argument "count".
|
|
37
|
-
* ```
|
|
38
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
39
|
-
* const incrementCount = () => {
|
|
40
|
-
* count += 1;
|
|
41
|
-
* invoke('update_count', {"count": count});
|
|
42
|
-
* };
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* Of course, like any class derived from HubBase, the hub can be used to publish and subscribe to
|
|
46
|
-
* topics in the front-end, without need of interacting with the Tauri backed.
|
|
47
|
-
*
|
|
48
|
-
* ```
|
|
49
|
-
* const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
50
|
-
* const [controlPower, setControlPower] = useState(false);
|
|
51
|
-
* useEffect(() => {
|
|
52
|
-
* const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
|
|
53
|
-
* setControlPower(value);
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* return () => {
|
|
58
|
-
* unsubscribe(unsubscribeControlPower);
|
|
59
|
-
* }
|
|
60
|
-
* }, [] );
|
|
61
|
-
*
|
|
62
|
-
* const onPbPressed = () => {
|
|
63
|
-
* let count = 1;
|
|
64
|
-
* dispatch({
|
|
65
|
-
* topic: "my-awesome-topic",
|
|
66
|
-
* payload: count
|
|
67
|
-
* });
|
|
68
|
-
* }
|
|
69
|
-
*
|
|
70
|
-
* ```
|
|
71
|
-
*
|
|
72
|
-
*/
|
|
73
|
-
export declare class HubSocketIo extends HubBase {
|
|
74
|
-
private socket;
|
|
75
|
-
/**
|
|
76
|
-
* Constructor
|
|
77
|
-
*/
|
|
78
|
-
constructor();
|
|
79
|
-
/**
|
|
80
|
-
* Invoke a method in the Socket.IO backend and wait for acknowledgment.
|
|
81
|
-
*
|
|
82
|
-
* @param fname method name
|
|
83
|
-
* @param payload Optional data payload
|
|
84
|
-
* @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
|
|
85
|
-
* @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
|
|
86
|
-
*/
|
|
87
|
-
invoke(fname: string, payload?: object, timeout?: number): Promise<object>;
|
|
88
|
-
/**
|
|
89
|
-
* Disconnects the Socket.IO client.
|
|
90
|
-
*/
|
|
91
|
-
disconnect(): void;
|
|
92
|
-
/**
|
|
93
|
-
* Emit an event to the Socket.IO server.
|
|
94
|
-
* The intention is that the invoke method is used instead.
|
|
95
|
-
*
|
|
96
|
-
* @param eventName Name of the event to emit
|
|
97
|
-
* @param payload Optional data payload
|
|
98
|
-
*/
|
|
99
|
-
protected emit(eventName: string, payload?: object): void;
|
|
100
|
-
}
|
|
101
|
-
export default HubSocketIo;
|
package/dist/hub/HubSocketIo.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{HubBase}from"./HubBase";import io from"socket.io-client";export class HubSocketIo extends HubBase{constructor(){super(),Object.defineProperty(this,"socket",{enumerable:!0,configurable:!0,writable:!0,value:void 0});const e=window.location.origin;this.socket=io(e),this.socket.on("autocore://broadcast_event",(e=>{let o=JSON.parse(e.payload);void 0!==o.topic&&null!==o.topic&&(void 0!==o.payload&&null!==o.payload?this.publish(o.topic,o.payload):this.publish(o.topic,void 0))}))}invoke(e,o,t=5e3){return new Promise(((i,s)=>{let c=!1;this.socket.emit(e,o,(e=>{c=!0,i(e)})),setTimeout((()=>{c||s(new Error(`Timeout: No response received within ${t} ms`))}),t)}))}disconnect(){this.socket.disconnect()}emit(e,o){this.socket.emit(e,o)}}export default HubSocketIo;
|
package/src/hub/HubSocketIo.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (C) 2023 Automated Design Corp. All Rights Reserved.
|
|
3
|
-
* Created Date: 2023-12-17 10:38:21
|
|
4
|
-
* Author: Thomas C. Bitsky Jr.
|
|
5
|
-
* -----
|
|
6
|
-
* Last Modified: 2024-03-08 09:46:20
|
|
7
|
-
* Modified By: ADC
|
|
8
|
-
* -----
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import { HubBase } from './HubBase';
|
|
13
|
-
import io, { Socket } from 'socket.io-client';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Hub for integrating with a webserver/backend using Socket.IO as the pipeline.
|
|
17
|
-
*
|
|
18
|
-
* The socket-io connection is expected to broadcast messages on the event
|
|
19
|
-
* name: 'autocore://broadcast_event'
|
|
20
|
-
*
|
|
21
|
-
* This hub will capture those messages and dispatch them globally to any
|
|
22
|
-
* listeners in the web app.
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Example: Listen to an event 'xarm-position':
|
|
26
|
-
* ```
|
|
27
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
28
|
-
* useEffect(() => {
|
|
29
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
30
|
-
* // The rust backend sent a JSON object of 3D position values.
|
|
31
|
-
* setX(value.x);
|
|
32
|
-
* setY(value.y);
|
|
33
|
-
* setZ(value.z);
|
|
34
|
-
* setA(value.roll);
|
|
35
|
-
* setB(value.yaw);
|
|
36
|
-
* setC(value.pitch);
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* return () => {
|
|
40
|
-
* unsubscribe(unsubscripeMp);
|
|
41
|
-
* }
|
|
42
|
-
*
|
|
43
|
-
* }, [] );
|
|
44
|
-
*
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* The hub should also be used for invoking events in the Tauri backend.
|
|
48
|
-
* This example will call the function "update_count" in the rust backend, passing
|
|
49
|
-
* the expected argument "count".
|
|
50
|
-
* ```
|
|
51
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
52
|
-
* const incrementCount = () => {
|
|
53
|
-
* count += 1;
|
|
54
|
-
* invoke('update_count', {"count": count});
|
|
55
|
-
* };
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* Of course, like any class derived from HubBase, the hub can be used to publish and subscribe to
|
|
59
|
-
* topics in the front-end, without need of interacting with the Tauri backed.
|
|
60
|
-
*
|
|
61
|
-
* ```
|
|
62
|
-
* const {dispatch, subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
63
|
-
* const [controlPower, setControlPower] = useState(false);
|
|
64
|
-
* useEffect(() => {
|
|
65
|
-
* const unsubscribeControlPower = subscribe('value-simulator-bBit1', (value) => {
|
|
66
|
-
* setControlPower(value);
|
|
67
|
-
* });
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* return () => {
|
|
71
|
-
* unsubscribe(unsubscribeControlPower);
|
|
72
|
-
* }
|
|
73
|
-
* }, [] );
|
|
74
|
-
*
|
|
75
|
-
* const onPbPressed = () => {
|
|
76
|
-
* let count = 1;
|
|
77
|
-
* dispatch({
|
|
78
|
-
* topic: "my-awesome-topic",
|
|
79
|
-
* payload: count
|
|
80
|
-
* });
|
|
81
|
-
* }
|
|
82
|
-
*
|
|
83
|
-
* ```
|
|
84
|
-
*
|
|
85
|
-
*/
|
|
86
|
-
export class HubSocketIo extends HubBase {
|
|
87
|
-
private socket: Socket;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Constructor
|
|
91
|
-
*/
|
|
92
|
-
constructor() {
|
|
93
|
-
super();
|
|
94
|
-
|
|
95
|
-
// Initialize the Socket.IO client to connect to the same domain and protocol
|
|
96
|
-
const socketUrl = window.location.origin;
|
|
97
|
-
|
|
98
|
-
this.socket = io(socketUrl);
|
|
99
|
-
|
|
100
|
-
// Listen for a custom event from the backend
|
|
101
|
-
this.socket.on('autocore://broadcast_event', (ev: any) => {
|
|
102
|
-
let objPayload = JSON.parse(ev.payload);
|
|
103
|
-
|
|
104
|
-
if (objPayload.topic !== undefined && objPayload.topic !== null ) {
|
|
105
|
-
|
|
106
|
-
if ( objPayload.payload !== undefined && objPayload.payload !== null ) {
|
|
107
|
-
this.publish(objPayload.topic, objPayload.payload);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.publish(objPayload.topic, undefined);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Invoke a method in the Socket.IO backend and wait for acknowledgment.
|
|
120
|
-
*
|
|
121
|
-
* @param fname method name
|
|
122
|
-
* @param payload Optional data payload
|
|
123
|
-
* @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
|
|
124
|
-
* @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
|
|
125
|
-
*/
|
|
126
|
-
invoke(fname: string, payload?: object, timeout: number = 5000): Promise<object> {
|
|
127
|
-
return new Promise((resolve, reject) => {
|
|
128
|
-
// Flag to track if the response was received
|
|
129
|
-
let responseReceived = false;
|
|
130
|
-
|
|
131
|
-
this.socket.emit(fname, payload, (response: object) => {
|
|
132
|
-
responseReceived = true;
|
|
133
|
-
resolve(response);
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
// Set a timeout to reject the promise if no response is received
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
if (!responseReceived) {
|
|
139
|
-
reject(new Error(`Timeout: No response received within ${timeout} ms`));
|
|
140
|
-
}
|
|
141
|
-
}, timeout);
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Disconnects the Socket.IO client.
|
|
147
|
-
*/
|
|
148
|
-
disconnect(): void {
|
|
149
|
-
this.socket.disconnect();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Emit an event to the Socket.IO server.
|
|
155
|
-
* The intention is that the invoke method is used instead.
|
|
156
|
-
*
|
|
157
|
-
* @param eventName Name of the event to emit
|
|
158
|
-
* @param payload Optional data payload
|
|
159
|
-
*/
|
|
160
|
-
protected emit(eventName: string, payload?: object): void {
|
|
161
|
-
this.socket.emit(eventName, payload);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export default HubSocketIo;
|