@adcops/autocore-react 3.0.12 → 3.0.14
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 +2 -1
- package/dist/core/EventEmitterContext.js +1 -1
- package/dist/hub/CommandMessage.d.ts +12 -0
- package/dist/hub/CommandMessage.js +1 -0
- package/dist/hub/HubBase.d.ts +3 -2
- package/dist/hub/HubSimulate.d.ts +2 -1
- package/dist/hub/HubSimulate.js +1 -1
- package/dist/hub/HubTauri.d.ts +2 -1
- package/dist/hub/HubWebSocket.d.ts +2 -14
- package/dist/hub/HubWebSocket.js +1 -1
- package/dist/hub/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/core/EventEmitterContext.tsx +9 -3
- package/src/hub/CommandMessage.ts +37 -0
- package/src/hub/HubBase.ts +4 -4
- package/src/hub/HubSimulate.ts +11 -4
- package/src/hub/HubTauri.ts +3 -3
- package/src/hub/HubWebSocket.ts +4 -30
- package/src/hub/index.ts +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { Hub } from "../hub";
|
|
3
|
+
import { CommandMessageResult } from "../hub/CommandMessage";
|
|
3
4
|
export { Hub };
|
|
4
5
|
/**
|
|
5
6
|
* Represents an event subsription.
|
|
@@ -76,7 +77,7 @@ export interface EventEmitterContextType {
|
|
|
76
77
|
* Invoke/send a message to the back end.
|
|
77
78
|
* This does NOT get published to the front end.
|
|
78
79
|
*/
|
|
79
|
-
invoke(domain: string, fname: string, payload?: object): Promise<
|
|
80
|
+
invoke(domain: string, fname: string, payload?: object): Promise<CommandMessageResult>;
|
|
80
81
|
/**
|
|
81
82
|
* Subscribe to events identified by the topic.
|
|
82
83
|
* @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,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})};
|
|
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({data:{},success:!1,error_message:""}),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})};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
package/dist/hub/HubBase.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitterContextType } from '../core/EventEmitterContext';
|
|
2
|
+
import { CommandMessageResult } from "./CommandMessage";
|
|
2
3
|
/**
|
|
3
4
|
* Base class for the interface for the IPC to the backend,
|
|
4
5
|
* which may be websockets, MQTT, the Tauri API,
|
|
@@ -98,7 +99,7 @@ export declare abstract class HubBase {
|
|
|
98
99
|
* Invoke/send a message to the back end.
|
|
99
100
|
* This does NOT get published to the front end.
|
|
100
101
|
*/
|
|
101
|
-
abstract invoke(domain: string, fname: string, payload?: object): Promise<
|
|
102
|
+
abstract invoke(domain: string, fname: string, payload?: object): Promise<CommandMessageResult>;
|
|
102
103
|
/**
|
|
103
104
|
* Convenience function to invoke a command with an optional topic and optional value.
|
|
104
105
|
* This will invoke the specified command in the backend. It does not broadcast the
|
|
@@ -108,7 +109,7 @@ export declare abstract class HubBase {
|
|
|
108
109
|
* @param topic string Topic
|
|
109
110
|
* @param value any data payload
|
|
110
111
|
*/
|
|
111
|
-
invokeTopic(domain: string, fname: string, topic: string | null, value?: any): Promise<
|
|
112
|
+
invokeTopic(domain: string, fname: string, topic: string | null, value?: any): Promise<CommandMessageResult>;
|
|
112
113
|
/**
|
|
113
114
|
* Pubish a topic throughout the web app using the
|
|
114
115
|
* Global EventEmitterContext. This will broadcast within the local frontend.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HubBase } from './HubBase';
|
|
2
|
+
import { CommandMessageResult } from "./CommandMessage";
|
|
2
3
|
/**
|
|
3
4
|
* Hub for simulating functionality when no backend is present.
|
|
4
5
|
*/
|
|
@@ -15,6 +16,6 @@ export declare class HubSimulate extends HubBase {
|
|
|
15
16
|
* @param timeout Timeout in milliseconds after which the promise is rejected if no response is received.
|
|
16
17
|
* @returns A Promise that resolves to the response from the backend or rejects if a timeout occurs.
|
|
17
18
|
*/
|
|
18
|
-
invoke(domain: string, fname: string, payload?: object, timeout?: number): Promise<
|
|
19
|
+
invoke(domain: string, fname: string, payload?: object, timeout?: number): Promise<CommandMessageResult>;
|
|
19
20
|
}
|
|
20
21
|
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,
|
|
1
|
+
import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,s,r,t=20){return new Promise(((e,s)=>{setTimeout((()=>{e({data:r,error_message:"",success:!0})}),t)}))}}export default HubSimulate;
|
package/dist/hub/HubTauri.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { HubBase } from './HubBase';
|
|
2
|
+
import { CommandMessageResult } from "./CommandMessage";
|
|
2
3
|
/**
|
|
3
4
|
* Hub for integrating with the Tauri backend.
|
|
4
5
|
*
|
|
@@ -82,5 +83,5 @@ export declare class HubTauri extends HubBase {
|
|
|
82
83
|
* @param payload Optional data payload
|
|
83
84
|
* @returns The return value of the backend method.
|
|
84
85
|
*/
|
|
85
|
-
invoke(domain: string, fname: string, payload?: object | undefined): Promise<
|
|
86
|
+
invoke(domain: string, fname: string, payload?: object | undefined): Promise<CommandMessageResult>;
|
|
86
87
|
}
|
|
@@ -12,26 +12,14 @@
|
|
|
12
12
|
* topic will be: "ADS/GM.fReal"
|
|
13
13
|
*/
|
|
14
14
|
import { HubBase } from './HubBase';
|
|
15
|
-
|
|
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
|
-
}
|
|
15
|
+
import { CommandMessage, CommandMessageResult } from "./CommandMessage";
|
|
27
16
|
export declare class HubWebSocket extends HubBase {
|
|
28
17
|
private socket;
|
|
29
18
|
private requestId;
|
|
30
19
|
private pendingRequests;
|
|
31
20
|
constructor();
|
|
32
|
-
invoke: (domain: string, fname: string, payload?: object) => Promise<
|
|
21
|
+
invoke: (domain: string, fname: string, payload?: object) => Promise<CommandMessageResult>;
|
|
33
22
|
handleUnsolicitedMessage: (msg: CommandMessage) => void;
|
|
34
23
|
disconnect: () => void;
|
|
35
24
|
protected emit: (eventName: string, payload?: object) => void;
|
|
36
25
|
}
|
|
37
|
-
export {};
|
package/dist/hub/HubWebSocket.js
CHANGED
|
@@ -1 +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,
|
|
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,r)=>{const n=++this.requestId;this.pendingRequests.set(n,{resolve:i,reject:r});let o={request_id:n,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.result):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
|
@@ -2,6 +2,7 @@ import { HubBase as Hub } from './HubBase';
|
|
|
2
2
|
import { HubTauri } from './HubTauri';
|
|
3
3
|
import { HubWebSocket } from "./HubWebSocket";
|
|
4
4
|
import { HubSimulate } from "./HubSimulate";
|
|
5
|
+
import { CommandMessage, CommandMessageResult } from './CommandMessage';
|
|
5
6
|
/**
|
|
6
7
|
* Creates a connection to the backend.
|
|
7
8
|
* @returns Hub
|
|
@@ -11,3 +12,4 @@ export { HubBase as Hub } from './HubBase';
|
|
|
11
12
|
export { HubTauri };
|
|
12
13
|
export { HubWebSocket };
|
|
13
14
|
export { HubSimulate };
|
|
15
|
+
export type { CommandMessage, CommandMessageResult };
|
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-04-
|
|
5
|
+
* Last Modified: 2024-04-24 12:11:16
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import React, { createContext, ReactNode, useState, useMemo } from 'react';
|
|
13
13
|
import {createHub, Hub} from "../hub";
|
|
14
|
+
import {CommandMessageResult} from "../hub/CommandMessage";
|
|
14
15
|
|
|
15
16
|
export {Hub};
|
|
16
17
|
|
|
@@ -103,7 +104,7 @@ export interface EventEmitterContextType {
|
|
|
103
104
|
* Invoke/send a message to the back end.
|
|
104
105
|
* This does NOT get published to the front end.
|
|
105
106
|
*/
|
|
106
|
-
invoke( domain: string, fname: string, payload? : object) : Promise<
|
|
107
|
+
invoke( domain: string, fname: string, payload? : object) : Promise<CommandMessageResult>;
|
|
107
108
|
|
|
108
109
|
/**
|
|
109
110
|
* Subscribe to events identified by the topic.
|
|
@@ -268,9 +269,14 @@ export const EventEmitterContext = createContext<EventEmitterContextType>({
|
|
|
268
269
|
domain;
|
|
269
270
|
fname;
|
|
270
271
|
payload;
|
|
272
|
+
let ret :CommandMessageResult = {
|
|
273
|
+
data: {},
|
|
274
|
+
success: false,
|
|
275
|
+
error_message : ""
|
|
276
|
+
};
|
|
271
277
|
// Placeholder for invoke logic
|
|
272
278
|
// Implement the logic to send a message to the backend and return a promise
|
|
273
|
-
return Promise.resolve(
|
|
279
|
+
return Promise.resolve(ret); // Example placeholder, replace with actual implementation
|
|
274
280
|
},
|
|
275
281
|
unsubscribe: (subscriptionId: number) => { subscriptionId;}, // Placeholder for unsubscription logic
|
|
276
282
|
hub: null,
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
+
* Created Date: 2024-04-24 11:47:13
|
|
4
|
+
* -----
|
|
5
|
+
* Last Modified: 2024-04-24 11:48:08
|
|
6
|
+
* -----
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
/// The result portion of a CommandMessage. The server will
|
|
13
|
+
/// place the result of a command in this portion of the message.
|
|
14
|
+
export interface CommandMessageResult {
|
|
15
|
+
/// The JSON object of the result.
|
|
16
|
+
data: any;
|
|
17
|
+
/// If true, the command was processed successfully.
|
|
18
|
+
success : boolean,
|
|
19
|
+
/// If success is false, this should contain a corresponding error message.
|
|
20
|
+
error_message: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// CommandMessage is the object passed between the client and server for making requests and
|
|
24
|
+
/// responses.
|
|
25
|
+
export interface CommandMessage {
|
|
26
|
+
/// An id to identify the request. The request ID is managed by the client and will be reflected back.
|
|
27
|
+
/// The server will never change the request ID.
|
|
28
|
+
request_id: number;
|
|
29
|
+
/// The command domain/servelet in which this command/function to invoke belongs.
|
|
30
|
+
domain: string;
|
|
31
|
+
/// The name of the function to invoke.
|
|
32
|
+
fname: string;
|
|
33
|
+
/// A JSON object of the arguments to the function.
|
|
34
|
+
args?: any;
|
|
35
|
+
/// The result of the command, reflected back from the server
|
|
36
|
+
result?: CommandMessageResult;
|
|
37
|
+
}
|
package/src/hub/HubBase.ts
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
* Created Date: 2023-12-15 14:21:33
|
|
4
4
|
* Author: Thomas C. Bitsky Jr.
|
|
5
5
|
* -----
|
|
6
|
-
* Last Modified: 2024-04-
|
|
6
|
+
* Last Modified: 2024-04-24 11:56:16
|
|
7
7
|
* Modified By: ADC
|
|
8
8
|
* -----
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { EventEmitterContextType} from '../core/EventEmitterContext';
|
|
13
|
-
|
|
13
|
+
import {CommandMessageResult} from "./CommandMessage";
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -122,7 +122,7 @@ 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(domain: string, fname: string, payload? : object) : Promise<
|
|
125
|
+
abstract invoke(domain: string, fname: string, payload? : object) : Promise<CommandMessageResult>;
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
/**
|
|
@@ -134,7 +134,7 @@ export abstract class HubBase {
|
|
|
134
134
|
* @param topic string Topic
|
|
135
135
|
* @param value any data payload
|
|
136
136
|
*/
|
|
137
|
-
invokeTopic( domain: string, fname : string, topic : string | null, value? : any ) : Promise<
|
|
137
|
+
invokeTopic( domain: string, fname : string, topic : string | null, value? : any ) : Promise<CommandMessageResult> {
|
|
138
138
|
const msg = {
|
|
139
139
|
topic : topic,
|
|
140
140
|
data : value
|
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-04-
|
|
5
|
+
* Last Modified: 2024-04-24 11:56:26
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
import { HubBase } from './HubBase';
|
|
13
|
-
|
|
13
|
+
import { CommandMessageResult } from "./CommandMessage";
|
|
14
14
|
/**
|
|
15
15
|
* Hub for simulating functionality when no backend is present.
|
|
16
16
|
*/
|
|
@@ -31,14 +31,21 @@ 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(domain
|
|
34
|
+
invoke(domain: string, fname: string, payload?: object, timeout: number = 20): Promise<CommandMessageResult> {
|
|
35
35
|
domain; // Not using for simulator
|
|
36
36
|
fname; // Not using for simulator
|
|
37
37
|
return new Promise((resolve, reject) => {
|
|
38
38
|
reject; // not using for simulator
|
|
39
39
|
// Set a timeout to echo a response
|
|
40
40
|
setTimeout(() => {
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
let ret: CommandMessageResult = {
|
|
43
|
+
data: payload,
|
|
44
|
+
error_message: "",
|
|
45
|
+
success: true
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
resolve(ret);
|
|
42
49
|
}, timeout);
|
|
43
50
|
});
|
|
44
51
|
}
|
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-04-
|
|
6
|
+
* Last Modified: 2024-04-24 11:56:32
|
|
7
7
|
* Modified By: ADC
|
|
8
8
|
* -----
|
|
9
9
|
*
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { InvokeArgs } from '@tauri-apps/api/tauri';
|
|
13
13
|
import { HubBase } from './HubBase';
|
|
14
14
|
import {event, invoke} from '@tauri-apps/api';
|
|
15
|
-
|
|
15
|
+
import {CommandMessageResult} from "./CommandMessage";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Hub for integrating with the Tauri backend.
|
|
@@ -128,7 +128,7 @@ 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(domain : string, fname: string, payload?: object | undefined): Promise<
|
|
131
|
+
invoke(domain : string, fname: string, payload?: object | undefined): Promise<CommandMessageResult> {
|
|
132
132
|
|
|
133
133
|
console.log(JSON.stringify(event));
|
|
134
134
|
|
package/src/hub/HubWebSocket.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
3
|
* Created Date: 2024-04-17 09:13:07
|
|
4
4
|
* -----
|
|
5
|
-
* Last Modified: 2024-04-
|
|
5
|
+
* Last Modified: 2024-04-24 11:56:51
|
|
6
6
|
* -----
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
@@ -22,33 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
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
|
-
}
|
|
25
|
+
import {CommandMessage, CommandMessageResult} from "./CommandMessage";
|
|
52
26
|
|
|
53
27
|
// Function to parse the JSON string received from the server into a CommandMessage object
|
|
54
28
|
// function parseCommandMessage(jsonString: string): CommandMessage {
|
|
@@ -95,7 +69,7 @@ export class HubWebSocket extends HubBase {
|
|
|
95
69
|
if (!data.result?.success) {
|
|
96
70
|
reject(new Error(data.result?.error_message));
|
|
97
71
|
} else {
|
|
98
|
-
resolve(data);
|
|
72
|
+
resolve(data.result);
|
|
99
73
|
}
|
|
100
74
|
this.pendingRequests.delete(data.request_id);
|
|
101
75
|
} else {
|
|
@@ -112,7 +86,7 @@ export class HubWebSocket extends HubBase {
|
|
|
112
86
|
};
|
|
113
87
|
}
|
|
114
88
|
|
|
115
|
-
invoke = (domain : string, fname: string, payload?: object): Promise<
|
|
89
|
+
invoke = (domain : string, fname: string, payload?: object): Promise<CommandMessageResult> => {
|
|
116
90
|
|
|
117
91
|
return new Promise((resolve, reject) => {
|
|
118
92
|
const id = ++this.requestId; // Increment and use the request ID
|
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-04-
|
|
5
|
+
* Last Modified: 2024-04-24 11:52:21
|
|
6
6
|
* Modified By: ADC
|
|
7
7
|
* -----
|
|
8
8
|
*
|
|
@@ -12,6 +12,7 @@ import { HubBase as Hub } from './HubBase';
|
|
|
12
12
|
import { HubTauri } from './HubTauri';
|
|
13
13
|
import { HubWebSocket } from "./HubWebSocket";
|
|
14
14
|
import {HubSimulate} from "./HubSimulate"
|
|
15
|
+
import { CommandMessage, CommandMessageResult } from './CommandMessage';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Creates a connection to the backend.
|
|
@@ -19,8 +20,6 @@ import {HubSimulate} from "./HubSimulate"
|
|
|
19
20
|
*/
|
|
20
21
|
export function createHub(): Hub {
|
|
21
22
|
|
|
22
|
-
console.log("HELLOW THERRE!!!");
|
|
23
|
-
|
|
24
23
|
if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
|
|
25
24
|
// Standalone Tauri application
|
|
26
25
|
console.log("HUB: Starting link to Tauri backend.");
|
|
@@ -53,3 +52,4 @@ export {HubBase as Hub} from './HubBase';
|
|
|
53
52
|
export {HubTauri}
|
|
54
53
|
export {HubWebSocket}
|
|
55
54
|
export {HubSimulate}
|
|
55
|
+
export type {CommandMessage, CommandMessageResult}
|