@adcops/autocore-react 3.1.1 → 3.3.5
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/additional-docs/react_performance_notes.md +94 -0
- package/dist/components/AutoCoreDevPanel.d.ts.map +1 -1
- package/dist/components/AutoCoreDevPanel.js +1 -1
- package/dist/components/FileList.d.ts.map +1 -1
- package/dist/components/FileList.js +1 -1
- package/dist/components/FileSelect.d.ts.map +1 -1
- package/dist/components/FileSelect.js +1 -1
- package/dist/core/AutoCoreTagContext.d.ts +59 -185
- package/dist/core/AutoCoreTagContext.d.ts.map +1 -1
- package/dist/core/AutoCoreTagContext.js +1 -1
- package/dist/core/AutoCoreTagTypes.d.ts +127 -6
- package/dist/core/AutoCoreTagTypes.d.ts.map +1 -1
- package/dist/core/CoreStreamTypes.d.ts +345 -0
- package/dist/core/CoreStreamTypes.d.ts.map +1 -0
- package/dist/core/CoreStreamTypes.js +1 -0
- package/dist/core/EventEmitterContext.d.ts +91 -473
- package/dist/core/EventEmitterContext.d.ts.map +1 -1
- package/dist/core/EventEmitterContext.js +1 -1
- package/dist/hooks/adsHooks.d.ts.map +1 -1
- package/dist/hooks/adsHooks.js +1 -1
- package/dist/hooks/commandHooks.d.ts +3 -3
- package/dist/hooks/commandHooks.d.ts.map +1 -1
- package/dist/hooks/commandHooks.js +1 -1
- package/dist/hooks/useAutoCoreTag.js +1 -1
- package/dist/hub/CommandMessage.d.ts +18 -9
- package/dist/hub/CommandMessage.d.ts.map +1 -1
- package/dist/hub/CommandMessage.js +1 -1
- package/dist/hub/DebugPanel.d.ts +31 -0
- package/dist/hub/DebugPanel.d.ts.map +1 -0
- package/dist/hub/DebugPanel.js +1 -0
- package/dist/hub/HubBase.d.ts +83 -129
- package/dist/hub/HubBase.d.ts.map +1 -1
- package/dist/hub/HubBase.js +1 -1
- package/dist/hub/HubSimulate.d.ts +41 -8
- package/dist/hub/HubSimulate.d.ts.map +1 -1
- package/dist/hub/HubSimulate.js +1 -1
- package/dist/hub/HubTauri.d.ts +24 -60
- package/dist/hub/HubTauri.d.ts.map +1 -1
- package/dist/hub/HubTauri.js +1 -1
- package/dist/hub/HubWebSocket.d.ts +33 -17
- package/dist/hub/HubWebSocket.d.ts.map +1 -1
- package/dist/hub/HubWebSocket.js +1 -1
- package/dist/hub/debug.d.ts +23 -0
- package/dist/hub/debug.d.ts.map +1 -0
- package/dist/hub/debug.js +1 -0
- package/dist/hub/index.d.ts +19 -4
- package/dist/hub/index.d.ts.map +1 -1
- package/dist/hub/index.js +1 -1
- package/package.json +8 -4
- package/src/components/AutoCoreDevPanel.tsx +14 -11
- package/src/components/FileList.tsx +5 -4
- package/src/components/FileSelect.tsx +2 -1
- package/src/core/ActionMode.ts +1 -1
- package/src/core/AutoCoreTagContext.tsx +247 -330
- package/src/core/AutoCoreTagTypes.ts +236 -104
- package/src/core/CoreStreamTypes.ts +512 -0
- package/src/core/EventEmitterContext.tsx +182 -520
- package/src/core/IndicatorButtonState.ts +1 -1
- package/src/core/hoc.tsx +1 -1
- package/src/hooks/adsHooks.tsx +21 -22
- package/src/hooks/commandHooks.tsx +23 -19
- package/src/hooks/index.ts +1 -1
- package/src/hooks/useAutoCoreTag.ts +2 -2
- package/src/hooks/useScaledValue.tsx +1 -1
- package/src/hub/CommandMessage.ts +71 -19
- package/src/hub/DebugPanel.ts +280 -0
- package/src/hub/HubBase.ts +147 -223
- package/src/hub/HubSimulate.ts +93 -24
- package/src/hub/HubTauri.ts +87 -96
- package/src/hub/HubWebSocket.ts +118 -140
- package/src/hub/debug.ts +211 -0
- package/src/hub/index.ts +49 -39
- package/docs/.nojekyll +0 -1
- package/docs/assets/hierarchy.js +0 -1
- package/docs/assets/highlight.css +0 -134
- package/docs/assets/icons.js +0 -18
- package/docs/assets/icons.svg +0 -1
- package/docs/assets/main.js +0 -60
- package/docs/assets/navigation.js +0 -1
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1633
- package/docs/classes/components_CodeEditor.CodeEditor.html +0 -135
- package/docs/classes/components_Indicator.Indicator.html +0 -122
- package/docs/classes/components_IndicatorRect.IndicatorRect.html +0 -121
- package/docs/classes/components_JogPanel.JogPanel.html +0 -136
- package/docs/classes/components_Lamp.Lamp.html +0 -122
- package/docs/classes/components_OskDialog.OskDialog.html +0 -125
- package/docs/classes/components_TextInput.TextInput.html +0 -125
- package/docs/classes/components_ValueDisplay.ValueDisplay.html +0 -148
- package/docs/classes/components_ValueIndicator.ValueIndicator.html +0 -126
- package/docs/classes/core_ValueSimulator.ValueSimulator.html +0 -51
- package/docs/classes/hub_HubBase.HubBase.html +0 -106
- package/docs/classes/hub_HubSimulate.HubSimulate.html +0 -75
- package/docs/classes/hub_HubTauri.HubTauri.html +0 -93
- package/docs/classes/hub_HubWebSocket.HubWebSocket.html +0 -112
- package/docs/documents/core_AutoCoreTagContext.AutoCoreTagContext.html +0 -148
- package/docs/enums/components_JogPanel.JogDistanceAction.html +0 -5
- package/docs/enums/components_JogPanel.JogPanelAction.html +0 -18
- package/docs/enums/components_JogPanel.JogSpeedAction.html +0 -5
- package/docs/enums/core_ActionMode.ActionMode.html +0 -6
- package/docs/enums/core_IndicatorColor.IndicatorColor.html +0 -23
- package/docs/functions/assets.BlocklyLogo.html +0 -1
- package/docs/functions/assets.Distance.html +0 -1
- package/docs/functions/assets.JogLong.html +0 -1
- package/docs/functions/assets.JogMedium.html +0 -1
- package/docs/functions/assets.JogShort.html +0 -1
- package/docs/functions/assets.PythonLogo.html +0 -1
- package/docs/functions/assets.Rotation3D.html +0 -1
- package/docs/functions/assets.RotationCcw.html +0 -1
- package/docs/functions/assets.RotationCcwA.html +0 -1
- package/docs/functions/assets.RotationCcwB.html +0 -1
- package/docs/functions/assets.RotationCcwC.html +0 -1
- package/docs/functions/assets.RotationCw.html +0 -1
- package/docs/functions/assets.RotationCwA.html +0 -1
- package/docs/functions/assets.RotationCwB.html +0 -1
- package/docs/functions/assets.RotationCwC.html +0 -1
- package/docs/functions/assets.Run.html +0 -1
- package/docs/functions/assets.Speed.html +0 -1
- package/docs/functions/assets.SpeedFast.html +0 -1
- package/docs/functions/assets.SpeedMedium.html +0 -1
- package/docs/functions/assets.SpeedNone.html +0 -1
- package/docs/functions/assets.SpeedSlow.html +0 -1
- package/docs/functions/assets.Walk.html +0 -1
- package/docs/functions/components_BlocklyEditor.createCustomToolbox.html +0 -6
- package/docs/functions/core_UniqueId.UniqueId.html +0 -9
- package/docs/functions/core_hoc.hocAddSubscription.html +0 -6
- package/docs/functions/hooks_adsHooks.useAdsRegisterSymbols.html +0 -16
- package/docs/functions/hooks_adsHooks.useAdsTapValue.html +0 -8
- package/docs/functions/hooks_adsHooks.useAdsWriteScaledValue.html +0 -18
- package/docs/functions/hooks_adsHooks.useAdsWriteValue.html +0 -9
- package/docs/functions/hooks_commandHooks.useRegisterSymbols.html +0 -16
- package/docs/functions/hooks_commandHooks.useTapValue.html +0 -10
- package/docs/functions/hooks_commandHooks.useWriteScaledValue.html +0 -18
- package/docs/functions/hooks_commandHooks.useWriteValue.html +0 -11
- package/docs/functions/hooks_useAutoCoreTag.ts.makeAutoCoreTagHooks.html +0 -12
- package/docs/functions/hooks_useScaledValue.useScaledValue.html +0 -18
- package/docs/functions/hub.createHub.html +0 -3
- package/docs/hierarchy.html +0 -1
- package/docs/index.html +0 -148
- package/docs/interfaces/components_IndicatorButton.IndicatorButtonProps.html +0 -654
- package/docs/interfaces/components_IndicatorRect.IndicatorRectProps.html +0 -37
- package/docs/interfaces/components_JogPanel.JogPanelButtonDefinition.html +0 -5
- package/docs/interfaces/components_ToggleGroup.ToggleGroupProps.html +0 -644
- package/docs/interfaces/core_AutoCoreTagTypes.BaseContextValue.html +0 -12
- package/docs/interfaces/core_AutoCoreTagTypes.ScaleConfig.html +0 -13
- package/docs/interfaces/core_EventEmitterContext.Action.html +0 -8
- package/docs/interfaces/core_EventEmitterContext.EventEmitterContextType.html +0 -33
- package/docs/interfaces/core_EventEmitterContext.State.html +0 -8
- package/docs/interfaces/core_EventEmitterContext.Subscription.html +0 -6
- package/docs/interfaces/core_IndicatorButtonState.IndicatorButtonState.html +0 -10
- package/docs/interfaces/core_PositionContext.IPositionContext.html +0 -17
- package/docs/interfaces/hub_CommandMessage.CommandMessage.html +0 -6
- package/docs/interfaces/hub_CommandMessage.CommandMessageResult.html +0 -4
- package/docs/modules/assets.html +0 -1
- package/docs/modules/assets_BlocklyLogo.html +0 -1
- package/docs/modules/assets_Distance.html +0 -1
- package/docs/modules/assets_JogLong.html +0 -1
- package/docs/modules/assets_JogMedium.html +0 -1
- package/docs/modules/assets_JogShort.html +0 -1
- package/docs/modules/assets_PythonLogo.html +0 -1
- package/docs/modules/assets_Rotation3D.html +0 -1
- package/docs/modules/assets_RotationCcw.html +0 -1
- package/docs/modules/assets_RotationCcwA.html +0 -1
- package/docs/modules/assets_RotationCcwB.html +0 -1
- package/docs/modules/assets_RotationCcwC.html +0 -1
- package/docs/modules/assets_RotationCw.html +0 -1
- package/docs/modules/assets_RotationCwA.html +0 -1
- package/docs/modules/assets_RotationCwB.html +0 -1
- package/docs/modules/assets_RotationCwC.html +0 -1
- package/docs/modules/assets_Run.html +0 -1
- package/docs/modules/assets_Speed.html +0 -1
- package/docs/modules/assets_SpeedFast.html +0 -1
- package/docs/modules/assets_SpeedMedium.html +0 -1
- package/docs/modules/assets_SpeedNone.html +0 -1
- package/docs/modules/assets_SpeedSlow.html +0 -1
- package/docs/modules/assets_Walk.html +0 -1
- package/docs/modules/components_AutoCoreDevPanel.html +0 -20
- package/docs/modules/components_BlocklyEditor.html +0 -1
- package/docs/modules/components_CodeEditor.html +0 -1
- package/docs/modules/components_FileList.html +0 -1
- package/docs/modules/components_FileSelect.html +0 -1
- package/docs/modules/components_FitText.html +0 -1
- package/docs/modules/components_Indicator.html +0 -1
- package/docs/modules/components_IndicatorButton.html +0 -1
- package/docs/modules/components_IndicatorRect.html +0 -1
- package/docs/modules/components_JogPanel.html +0 -1
- package/docs/modules/components_Lamp.html +0 -1
- package/docs/modules/components_Osk.html +0 -1
- package/docs/modules/components_OskDialog.html +0 -1
- package/docs/modules/components_ProgressBarWithValue.html +0 -1
- package/docs/modules/components_TextInput.html +0 -1
- package/docs/modules/components_ToggleGroup.html +0 -1
- package/docs/modules/components_ValueDisplay.html +0 -1
- package/docs/modules/components_ValueIndicator.html +0 -1
- package/docs/modules/components_ValueInput.html +0 -1
- package/docs/modules/core_ActionMode.html +0 -1
- package/docs/modules/core_AutoCoreTagContext.html +0 -11
- package/docs/modules/core_AutoCoreTagTypes.html +0 -1
- package/docs/modules/core_EventEmitterContext.html +0 -53
- package/docs/modules/core_IndicatorButtonState.html +0 -1
- package/docs/modules/core_IndicatorColor.html +0 -1
- package/docs/modules/core_MaskPatterns.html +0 -1
- package/docs/modules/core_NumerableTypes.html +0 -1
- package/docs/modules/core_PositionContext.html +0 -1
- package/docs/modules/core_UniqueId.html +0 -1
- package/docs/modules/core_ValueSimulator.html +0 -1
- package/docs/modules/core_hoc.html +0 -1
- package/docs/modules/hooks.html +0 -1
- package/docs/modules/hooks_adsHooks.html +0 -1
- package/docs/modules/hooks_commandHooks.html +0 -1
- package/docs/modules/hooks_useAutoCoreTag.ts.html +0 -52
- package/docs/modules/hooks_useScaledValue.html +0 -1
- package/docs/modules/hub.html +0 -1
- package/docs/modules/hub_CommandMessage.html +0 -1
- package/docs/modules/hub_HubBase.html +0 -1
- package/docs/modules/hub_HubSimulate.html +0 -1
- package/docs/modules/hub_HubTauri.html +0 -1
- package/docs/modules/hub_HubWebSocket.html +0 -1
- package/docs/modules.html +0 -23
- package/docs/types/components_IndicatorButton.IndicatorButtonOptionsType.html +0 -1
- package/docs/types/core_AutoCoreTagTypes.ExtractByTag.html +0 -2
- package/docs/types/core_AutoCoreTagTypes.PrimitiveKind.html +0 -1
- package/docs/types/core_AutoCoreTagTypes.TagConfig.html +0 -16
- package/docs/types/core_AutoCoreTagTypes.TagValueMap.html +0 -1
- package/docs/types/core_AutoCoreTagTypes.TagValueOf.html +0 -1
- package/docs/types/core_EventEmitterContext.EmitterDispatchFunction.html +0 -3
- package/docs/types/core_EventEmitterContext.EmitterSubscribeFunction.html +0 -3
- package/docs/types/core_EventEmitterContext.EmitterUnsubscribeFunction.html +0 -3
- package/docs/types/core_NumerableTypes.NumerableFormatOptions.html +0 -4
- package/docs/types/core_hoc.HocAddSubscriptionProps.html +0 -6
- package/docs/variables/components_AutoCoreDevPanel.AutoCoreDevPanel.html +0 -43
- package/docs/variables/components_BlocklyEditor.BlocklyEditor.html +0 -13
- package/docs/variables/components_BlocklyEditor.StandardToolbox.html +0 -1
- package/docs/variables/components_FileList.FileList.html +0 -23
- package/docs/variables/components_FileSelect.FileSelect.html +0 -1
- package/docs/variables/components_FitText.FitText.html +0 -4
- package/docs/variables/components_IndicatorButton.IndicatorButton.html +0 -1
- package/docs/variables/components_JogPanel.DefaultLinearJogButtons.html +0 -2
- package/docs/variables/components_JogPanel.DefaultRotationJogButtons.html +0 -2
- package/docs/variables/components_Osk.Osk.html +0 -1
- package/docs/variables/components_ProgressBarWithValue.ProgressBarWithValue.html +0 -1
- package/docs/variables/components_ToggleGroup.ToggleGroup.html +0 -1
- package/docs/variables/components_ValueInput.ValueInput.html +0 -4
- package/docs/variables/core_AutoCoreTagContext.AutoCoreTagContext.html +0 -1
- package/docs/variables/core_AutoCoreTagContext.AutoCoreTagProvider.html +0 -7
- package/docs/variables/core_EventEmitterContext.EventEmitterContext.html +0 -64
- package/docs/variables/core_EventEmitterContext.EventEmitterProvider.html +0 -10
- package/docs/variables/core_MaskPatterns.PrimeReactMaskPatterns.html +0 -14
- package/docs/variables/core_MaskPatterns.RegExMaskPatterns.html +0 -15
- package/docs/variables/core_PositionContext.DimensionsContext.html +0 -6
- package/docs/variables/hooks_useScaledValue.kMillimeters2Inches.html +0 -2
- package/docs/variables/hooks_useScaledValue.kNewtons2Pounds.html +0 -2
package/dist/hooks/adsHooks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useContext,useRef,useEffect,useCallback}from"react";import{EventEmitterContext}from"../core/EventEmitterContext";function sleep(e){return new Promise(t=>setTimeout(t,e))}export const useAdsRegisterSymbols=(e,t,n={})=>{const{invoke:
|
|
1
|
+
import{useContext,useRef,useEffect,useCallback}from"react";import{EventEmitterContext}from"../core/EventEmitterContext";import{MessageType}from"../hub/CommandMessage";function sleep(e){return new Promise(t=>setTimeout(t,e))}export const useAdsRegisterSymbols=(e,t,n={})=>{const{invoke:s,subscribe:r,unsubscribe:o,isConnected:c}=useContext(EventEmitterContext),u=useRef([]),a=useRef(!0);return useEffect(()=>{a.current=!0;const i=async()=>{for(const[o,c]of Object.entries(t))try{const t=n[o]?{symbol_name:c,options:n[o]}:{symbol_name:c};await s("ADS.register_symbol",MessageType.Request,t);const i=r(`ADS/${c}`,t=>{if(a.current){const n=e[o];n&&n(t.value)}});u.current.push(i)}catch(e){}await s("ADS.refresh",MessageType.Request,{})};if(c())i();else{let e=r("HUB/connected",()=>{i(),o(e)});u.current.push(e)}return()=>{a.current=!1,u.current.forEach(e=>o(e)),u.current=[]}},[]),null};export function useAdsWriteValue(e){const{write:t}=useContext(EventEmitterContext);return async n=>{try{await t(`ADS.${e}`,n)}catch(e){}}}export function useAdsWriteScaledValue(e,t,n){const{write:s}=useContext(EventEmitterContext);return useCallback(async r=>{const o=(r-n)/t;try{await s(`ADS.${e}`,o)}catch(e){}},[e,t,n,s])}export function useAdsTapValue(e){const{write:t}=useContext(EventEmitterContext);return async()=>{try{const n=`ADS.${e}`;await t(n,!0),await sleep(300),await t(n,!1)}catch(e){}}}
|
|
@@ -65,7 +65,7 @@ export declare const useRegisterSymbols: (domain: string, setters: Record<string
|
|
|
65
65
|
* );
|
|
66
66
|
* };
|
|
67
67
|
*/
|
|
68
|
-
export declare function useWriteValue(domain: string, symbolName: string
|
|
68
|
+
export declare function useWriteValue(domain: string, symbolName: string): (value: object | boolean | number | string) => Promise<void>;
|
|
69
69
|
/**
|
|
70
70
|
* useWriteScaledValue is a custom React hook that enables writing scaled numerical values to the autocore backend system.
|
|
71
71
|
* It applies a specified scale and offset to a numeric value before sending it over the websocket connection.
|
|
@@ -114,7 +114,7 @@ export declare function useWriteValue(domain: string, symbolName: string, fname?
|
|
|
114
114
|
* converts it to millimeters using the current `scale`, and writes the result to a backend symbol. The `scale` and `offset` can be adjusted
|
|
115
115
|
* dynamically if needed, for instance, based on user selection or other external configurations.
|
|
116
116
|
*/
|
|
117
|
-
export declare function useWriteScaledValue(domain: string, symbolName: string, scale: number, offset: number
|
|
117
|
+
export declare function useWriteScaledValue(domain: string, symbolName: string, scale: number, offset: number): (value: number) => Promise<void>;
|
|
118
118
|
/**
|
|
119
119
|
* Custom hook to send a "tap" action, which sends true followed by false after a short delay,
|
|
120
120
|
* to a specified symbol in the backend. This is used to simulate a button tap or momentary switch.
|
|
@@ -142,5 +142,5 @@ export declare function useWriteScaledValue(domain: string, symbolName: string,
|
|
|
142
142
|
* };
|
|
143
143
|
* ```
|
|
144
144
|
*/
|
|
145
|
-
export declare function useTapValue(domain: string, symbolName: string
|
|
145
|
+
export declare function useTapValue(domain: string, symbolName: string): () => Promise<void>;
|
|
146
146
|
//# sourceMappingURL=commandHooks.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commandHooks.d.ts","sourceRoot":"","sources":["../../src/hooks/commandHooks.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"commandHooks.d.ts","sourceRoot":"","sources":["../../src/hooks/commandHooks.tsx"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,kBAAkB,GAC3B,QAAS,MAAM,EACf,SAAS,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC,EAC7C,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,UAAS,MAAM,CAAC,MAAM,EAAE,EAAE,CAAM,SAgEnC,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,IAI9C,OAAO,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,mBAQ1D;AAOD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,WAGhE,MAAM,mBAc1C;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAcnF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useContext,useRef,useEffect,useCallback}from"react";import{EventEmitterContext}from"../core/EventEmitterContext";function sleep(e){return new Promise(t=>setTimeout(t,e))}export const useRegisterSymbols=(e,t,n,r={})=>{const{subscribe:
|
|
1
|
+
import{useContext,useRef,useEffect,useCallback}from"react";import{EventEmitterContext}from"../core/EventEmitterContext";import{MessageType}from"../hub/CommandMessage";function sleep(e){return new Promise(t=>setTimeout(t,e))}export const useRegisterSymbols=(e,t,n,r={})=>{const{subscribe:s,unsubscribe:c,isConnected:o,invoke:u}=useContext(EventEmitterContext),a=useRef([]),i=useRef(!0);return useEffect(()=>{i.current=!0;const r=async()=>{for(const[r,c]of Object.entries(n))try{const n=s(`${e}/${c}`,e=>{if(i.current){const n=t[r];n&&n(e.value)}});a.current.push(n),await u(`${e}.${c}`,MessageType.Request,{action:"refresh"})}catch(e){}};if(o())r();else{let e=s("HUB/connected",()=>{setTimeout(()=>{r(),c(e)},500)});a.current.push(e)}return()=>{i.current=!1,a.current.forEach(e=>c(e)),a.current=[]}},[]),null};export function useWriteValue(e,t){const{write:n}=useContext(EventEmitterContext);return async r=>{try{await n(`${e}.${t}`,r)}catch(e){}}}export function useWriteScaledValue(e,t,n,r){const{write:s}=useContext(EventEmitterContext);return useCallback(async c=>{const o=(c-r)/n;try{await s(`${e}.${t}`,o)}catch(e){}},[e,t,n,r,s])}export function useTapValue(e,t){const{write:n}=useContext(EventEmitterContext);return async()=>{try{const r=`${e}.${t}`;await n(r,!0),await sleep(300),await n(r,!1)}catch(e){}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback,useContext,useMemo}from"react";export function makeAutoCoreTagHooks(e,a){return{useAutoCoreTag:
|
|
1
|
+
import{useCallback,useContext,useMemo}from"react";export function makeAutoCoreTagHooks(e,a){return{useAutoCoreTag:s=>{const{values:t,rawValues:u,isLoading:o,write:r,tap:n}=useContext(e),l=(e=>a.find(a=>a.fqdn===e))(s);if(!l)throw new Error(`useAutoCoreTag: unknown tagName '${String(s)}'`);const i=useCallback(e=>r(s,e),[r,s]),c=useCallback(()=>n?.(s),[n,s]);return{value:t[s],rawValue:u[s],write:i,tap:c,isLoading:o}},useAutoCoreTags:a=>{const{values:s,rawValues:t,isLoading:u,write:o}=useContext(e);return{values:useMemo(()=>Object.fromEntries(a.map(e=>[e,s[e]])),[s,a]),rawValues:useMemo(()=>Object.fromEntries(a.map(e=>[e,t[e]])),[t,a]),write:useCallback(async(e,a)=>{await o(e,a)},[o]),isLoading:u}},useAutoCoreSelect:(a,s=[])=>{const{values:t,isLoading:u}=useContext(e);return{selected:useMemo(()=>a(t),[t,...s]),isLoading:u}},useScales:()=>{const{scales:a,updateScale:s}=useContext(e),t=useCallback(e=>a[e],[a]);return{scales:a,updateScale:s,getScale:t}}}}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare enum MessageType {
|
|
2
|
+
NoOp = 0,
|
|
3
|
+
Response = 1,
|
|
4
|
+
Read = 2,
|
|
5
|
+
Write = 3,
|
|
6
|
+
Subscribe = 4,
|
|
7
|
+
Unsubscribe = 5,
|
|
8
|
+
Broadcast = 6,
|
|
9
|
+
Heartbeat = 7,
|
|
10
|
+
Control = 8,
|
|
11
|
+
Request = 10
|
|
5
12
|
}
|
|
6
13
|
export interface CommandMessage {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
transaction_id: number;
|
|
15
|
+
timecode: number;
|
|
16
|
+
topic: string;
|
|
17
|
+
message_type: MessageType;
|
|
18
|
+
data?: any;
|
|
19
|
+
success: boolean;
|
|
20
|
+
error_message: string;
|
|
12
21
|
}
|
|
13
22
|
//# sourceMappingURL=CommandMessage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandMessage.d.ts","sourceRoot":"","sources":["../../src/hub/CommandMessage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CommandMessage.d.ts","sourceRoot":"","sources":["../../src/hub/CommandMessage.ts"],"names":[],"mappings":"AAuBA,oBAAY,WAAW;IAEnB,IAAI,IAAI;IAGR,QAAQ,IAAI;IAGZ,IAAI,IAAI;IAGR,KAAK,IAAI;IAGT,SAAS,IAAI;IAGb,WAAW,IAAI;IAGf,SAAS,IAAI;IAGb,SAAS,IAAI;IAGb,OAAO,IAAI;IAGX,OAAO,KAAK;CACf;AAMD,MAAM,WAAW,cAAc;IAG3B,cAAc,EAAE,MAAM,CAAC;IAIvB,QAAQ,EAAE,MAAM,CAAC;IAKjB,KAAK,EAAE,MAAM,CAAC;IAGd,YAAY,EAAE,WAAW,CAAC;IAK1B,IAAI,CAAC,EAAE,GAAG,CAAC;IAIX,OAAO,EAAE,OAAO,CAAC;IAGjB,aAAa,EAAE,MAAM,CAAC;CAEzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export var MessageType;!function(e){e[e.NoOp=0]="NoOp",e[e.Response=1]="Response",e[e.Read=2]="Read",e[e.Write=3]="Write",e[e.Subscribe=4]="Subscribe",e[e.Unsubscribe=5]="Unsubscribe",e[e.Broadcast=6]="Broadcast",e[e.Heartbeat=7]="Heartbeat",e[e.Control=8]="Control",e[e.Request=10]="Request"}(MessageType||(MessageType={}));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
interface DebugLog {
|
|
2
|
+
time: string;
|
|
3
|
+
type: "info" | "warn" | "error" | "send" | "recv";
|
|
4
|
+
source: string;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
declare class DebugPanel {
|
|
8
|
+
private container;
|
|
9
|
+
private logContainer;
|
|
10
|
+
private statsContainer;
|
|
11
|
+
private logs;
|
|
12
|
+
private maxLogs;
|
|
13
|
+
private stats;
|
|
14
|
+
constructor();
|
|
15
|
+
private injectPanel;
|
|
16
|
+
private setupElements;
|
|
17
|
+
private updateStats;
|
|
18
|
+
log(type: DebugLog["type"], source: string, message: string): void;
|
|
19
|
+
private renderLogs;
|
|
20
|
+
hubCreated(): void;
|
|
21
|
+
connectCalled(socketState: string): void;
|
|
22
|
+
wsOpened(url: string): void;
|
|
23
|
+
wsClosed(code: number, reason: string): void;
|
|
24
|
+
wsError(error: string): void;
|
|
25
|
+
messageSent(type: string, command: string, requestId: number): void;
|
|
26
|
+
messageReceived(type: string, command: string, requestId?: number): void;
|
|
27
|
+
updateState(state: string): void;
|
|
28
|
+
}
|
|
29
|
+
export declare function getDebugPanel(): DebugPanel;
|
|
30
|
+
export default getDebugPanel;
|
|
31
|
+
//# sourceMappingURL=DebugPanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DebugPanel.d.ts","sourceRoot":"","sources":["../../src/hub/DebugPanel.ts"],"names":[],"mappings":"AAWA,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,cAAM,UAAU;IACd,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,IAAI,CAAkB;IAC9B,OAAO,CAAC,OAAO,CAAO;IAGtB,OAAO,CAAC,KAAK,CASX;;IAOF,OAAO,CAAC,WAAW;IA2FnB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,WAAW;IAsBnB,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAyBlE,OAAO,CAAC,UAAU;IAgBlB,UAAU,IAAI,IAAI;IAMlB,aAAa,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAOxC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAO3B,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAO5C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM5B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAMnE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI;IAMxE,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;CAIjC;AAKD,wBAAgB,aAAa,IAAI,UAAU,CAO1C;AAKD,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class DebugPanel{constructor(){Object.defineProperty(this,"container",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"statsContainer",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"logs",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"maxLogs",{enumerable:!0,configurable:!0,writable:!0,value:100}),Object.defineProperty(this,"stats",{enumerable:!0,configurable:!0,writable:!0,value:{hubInstancesCreated:0,connectCalls:0,wsOpened:0,wsClosed:0,wsErrors:0,messagesSent:0,messagesReceived:0,currentState:"unknown"}}),this.injectPanel(),this.log("info","DebugPanel","Debug panel initialized")}injectPanel(){const e=document.getElementById("autocore-debug-panel");e&&e.remove(),this.container=document.createElement("div"),this.container.id="autocore-debug-panel",this.container.innerHTML='\n <style>\n #autocore-debug-panel {\n position: fixed;\n bottom: 10px;\n right: 10px;\n width: 400px;\n max-height: 300px;\n background: rgba(0, 0, 0, 0.9);\n color: #0f0;\n font-family: monospace;\n font-size: 11px;\n border: 1px solid #0f0;\n border-radius: 4px;\n z-index: 99999;\n overflow: hidden;\n }\n #autocore-debug-panel .header {\n background: #0f0;\n color: #000;\n padding: 4px 8px;\n font-weight: bold;\n cursor: pointer;\n display: flex;\n justify-content: space-between;\n }\n #autocore-debug-panel .stats {\n padding: 4px 8px;\n border-bottom: 1px solid #0f0;\n display: grid;\n grid-template-columns: 1fr 1fr;\n gap: 2px;\n }\n #autocore-debug-panel .stats span {\n color: #fff;\n }\n #autocore-debug-panel .stats .value {\n color: #ff0;\n }\n #autocore-debug-panel .logs {\n max-height: 180px;\n overflow-y: auto;\n padding: 4px;\n }\n #autocore-debug-panel .log-entry {\n margin: 1px 0;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n #autocore-debug-panel .log-entry.info { color: #888; }\n #autocore-debug-panel .log-entry.warn { color: #fa0; }\n #autocore-debug-panel .log-entry.error { color: #f44; }\n #autocore-debug-panel .log-entry.send { color: #4f4; }\n #autocore-debug-panel .log-entry.recv { color: #44f; }\n #autocore-debug-panel .state-connected { color: #4f4 !important; }\n #autocore-debug-panel .state-disconnected { color: #f44 !important; }\n #autocore-debug-panel .state-connecting { color: #fa0 !important; }\n </style>\n <div class="header">\n <span>AutoCore Debug</span>\n <span id="debug-toggle">[_]</span>\n </div>\n <div id="debug-content">\n <div class="stats" id="debug-stats"></div>\n <div class="logs" id="debug-logs"></div>\n </div>\n ',document.body?(document.body.appendChild(this.container),this.setupElements()):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(this.container),this.setupElements()})}setupElements(){this.statsContainer=document.getElementById("debug-stats"),this.logContainer=document.getElementById("debug-logs");const e=document.getElementById("debug-toggle"),t=document.getElementById("debug-content");e?.addEventListener("click",()=>{t&&(t.style.display="none"===t.style.display?"block":"none",e.textContent="none"===t.style.display?"[+]":"[_]")}),this.updateStats()}updateStats(){if(!this.statsContainer)return;const e="OPEN"===this.stats.currentState?"state-connected":"CONNECTING"===this.stats.currentState?"state-connecting":"state-disconnected";this.statsContainer.innerHTML=`\n <div><span>Hub Instances:</span> <span class="value">${this.stats.hubInstancesCreated}</span></div>\n <div><span>connect() calls:</span> <span class="value">${this.stats.connectCalls}</span></div>\n <div><span>WS Opened:</span> <span class="value">${this.stats.wsOpened}</span></div>\n <div><span>WS Closed:</span> <span class="value">${this.stats.wsClosed}</span></div>\n <div><span>WS Errors:</span> <span class="value">${this.stats.wsErrors}</span></div>\n <div><span>Msgs Sent:</span> <span class="value">${this.stats.messagesSent}</span></div>\n <div><span>Msgs Recv:</span> <span class="value">${this.stats.messagesReceived}</span></div>\n <div><span>WS State:</span> <span class="value ${e}">${this.stats.currentState}</span></div>\n `}log(e,t,n){const s=(new Date).toTimeString().slice(0,8),a={time:s,type:e,source:t,message:n};this.logs.push(a),this.logs.length>this.maxLogs&&this.logs.shift();this.renderLogs()}renderLogs(){this.logContainer&&(this.logContainer.innerHTML=this.logs.slice(-50).map(e=>`<div class="log-entry ${e.type}">[${e.time}] ${e.source}: ${e.message}</div>`).join(""),this.logContainer.scrollTop=this.logContainer.scrollHeight)}hubCreated(){this.stats.hubInstancesCreated++,this.log("warn","Hub",`NEW INSTANCE CREATED (total: ${this.stats.hubInstancesCreated})`),this.updateStats()}connectCalled(e){this.stats.connectCalls++,this.stats.currentState=e,this.log("info","Hub",`connect() called (socket state: ${e})`),this.updateStats()}wsOpened(e){this.stats.wsOpened++,this.stats.currentState="OPEN",this.log("info","WS",`OPENED: ${e}`),this.updateStats()}wsClosed(e,t){this.stats.wsClosed++,this.stats.currentState="CLOSED",this.log("warn","WS",`CLOSED: code=${e}, reason=${t}`),this.updateStats()}wsError(e){this.stats.wsErrors++,this.log("error","WS",`ERROR: ${e}`),this.updateStats()}messageSent(e,t,n){this.stats.messagesSent++,this.log("send","WS",`>>> ${e}/${t} (id=${n})`),this.updateStats()}messageReceived(e,t,n){this.stats.messagesReceived++,this.log("recv","WS",`<<< ${e}/${t} (id=${n??"none"})`),this.updateStats()}updateState(e){this.stats.currentState=e,this.updateStats()}}let debugPanel=null;export function getDebugPanel(){return debugPanel||(debugPanel=new DebugPanel,window.__AUTOCORE_DEBUG_PANEL__=debugPanel),debugPanel}getDebugPanel();export default getDebugPanel;
|
package/dist/hub/HubBase.d.ts
CHANGED
|
@@ -1,182 +1,136 @@
|
|
|
1
1
|
import type { EventEmitterContextType } from '../core/EventEmitterContext';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommandMessage } from "./CommandMessage";
|
|
3
|
+
import { MessageType } from "./CommandMessage";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* or something else.
|
|
5
|
+
* @class HubBase
|
|
6
|
+
* @abstract
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Abstract base class that defines the interface for communicating with the AutoCore backend.
|
|
9
|
+
* Implementations (like `HubWebSocket` or `HubTauri`) handle the specific transport mechanics.
|
|
9
10
|
*
|
|
10
|
-
*
|
|
11
|
-
* The hub can be used to publish and subscribe to
|
|
12
|
-
* topics in the front-end, regardless of being connected to any backend.
|
|
11
|
+
* ## Core Responsibilities
|
|
13
12
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* return () => {
|
|
24
|
-
* unsubscribe(unsubscribeControlPower);
|
|
25
|
-
* }
|
|
26
|
-
* }, [] );
|
|
27
|
-
*
|
|
28
|
-
* const onPbPressed = () => {
|
|
29
|
-
* let count = 1;
|
|
30
|
-
* dispatch({
|
|
31
|
-
* topic: "my-awesome-topic",
|
|
32
|
-
* payload: count
|
|
33
|
-
* });
|
|
34
|
-
* }
|
|
35
|
-
*
|
|
36
|
-
* ```
|
|
37
|
-
* The hub should also be used for invoking events in the backend.
|
|
38
|
-
* This example will call the function "update_count" in the backend, passing
|
|
39
|
-
* the expected argument "count". Details of the interaction between the Hub and
|
|
40
|
-
* the backend will be handled by the appropriate HubBase sub-class, and should
|
|
41
|
-
* be transparent to the front end.
|
|
42
|
-
*
|
|
43
|
-
* ```
|
|
44
|
-
* const {invoke} = useContext(EventEmitterContext);
|
|
45
|
-
* const incrementCount = () => {
|
|
46
|
-
* count += 1;
|
|
47
|
-
* invoke('update_count', {"count": count});
|
|
48
|
-
* };
|
|
49
|
-
*
|
|
50
|
-
* Subscribing to a topic is simple. The type of value received is specific
|
|
51
|
-
* to the topic.
|
|
13
|
+
* 1. **Transport Abstraction**: Provides a unified API (`read`, `write`, `subscribe`) regardless of
|
|
14
|
+
* underlying transport (WS, IPC, etc.).
|
|
15
|
+
* 2. **Topic Mapping**: Maintains a bidirectional mapping between local `tagName` (UI friendly)
|
|
16
|
+
* and backend `FQDN` (Fully Qualified Domain Name).
|
|
17
|
+
* - `tagName`: "motorsEnable"
|
|
18
|
+
* - `FQDN`: "ADS.Main.bMotorsEnable"
|
|
19
|
+
* 3. **Event Dispatching**: Routes incoming messages from the backend to the `EventEmitterContext`.
|
|
52
20
|
*
|
|
53
|
-
*
|
|
54
|
-
* ```
|
|
55
|
-
* const {subscribe, unsubscribe} = useContext(EventEmitterContext);
|
|
56
|
-
* useEffect(() => {
|
|
57
|
-
* const unsubscripeMp = subscribe('xarm-position', (value) => {
|
|
58
|
-
* // The publisher sent a JSON object of 3D position values.
|
|
59
|
-
* setX(value.x);
|
|
60
|
-
* setY(value.y);
|
|
61
|
-
* setZ(value.z);
|
|
62
|
-
* setA(value.roll);
|
|
63
|
-
* setB(value.yaw);
|
|
64
|
-
* setC(value.pitch);
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* return () => {
|
|
68
|
-
* unsubscribe(unsubscripeMp);
|
|
69
|
-
* }
|
|
21
|
+
* ## Usage
|
|
70
22
|
*
|
|
71
|
-
*
|
|
23
|
+
* The `Hub` is typically accessed via the `EventEmitterContext`:
|
|
72
24
|
*
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const { hub } = useContext(EventEmitterContext);
|
|
27
|
+
* await hub.write("ADS.Main.nSpeed", 500);
|
|
73
28
|
* ```
|
|
74
|
-
*
|
|
75
29
|
*/
|
|
76
30
|
export declare abstract class HubBase {
|
|
31
|
+
/** Maps local tag names to backend FQDNs. */
|
|
77
32
|
protected localTopicToBackendTopicMap: Map<string, string>;
|
|
33
|
+
/** Maps backend FQDNs to local tag names. */
|
|
78
34
|
protected backendTopicToLocalMap: Map<string, string>;
|
|
79
|
-
|
|
80
|
-
protected backendFNameToLocalFNameMap: Map<string, string>;
|
|
35
|
+
/** Reference to the global event emitter for dispatching incoming messages. */
|
|
81
36
|
protected context: EventEmitterContextType | null;
|
|
37
|
+
/** Connection state tracker. */
|
|
82
38
|
protected isConnected_: boolean;
|
|
83
39
|
/**
|
|
84
40
|
* Constructor
|
|
85
41
|
*/
|
|
86
42
|
constructor();
|
|
87
43
|
/**
|
|
88
|
-
*
|
|
89
|
-
* should handle this as part of the initialization sequence. Because React can
|
|
90
|
-
* sometimes make (and destroy) multiple copies of the EventEmitterContext, it's important
|
|
91
|
-
* that the context be stored in the instance this way so that the HubBase can properly target
|
|
92
|
-
* right context.
|
|
44
|
+
* Links this Hub instance with the React application's Event Context.
|
|
93
45
|
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
46
|
+
* This connection allows the Hub to "push" messages into the React app by calling `context.dispatch()`.
|
|
47
|
+
* This is called automatically by `EventEmitterProvider` on initialization.
|
|
96
48
|
*
|
|
49
|
+
* @param context The React context instance.
|
|
97
50
|
*/
|
|
98
51
|
setContext(context: EventEmitterContextType | null): void;
|
|
99
52
|
/**
|
|
100
|
-
*
|
|
101
|
-
*
|
|
53
|
+
* Sends a raw command message to the backend.
|
|
54
|
+
*
|
|
55
|
+
* @param topic The resource identifier (FQDN).
|
|
56
|
+
* @param messageType The operation to perform (Read, Write, etc.).
|
|
57
|
+
* @param payload The data payload.
|
|
58
|
+
* @returns A Promise that resolves with the server's response.
|
|
102
59
|
*/
|
|
103
|
-
abstract invoke(
|
|
60
|
+
abstract invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
|
|
104
61
|
/**
|
|
105
|
-
*
|
|
106
|
-
*
|
|
62
|
+
* Request the current value of a resource.
|
|
63
|
+
*
|
|
64
|
+
* @param topic FQDN of the resource.
|
|
107
65
|
*/
|
|
108
|
-
|
|
66
|
+
read(topic: string, payload?: object): Promise<CommandMessage>;
|
|
109
67
|
/**
|
|
110
|
-
*
|
|
68
|
+
* Write a new value to a resource.
|
|
69
|
+
*
|
|
70
|
+
* @param topic FQDN of the resource.
|
|
71
|
+
* @param value The value to write.
|
|
111
72
|
*/
|
|
112
|
-
|
|
73
|
+
write(topic: string, value: any): Promise<CommandMessage>;
|
|
113
74
|
/**
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
* @param
|
|
120
|
-
* @param
|
|
75
|
+
* Subscribe to updates for a specific resource.
|
|
76
|
+
*
|
|
77
|
+
* Registers a mapping so that when the server sends updates for `topic` (FQDN),
|
|
78
|
+
* the Hub will translate it to `tagName` before dispatching to the UI.
|
|
79
|
+
*
|
|
80
|
+
* @param tagName The local alias for this resource (e.g., "position").
|
|
81
|
+
* @param topic The backend FQDN (e.g., "ADS.Main.fPos").
|
|
82
|
+
* @param payload Optional subscription parameters (rate, deadband).
|
|
121
83
|
*/
|
|
122
|
-
|
|
84
|
+
subscribe(tagName: string, topic: string, payload?: object): Promise<CommandMessage>;
|
|
123
85
|
/**
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
86
|
+
* Unsubscribe from updates.
|
|
87
|
+
*
|
|
88
|
+
* Uses the `tagName` to look up the FQDN and send the unsubscribe command.
|
|
89
|
+
* Also removes the local mapping.
|
|
90
|
+
*
|
|
91
|
+
* @param tagName The local alias to unsubscribe.
|
|
127
92
|
*/
|
|
128
|
-
|
|
93
|
+
unsubscribe(/* topic: string,*/ tagName: string, payload?: object): Promise<CommandMessage>;
|
|
129
94
|
/**
|
|
130
|
-
*
|
|
131
|
-
* @param localTopic string
|
|
132
|
-
* @param backendTopic string
|
|
95
|
+
* Send a generic request (custom command).
|
|
133
96
|
*/
|
|
134
|
-
|
|
97
|
+
request(topic: string, payload?: object): Promise<CommandMessage>;
|
|
135
98
|
/**
|
|
136
|
-
*
|
|
137
|
-
* @param localTopic string
|
|
99
|
+
* Update internal connection state.
|
|
138
100
|
*/
|
|
139
|
-
|
|
101
|
+
protected setIsConnected: (s: boolean) => void;
|
|
140
102
|
/**
|
|
141
|
-
*
|
|
142
|
-
* function name in the backend.
|
|
143
|
-
* @param localFName string
|
|
144
|
-
* @param backendFName string
|
|
103
|
+
* Check if currently connected to backend.
|
|
145
104
|
*/
|
|
146
|
-
|
|
105
|
+
isConnected: () => boolean;
|
|
147
106
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
107
|
+
* Dispatches an event to the React application.
|
|
108
|
+
*
|
|
109
|
+
* 1. Translates the `topic` (potentially an FQDN) to a local `tagName` if a mapping exists.
|
|
110
|
+
* 2. Calls `context.dispatch()` to notify local subscribers.
|
|
111
|
+
*
|
|
112
|
+
* This is the bridge between the backend transport and the frontend UI components.
|
|
113
|
+
*
|
|
114
|
+
* @param topic The topic from the message (usually FQDN).
|
|
115
|
+
* @param data The data payload.
|
|
150
116
|
*/
|
|
151
|
-
|
|
117
|
+
publish(topic: string, data: any | undefined): void;
|
|
152
118
|
/**
|
|
153
|
-
*
|
|
154
|
-
* registered, the local topic is returned.
|
|
155
|
-
* @param localTopic local topic name
|
|
156
|
-
* @returns string
|
|
119
|
+
* Registers a mapping between a local name and a backend FQDN.
|
|
157
120
|
*/
|
|
158
|
-
|
|
121
|
+
mapTopic(localTopic: string, backendTopic: string): void;
|
|
159
122
|
/**
|
|
160
|
-
*
|
|
161
|
-
* registered, the local FName is returned.
|
|
162
|
-
* @param localTopic local function name
|
|
163
|
-
* @returns string
|
|
123
|
+
* Removes a mapping.
|
|
164
124
|
*/
|
|
165
|
-
|
|
125
|
+
unmapTopic(localTopic: string): void;
|
|
166
126
|
/**
|
|
167
|
-
*
|
|
168
|
-
* registered, the backend topic is returned.
|
|
169
|
-
* @param backendTopic backend topic name
|
|
170
|
-
* @returns string
|
|
127
|
+
* Translates Local Name -> Backend FQDN.
|
|
171
128
|
*/
|
|
172
|
-
|
|
129
|
+
toBackendTopic(localTopic: string): string;
|
|
173
130
|
/**
|
|
174
|
-
*
|
|
175
|
-
* registered, the backend function name is returned.
|
|
176
|
-
* @param backendTopic backend function name
|
|
177
|
-
* @returns string
|
|
131
|
+
* Translates Backend FQDN -> Local Name.
|
|
178
132
|
*/
|
|
179
|
-
|
|
133
|
+
toLocalTopic(backendTopic: string): string;
|
|
180
134
|
}
|
|
181
135
|
export default HubBase;
|
|
182
136
|
//# sourceMappingURL=HubBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HubBase.d.ts","sourceRoot":"","sources":["../../src/hub/HubBase.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,
|
|
1
|
+
{"version":3,"file":"HubBase.d.ts","sourceRoot":"","sources":["../../src/hub/HubBase.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,8BAAsB,OAAO;IAEzB,6CAA6C;IAC7C,SAAS,CAAC,2BAA2B,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAEvF,6CAA6C;IAC7C,SAAS,CAAC,sBAAsB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAA6B;IAElF,+EAA+E;IAC/E,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAQ;IAEzD,gCAAgC;IAChC,SAAS,CAAC,YAAY,EAAE,OAAO,CAAS;IAGxC;;OAEG;;IAKH;;;;;;;OAOG;IACH,UAAU,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAQlD;;;;;;;OAOG;IACH,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAMnG;;;;OAIG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9D;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,cAAc,CAAC;IAIzD;;;;;;;;;OASG;IACH,SAAS,CAAC,OAAO,EAAG,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAKrF;;;;;;;OAOG;IACH,WAAW,CAAE,mBAAmB,CAAC,OAAO,EAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAM7F;;OAEG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAQjE;;OAEG;IACH,SAAS,CAAC,cAAc,GAAI,GAAG,OAAO,UAErC;IAED;;OAEG;IACH,WAAW,QAAO,OAAO,CAExB;IAMD;;;;;;;;;;OAUG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAcnD;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI;IAKxD;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI;IAWpC;;OAEG;IACH,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAK1C;;OAEG;IACH,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM;CAI7C;AAGD,eAAe,OAAO,CAAC"}
|
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,"
|
|
1
|
+
import{MessageType}from"./CommandMessage";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,"context",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"isConnected_",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"setIsConnected",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.isConnected_=e}}),Object.defineProperty(this,"isConnected",{enumerable:!0,configurable:!0,writable:!0,value:()=>this.isConnected_})}setContext(e){this.context=e}read(e,t){return this.invoke(e,MessageType.Read,t)}write(e,t){return this.invoke(e,MessageType.Write,{value:t})}subscribe(e,t,i){return this.mapTopic(e,t),this.invoke(t,MessageType.Subscribe,i)}unsubscribe(e,t){const i=this.toBackendTopic(e);return this.unmapTopic(e),this.invoke(i,MessageType.Unsubscribe,t)}request(e,t){return this.invoke(e,MessageType.Request,t)}publish(e,t){const i=this.toLocalTopic(e);this.context?.dispatch({topic:i,payload:t})}mapTopic(e,t){this.localTopicToBackendTopicMap.set(e,t),this.backendTopicToLocalMap.set(t,e)}unmapTopic(e){if(this.localTopicToBackendTopicMap.has(e)){const t=this.localTopicToBackendTopicMap.get(e);this.localTopicToBackendTopicMap.delete(e),null!=t&&this.backendTopicToLocalMap.has(t)&&this.backendTopicToLocalMap.delete(t)}}toBackendTopic(e){return this.localTopicToBackendTopicMap.get(e)??e}toLocalTopic(e){return this.backendTopicToLocalMap.get(e)??e}}export default HubBase;
|
|
@@ -1,22 +1,55 @@
|
|
|
1
1
|
import { HubBase } from './HubBase';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CommandMessage } from "./CommandMessage";
|
|
3
|
+
import { MessageType } from "./CommandMessage";
|
|
3
4
|
/**
|
|
4
|
-
* Hub for simulating functionality when no backend is present.
|
|
5
|
+
* Hub for simulating backend functionality when no actual backend is present.
|
|
6
|
+
*
|
|
7
|
+
* Useful for development, testing, and demos without a running autocore-server.
|
|
8
|
+
* The simulator echoes back requests as successful responses after a configurable delay.
|
|
9
|
+
*
|
|
10
|
+
* ## Usage Examples
|
|
11
|
+
*
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const { hub } = useContext(EventEmitterContext);
|
|
14
|
+
*
|
|
15
|
+
* // Read returns the topic as the "value"
|
|
16
|
+
* const result = await hub.read("ads.plc1.gio.bControlPowerOk");
|
|
17
|
+
* console.log(result.data); // { value: "ads.plc1.gio.bControlPowerOk" }
|
|
18
|
+
*
|
|
19
|
+
* // Write echoes back the written value
|
|
20
|
+
* await hub.write("ads.plc1.gio.nSetpoint", 100);
|
|
21
|
+
* ```
|
|
5
22
|
*/
|
|
6
23
|
export declare class HubSimulate extends HubBase {
|
|
24
|
+
private responseDelay;
|
|
7
25
|
/**
|
|
8
26
|
* Constructor
|
|
27
|
+
* @param responseDelay Simulated response delay in milliseconds (default: 20ms)
|
|
9
28
|
*/
|
|
10
|
-
constructor();
|
|
29
|
+
constructor(responseDelay?: number);
|
|
11
30
|
/**
|
|
12
|
-
*
|
|
31
|
+
* Simulate sending a message to a backend.
|
|
13
32
|
*
|
|
14
|
-
*
|
|
33
|
+
* For Read operations, returns the topic as the value.
|
|
34
|
+
* For Write operations, echoes back the payload.
|
|
35
|
+
* For all operations, returns a successful response after the configured delay.
|
|
36
|
+
*
|
|
37
|
+
* @param topic The FQDN of the resource
|
|
38
|
+
* @param messageType The action to perform
|
|
15
39
|
* @param payload Optional data payload
|
|
16
|
-
* @
|
|
17
|
-
|
|
40
|
+
* @returns Promise<CommandMessage> A simulated successful response
|
|
41
|
+
*/
|
|
42
|
+
invoke(topic: string, messageType: MessageType, payload?: object): Promise<CommandMessage>;
|
|
43
|
+
/**
|
|
44
|
+
* Simulate a broadcast from the "backend".
|
|
45
|
+
*
|
|
46
|
+
* This is useful for testing subscription handlers.
|
|
47
|
+
*
|
|
48
|
+
* @param topic The topic to broadcast on
|
|
49
|
+
* @param data The data to broadcast
|
|
50
|
+
* @param delay Optional delay before broadcasting (default: 0ms)
|
|
18
51
|
*/
|
|
19
|
-
|
|
52
|
+
simulateBroadcast(topic: string, data: any, delay?: number): void;
|
|
20
53
|
}
|
|
21
54
|
export default HubSimulate;
|
|
22
55
|
//# sourceMappingURL=HubSimulate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HubSimulate.d.ts","sourceRoot":"","sources":["../../src/hub/HubSimulate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HubSimulate.d.ts","sourceRoot":"","sources":["../../src/hub/HubSimulate.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,WAAY,SAAQ,OAAO;IAEpC,OAAO,CAAC,aAAa,CAAS;IAE9B;;;OAGG;gBACS,aAAa,GAAE,MAAW;IAMtC;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAgD1F;;;;;;;;OAQG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,GAAE,MAAU,GAAG,IAAI;CAKvE;AAED,eAAe,WAAW,CAAC"}
|
package/dist/hub/HubSimulate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{HubBase}from"./HubBase";export class HubSimulate extends HubBase{constructor(){super()}invoke(e,s,
|
|
1
|
+
import{HubBase}from"./HubBase";import{MessageType}from"./CommandMessage";export class HubSimulate extends HubBase{constructor(e=20){super(),Object.defineProperty(this,"responseDelay",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.responseDelay=e,this.setIsConnected(!0)}invoke(e,s,a){return new Promise(t=>{setTimeout(()=>{let r;switch(s){case MessageType.Read:r={value:e,simulated:!0};break;case MessageType.Write:r={written:!0,...a};break;case MessageType.Subscribe:r={subscribed:!0,topic:e};break;case MessageType.Unsubscribe:r={unsubscribed:!0,topic:e};break;default:r=a??{}}const i={transaction_id:0,timecode:Date.now(),topic:e,message_type:MessageType.Response,data:r,success:!0,error_message:""};t(i)},this.responseDelay)})}simulateBroadcast(e,s,a=0){setTimeout(()=>{this.publish(e,s)},a)}}export default HubSimulate;
|