@adcops/autocore-react 3.0.34 → 3.0.36
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/assets/BlocklyLogo.js +1 -9
- package/dist/assets/Distance.js +1 -5
- package/dist/assets/JogLong.js +1 -3
- package/dist/assets/JogMedium.js +1 -3
- package/dist/assets/JogShort.js +1 -3
- package/dist/assets/PythonLogo.js +1 -21
- package/dist/assets/Rotation3D.js +1 -3
- package/dist/assets/RotationCcw.js +1 -10
- package/dist/assets/RotationCcwA.js +1 -16
- package/dist/assets/RotationCcwB.js +1 -16
- package/dist/assets/RotationCcwC.js +1 -16
- package/dist/assets/RotationCw.js +1 -10
- package/dist/assets/RotationCwA.js +1 -16
- package/dist/assets/RotationCwB.js +1 -16
- package/dist/assets/RotationCwC.js +1 -16
- package/dist/assets/Run.js +1 -3
- package/dist/assets/Speed.js +1 -5
- package/dist/assets/SpeedFast.js +1 -3
- package/dist/assets/SpeedMedium.js +1 -3
- package/dist/assets/SpeedNone.js +1 -3
- package/dist/assets/SpeedSlow.js +1 -3
- package/dist/assets/Walk.js +1 -3
- package/dist/assets/index.js +1 -22
- package/dist/components/BlocklyEditor.css +71 -2
- package/dist/components/BlocklyEditor.js +1 -508
- package/dist/components/CodeEditor.js +1 -108
- package/dist/components/FileList.js +1 -218
- package/dist/components/FileSelect.js +1 -63
- package/dist/components/FitText.js +1 -13
- package/dist/components/Indicator.js +1 -113
- package/dist/components/IndicatorButton.js +1 -187
- package/dist/components/IndicatorRect.js +1 -93
- package/dist/components/JogPanel.js +1 -295
- package/dist/components/Lamp.js +1 -161
- package/dist/components/Osk.js +1 -125
- package/dist/components/OskDialog.js +1 -128
- package/dist/components/ProgressBarWithValue.js +1 -18
- package/dist/components/TextInput.js +1 -139
- package/dist/components/ToggleGroup.js +1 -204
- package/dist/components/ValueDisplay.js +1 -160
- package/dist/components/ValueIndicator.js +1 -38
- package/dist/components/ValueInput.js +1 -158
- package/dist/core/ActionMode.js +1 -18
- package/dist/core/EventEmitterContext.js +1 -252
- package/dist/core/IndicatorButtonState.js +1 -9
- package/dist/core/IndicatorColor.js +1 -36
- package/dist/core/MaskPatterns.js +1 -80
- package/dist/core/NumerableTypes.js +1 -10
- package/dist/core/PositionContext.js +1 -24
- package/dist/core/UniqueId.js +1 -32
- package/dist/core/ValueSimulator.js +1 -233
- package/dist/core/hoc.js +1 -44
- package/dist/hooks/adsHooks.js +1 -253
- package/dist/hooks/commandHooks.js +1 -252
- package/dist/hooks/index.js +1 -10
- package/dist/hooks/useScaledValue.js +1 -86
- package/dist/hub/CommandMessage.js +1 -9
- package/dist/hub/HubBase.js +1 -310
- package/dist/hub/HubSimulate.js +1 -46
- package/dist/hub/HubTauri.js +1 -130
- package/dist/hub/HubWebSocket.js +1 -240
- package/dist/hub/index.js +1 -57
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-Italic-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Italic-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Regular.woff2 +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-RegularItalic.woff2 +0 -0
- package/dist/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-VariableFont_wght.ttf +0 -0
- package/dist/themes/adc-dark/blue/theme.css +7097 -0
- package/dist/themes/adc-dark/blue/theme.css.map +1 -0
- package/package.json +8 -2
- package/src/components/BlocklyEditor.css +71 -2
- package/src/themes/adc-dark/_extensions.scss +166 -0
- package/src/themes/adc-dark/_variables.scss +913 -0
- package/src/themes/adc-dark/blue/_fonts.scss +24 -0
- package/src/themes/adc-dark/blue/adc_theme.scss +31 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-Italic-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleMono-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Italic-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-Regular.woff2 +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-RegularItalic.woff2 +0 -0
- package/src/themes/adc-dark/blue/fonts/AtkinsonHyperlegibleNext-VariableFont_wght.ttf +0 -0
- package/src/themes/adc-dark/blue/theme.scss +14 -0
- package/src/themes/theme-base/_colors.scss +18 -0
- package/src/themes/theme-base/_common.scss +75 -0
- package/src/themes/theme-base/_components.scss +111 -0
- package/src/themes/theme-base/_mixins.scss +243 -0
- package/src/themes/theme-base/components/button/_button.scss +644 -0
- package/src/themes/theme-base/components/button/_speeddial.scss +91 -0
- package/src/themes/theme-base/components/button/_splitbutton.scss +359 -0
- package/src/themes/theme-base/components/data/_carousel.scss +39 -0
- package/src/themes/theme-base/components/data/_datascroller.scss +47 -0
- package/src/themes/theme-base/components/data/_datatable.scss +389 -0
- package/src/themes/theme-base/components/data/_dataview.scss +47 -0
- package/src/themes/theme-base/components/data/_filter.scss +138 -0
- package/src/themes/theme-base/components/data/_orderlist.scss +86 -0
- package/src/themes/theme-base/components/data/_organizationchart.scss +50 -0
- package/src/themes/theme-base/components/data/_paginator.scss +91 -0
- package/src/themes/theme-base/components/data/_picklist.scss +74 -0
- package/src/themes/theme-base/components/data/_timeline.scss +38 -0
- package/src/themes/theme-base/components/data/_tree.scss +184 -0
- package/src/themes/theme-base/components/data/_treetable.scss +431 -0
- package/src/themes/theme-base/components/file/_fileupload.scss +41 -0
- package/src/themes/theme-base/components/input/_autocomplete.scss +95 -0
- package/src/themes/theme-base/components/input/_calendar.scss +251 -0
- package/src/themes/theme-base/components/input/_cascadeselect.scss +107 -0
- package/src/themes/theme-base/components/input/_checkbox.scss +181 -0
- package/src/themes/theme-base/components/input/_chips.scss +102 -0
- package/src/themes/theme-base/components/input/_colorpicker.scss +18 -0
- package/src/themes/theme-base/components/input/_dropdown.scss +252 -0
- package/src/themes/theme-base/components/input/_editor.scss +122 -0
- package/src/themes/theme-base/components/input/_iconfield.scss +10 -0
- package/src/themes/theme-base/components/input/_inputgroup.scss +74 -0
- package/src/themes/theme-base/components/input/_inputicon.scss +15 -0
- package/src/themes/theme-base/components/input/_inputnumber.scss +5 -0
- package/src/themes/theme-base/components/input/_inputotp.scss +10 -0
- package/src/themes/theme-base/components/input/_inputswitch.scss +100 -0
- package/src/themes/theme-base/components/input/_inputtext.scss +101 -0
- package/src/themes/theme-base/components/input/_listbox.scss +139 -0
- package/src/themes/theme-base/components/input/_mention.scss +31 -0
- package/src/themes/theme-base/components/input/_multiselect.scss +278 -0
- package/src/themes/theme-base/components/input/_password.scss +33 -0
- package/src/themes/theme-base/components/input/_radiobutton.scss +170 -0
- package/src/themes/theme-base/components/input/_rating.scss +81 -0
- package/src/themes/theme-base/components/input/_selectbutton.scss +50 -0
- package/src/themes/theme-base/components/input/_slider.scss +49 -0
- package/src/themes/theme-base/components/input/_togglebutton.scss +99 -0
- package/src/themes/theme-base/components/input/_treeselect.scss +151 -0
- package/src/themes/theme-base/components/input/_tristatecheckbox.scss +46 -0
- package/src/themes/theme-base/components/menu/_breadcrumb.scss +42 -0
- package/src/themes/theme-base/components/menu/_contextmenu.scss +39 -0
- package/src/themes/theme-base/components/menu/_dock.scss +109 -0
- package/src/themes/theme-base/components/menu/_megamenu.scss +141 -0
- package/src/themes/theme-base/components/menu/_menu.scss +33 -0
- package/src/themes/theme-base/components/menu/_menubar.scss +216 -0
- package/src/themes/theme-base/components/menu/_panelmenu.scss +153 -0
- package/src/themes/theme-base/components/menu/_slidemenu.scss +60 -0
- package/src/themes/theme-base/components/menu/_steps.scss +57 -0
- package/src/themes/theme-base/components/menu/_tabmenu.scss +50 -0
- package/src/themes/theme-base/components/menu/_tieredmenu.scss +43 -0
- package/src/themes/theme-base/components/messages/_inlinemessage.scss +69 -0
- package/src/themes/theme-base/components/messages/_message.scss +107 -0
- package/src/themes/theme-base/components/messages/_toast.scss +100 -0
- package/src/themes/theme-base/components/misc/_avatar.scss +34 -0
- package/src/themes/theme-base/components/misc/_badge.scss +77 -0
- package/src/themes/theme-base/components/misc/_blockui.scss +0 -0
- package/src/themes/theme-base/components/misc/_chip.scss +39 -0
- package/src/themes/theme-base/components/misc/_inplace.scss +17 -0
- package/src/themes/theme-base/components/misc/_metergroup.scss +81 -0
- package/src/themes/theme-base/components/misc/_progressbar.scss +17 -0
- package/src/themes/theme-base/components/misc/_scrolltop.scss +25 -0
- package/src/themes/theme-base/components/misc/_skeleton.scss +8 -0
- package/src/themes/theme-base/components/misc/_tag.scss +40 -0
- package/src/themes/theme-base/components/misc/_terminal.scss +12 -0
- package/src/themes/theme-base/components/multimedia/_galleria.scss +153 -0
- package/src/themes/theme-base/components/multimedia/_image.scss +54 -0
- package/src/themes/theme-base/components/overlay/_confirmpopup.scss +72 -0
- package/src/themes/theme-base/components/overlay/_dialog.scss +78 -0
- package/src/themes/theme-base/components/overlay/_overlaypanel.scss +64 -0
- package/src/themes/theme-base/components/overlay/_sidebar.scss +23 -0
- package/src/themes/theme-base/components/overlay/_tooltip.scss +33 -0
- package/src/themes/theme-base/components/panel/_accordion.scss +118 -0
- package/src/themes/theme-base/components/panel/_card.scss +30 -0
- package/src/themes/theme-base/components/panel/_divider.scss +31 -0
- package/src/themes/theme-base/components/panel/_fieldset.scss +47 -0
- package/src/themes/theme-base/components/panel/_panel.scss +47 -0
- package/src/themes/theme-base/components/panel/_scrollpanel.scss +10 -0
- package/src/themes/theme-base/components/panel/_splitter.scss +23 -0
- package/src/themes/theme-base/components/panel/_stepper.scss +136 -0
- package/src/themes/theme-base/components/panel/_tabview.scss +147 -0
- package/src/themes/theme-base/components/panel/_toolbar.scss +11 -0
- package/tools/build-themes.cjs +66 -0
- package/tools/copy-distribution-files.cjs +20 -16
package/dist/hub/HubWebSocket.js
CHANGED
|
@@ -1,240 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) 2024 Automated Design Corp.. All Rights Reserved.
|
|
3
|
-
* Created Date: 2024-04-17 09:13:07
|
|
4
|
-
* -----
|
|
5
|
-
* Last Modified: 2025-05-08 14:47:42
|
|
6
|
-
* -----
|
|
7
|
-
*
|
|
8
|
-
*/
|
|
9
|
-
/** @file
|
|
10
|
-
*
|
|
11
|
-
* ## broadcast messages
|
|
12
|
-
* The result field of CommandMessages used for broadcast must have
|
|
13
|
-
* success set to true, and must contain the field "topic." The topic field, along
|
|
14
|
-
* with the domain field of the CommandMessage will be combined for the topic used
|
|
15
|
-
* by the websocket client.
|
|
16
|
-
*
|
|
17
|
-
* broadcast topic = `${CommandMessage.domain}/${CommandMessage.result["topic"]}
|
|
18
|
-
*
|
|
19
|
-
* So, to subscribe to a broadcast topic for GM.fReal that is served by the ADS client, the
|
|
20
|
-
* topic will be: "ADS/GM.fReal"
|
|
21
|
-
*/
|
|
22
|
-
import { HubBase } from './HubBase';
|
|
23
|
-
/**
|
|
24
|
-
* Converts a Base64 encoded string into a Blob object.
|
|
25
|
-
*
|
|
26
|
-
* This function is useful for handling binary data encoded in Base64 format,
|
|
27
|
-
* especially when the data needs to be reconstructed into a binary format
|
|
28
|
-
* such as when downloading files that were transferred as Base64 strings over
|
|
29
|
-
* a network. The function slices the Base64 string, decodes it to binary,
|
|
30
|
-
* and constructs a Blob from the resulting byte arrays.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} b64Data The base64 encoded string you want to convert to a Blob.
|
|
33
|
-
* @param {string} [contentType='application/octet-stream'] The MIME type of the Blob.
|
|
34
|
-
* This parameter is optional and defaults to 'application/octet-stream'.
|
|
35
|
-
* @param {number} [sliceSize=512] The size of each chunk used to slice the Base64 string.
|
|
36
|
-
* Smaller slice sizes can improve the function's handling of large Base64 strings.
|
|
37
|
-
* This parameter is optional and defaults to 512.
|
|
38
|
-
*
|
|
39
|
-
* @returns {Blob} A Blob object representing the decoded binary data.
|
|
40
|
-
*/
|
|
41
|
-
function b64toBlob(b64Data, contentType = 'application/octet-stream', sliceSize = 512) {
|
|
42
|
-
const byteCharacters = atob(b64Data);
|
|
43
|
-
const byteArrays = [];
|
|
44
|
-
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
|
|
45
|
-
const slice = byteCharacters.slice(offset, offset + sliceSize);
|
|
46
|
-
const byteNumbers = new Array(slice.length);
|
|
47
|
-
for (let i = 0; i < slice.length; i++) {
|
|
48
|
-
byteNumbers[i] = slice.charCodeAt(i);
|
|
49
|
-
}
|
|
50
|
-
const byteArray = new Uint8Array(byteNumbers);
|
|
51
|
-
byteArrays.push(byteArray);
|
|
52
|
-
}
|
|
53
|
-
const blob = new Blob(byteArrays, { type: contentType });
|
|
54
|
-
return blob;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Creates a temporary hyperlink in the document and programmatically triggers a download of the Blob provided.
|
|
58
|
-
*
|
|
59
|
-
* This function is useful for triggering downloads of binary data such as files, which are represented
|
|
60
|
-
* by Blob objects in the browser. The function creates a URL from the Blob, sets it as the href of a
|
|
61
|
-
* dynamically created anchor tag (`<a>`), sets the suggested filename, and then simulates a click on
|
|
62
|
-
* this link to start the download. After the download is triggered, the link is removed and the URL
|
|
63
|
-
* is revoked to free up memory.
|
|
64
|
-
*
|
|
65
|
-
* @param {Blob} blob The Blob object containing the data to be downloaded.
|
|
66
|
-
* @param {string} filename The filename to be used for the downloaded file.
|
|
67
|
-
*/
|
|
68
|
-
function downloadBlob(blob, filename) {
|
|
69
|
-
// Create a URL for the blob object
|
|
70
|
-
const url = window.URL.createObjectURL(blob);
|
|
71
|
-
// Create a temporary anchor tag (`<a>`) element
|
|
72
|
-
const a = document.createElement('a');
|
|
73
|
-
a.href = url; // Set the href to the blob URL
|
|
74
|
-
a.download = filename; // Suggest a filename for the downloaded file
|
|
75
|
-
// Append the anchor tag to the body of the document
|
|
76
|
-
document.body.appendChild(a);
|
|
77
|
-
// Programmatically trigger a click on the anchor tag
|
|
78
|
-
a.click();
|
|
79
|
-
// Remove the anchor tag from the document
|
|
80
|
-
document.body.removeChild(a);
|
|
81
|
-
// Revoke the blob URL to free up resources
|
|
82
|
-
window.URL.revokeObjectURL(url);
|
|
83
|
-
}
|
|
84
|
-
export class HubWebSocket extends HubBase {
|
|
85
|
-
/**
|
|
86
|
-
* Constructor. Creates and attempts to make the Websocket connection.
|
|
87
|
-
*/
|
|
88
|
-
constructor() {
|
|
89
|
-
super();
|
|
90
|
-
Object.defineProperty(this, "socket", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
configurable: true,
|
|
93
|
-
writable: true,
|
|
94
|
-
value: void 0
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(this, "requestId", {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
configurable: true,
|
|
99
|
-
writable: true,
|
|
100
|
-
value: 0
|
|
101
|
-
});
|
|
102
|
-
Object.defineProperty(this, "pendingRequests", {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
configurable: true,
|
|
105
|
-
writable: true,
|
|
106
|
-
value: new Map()
|
|
107
|
-
});
|
|
108
|
-
/**
|
|
109
|
-
* Invoke a command in the remote webserver.
|
|
110
|
-
* @param domain The domain of the Servelet supplying the functionality.
|
|
111
|
-
* @param fname The name of the command to execute.
|
|
112
|
-
* @param payload The arguments of the command.
|
|
113
|
-
* @returns Promise<CommandMessageResult>
|
|
114
|
-
*/
|
|
115
|
-
Object.defineProperty(this, "invoke", {
|
|
116
|
-
enumerable: true,
|
|
117
|
-
configurable: true,
|
|
118
|
-
writable: true,
|
|
119
|
-
value: (domain, fname, payload) => {
|
|
120
|
-
return new Promise((resolve, reject) => {
|
|
121
|
-
const id = ++this.requestId; // Increment and use the request ID
|
|
122
|
-
this.pendingRequests.set(id, { resolve, reject });
|
|
123
|
-
let cm = {
|
|
124
|
-
request_id: id,
|
|
125
|
-
domain: domain,
|
|
126
|
-
fname: fname,
|
|
127
|
-
args: payload,
|
|
128
|
-
result: undefined
|
|
129
|
-
};
|
|
130
|
-
this.socket.send(JSON.stringify(cm));
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
Object.defineProperty(this, "handleUnsolicitedMessage", {
|
|
135
|
-
enumerable: true,
|
|
136
|
-
configurable: true,
|
|
137
|
-
writable: true,
|
|
138
|
-
value: (msg) => {
|
|
139
|
-
// Handle messages that do not correspond to a pending request
|
|
140
|
-
if (msg.fname === "BROADCAST"
|
|
141
|
-
&& msg.domain.length >= 1
|
|
142
|
-
&& msg.result !== undefined && msg.result !== null
|
|
143
|
-
&& msg.result.data !== undefined && msg.result.data !== null) {
|
|
144
|
-
let topic = `${msg.domain}/${msg.result.data["topic"]}`;
|
|
145
|
-
// console.log(`HUB PUBLISHING: ${topic} : ${JSON.stringify(msg.result.data)}`);
|
|
146
|
-
this.publish(topic, msg.result.data);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
console.error("INVALID BROADCAST RECEIVED!");
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
Object.defineProperty(this, "disconnect", {
|
|
154
|
-
enumerable: true,
|
|
155
|
-
configurable: true,
|
|
156
|
-
writable: true,
|
|
157
|
-
value: () => {
|
|
158
|
-
this.socket.close();
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
Object.defineProperty(this, "emit", {
|
|
162
|
-
enumerable: true,
|
|
163
|
-
configurable: true,
|
|
164
|
-
writable: true,
|
|
165
|
-
value: (eventName, payload) => {
|
|
166
|
-
this.socket.send(JSON.stringify({ eventName, payload }));
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
const host = window.location.hostname; // Get the hostname from the address bar
|
|
170
|
-
// Default to using autocore-server.
|
|
171
|
-
let port = undefined; // window.location.port; // Get the port from the address bar, if any
|
|
172
|
-
const proto = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; // Determine the protocol
|
|
173
|
-
const wsUrl = `${proto}${host}${port ? ':' + port : ''}/ws/`; // Construct WebSocket URL
|
|
174
|
-
this.socket = new WebSocket(wsUrl);
|
|
175
|
-
let self = this;
|
|
176
|
-
//
|
|
177
|
-
// Websocket connection established.
|
|
178
|
-
//
|
|
179
|
-
this.socket.onopen = function () {
|
|
180
|
-
console.log("WebSocket connection established.");
|
|
181
|
-
self.publish("HUB/connected", true);
|
|
182
|
-
self.setIsConnected(true);
|
|
183
|
-
};
|
|
184
|
-
// Message recevied via the websocket connection.
|
|
185
|
-
//
|
|
186
|
-
this.socket.onmessage = (event) => {
|
|
187
|
-
const data = JSON.parse(event.data);
|
|
188
|
-
// console.log(`MSG: ${JSON.stringify(data)}`);
|
|
189
|
-
if (data.request_id && this.pendingRequests.has(data.request_id)) {
|
|
190
|
-
const { resolve, reject } = this.pendingRequests.get(data.request_id);
|
|
191
|
-
if (data.fname === "FILE_DOWNLOAD"
|
|
192
|
-
&& data.args["file_name"] !== undefined && data.args["file_name"] !== null
|
|
193
|
-
&& data.args["file_name"].length > 0) {
|
|
194
|
-
// The file name was supplied in the original request
|
|
195
|
-
let tokens = data.args["file_name"].split("/");
|
|
196
|
-
const filename = tokens[tokens.length - 1];
|
|
197
|
-
if (data.result && data.result.success) {
|
|
198
|
-
const blob = b64toBlob(data.result.data);
|
|
199
|
-
downloadBlob(blob, filename);
|
|
200
|
-
// Don't send the whole file through; that's crazy.
|
|
201
|
-
data.result.data = filename;
|
|
202
|
-
// Signal the function that initiated the download that all is well.
|
|
203
|
-
resolve(data.result);
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
// Signal the function that initiated the download that it failed.
|
|
207
|
-
reject(new Error(data.result?.error_message));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
if (!data.result?.success) {
|
|
212
|
-
// Return the result to the function that initiated the request.
|
|
213
|
-
reject(new Error(data.result?.error_message));
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
// Send the error to the function that intiated the request.
|
|
217
|
-
resolve(data.result);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
this.pendingRequests.delete(data.request_id);
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
this.handleUnsolicitedMessage(data);
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
//
|
|
227
|
-
// Error occurred in the Websocket connection.
|
|
228
|
-
//
|
|
229
|
-
this.socket.onerror = (error) => {
|
|
230
|
-
console.error('WebSocket error:', error);
|
|
231
|
-
};
|
|
232
|
-
//
|
|
233
|
-
// The Websocket connection has closed.
|
|
234
|
-
//
|
|
235
|
-
this.socket.onclose = () => {
|
|
236
|
-
self.setIsConnected(false);
|
|
237
|
-
console.log('WebSocket connection closed.');
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
}
|
|
1
|
+
import{HubBase}from"./HubBase";function b64toBlob(e,t="application/octet-stream",s=512){const n=atob(e),o=[];for(let e=0;e<n.length;e+=s){const t=n.slice(e,e+s),r=new Array(t.length);for(let e=0;e<t.length;e++)r[e]=t.charCodeAt(e);const i=new Uint8Array(r);o.push(i)}return new Blob(o,{type:t})}function downloadBlob(e,t){const s=window.URL.createObjectURL(e),n=document.createElement("a");n.href=s,n.download=t,document.body.appendChild(n),n.click(),document.body.removeChild(n),window.URL.revokeObjectURL(s)}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(((n,o)=>{const r=++this.requestId;this.pendingRequests.set(r,{resolve:n,reject:o});let i={request_id:r,domain:e,fname:t,args:s,result:void 0};this.socket.send(JSON.stringify(i))}))}),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;let t;const s=`${"https:"===window.location.protocol?"wss://":"ws://"}${e}${t?":"+t:""}/ws/`;this.socket=new WebSocket(s);let n=this;this.socket.onopen=function(){n.publish("HUB/connected",!0),n.setIsConnected(!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);if("FILE_DOWNLOAD"===t.fname&&void 0!==t.args.file_name&&null!==t.args.file_name&&t.args.file_name.length>0){let n=t.args.file_name.split("/");const o=n[n.length-1];if(t.result&&t.result.success){downloadBlob(b64toBlob(t.result.data),o),t.result.data=o,e(t.result)}else s(new Error(t.result?.error_message))}else 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=()=>{n.setIsConnected(!1)}}}
|
package/dist/hub/index.js
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* Copyright (C) 2024 Automated Design Corp. All Rights Reserved.
|
|
3
|
-
* Created Date: 2024-01-16 21:07:29
|
|
4
|
-
* -----
|
|
5
|
-
* Last Modified: 2024-05-31 07:51:19
|
|
6
|
-
* Modified By: ADC
|
|
7
|
-
* -----
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
import { HubTauri } from './HubTauri';
|
|
11
|
-
import { HubWebSocket } from "./HubWebSocket";
|
|
12
|
-
import { HubSimulate } from "./HubSimulate";
|
|
13
|
-
let hubInstance = null;
|
|
14
|
-
/**
|
|
15
|
-
* Creates a connection to the backend.
|
|
16
|
-
* @returns Hub
|
|
17
|
-
*/
|
|
18
|
-
export function createHub() {
|
|
19
|
-
if (!hubInstance) {
|
|
20
|
-
if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
|
|
21
|
-
console.log("HUB: Starting link to Tauri backend.");
|
|
22
|
-
hubInstance = new HubTauri();
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
console.log("HUB: Starting websocket connection.");
|
|
26
|
-
hubInstance = new HubWebSocket();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
return hubInstance;
|
|
30
|
-
// if (window.__TAURI__ !== undefined && window.__TAURI__ !== null) {
|
|
31
|
-
// // Standalone Tauri application
|
|
32
|
-
// console.log("HUB: Starting link to Tauri backend.");
|
|
33
|
-
// return new HubTauri();
|
|
34
|
-
// }
|
|
35
|
-
// // else if (
|
|
36
|
-
// // window.location.port !== undefined
|
|
37
|
-
// // && window.location.port.length > 0
|
|
38
|
-
// // && window.location.port !== '80'
|
|
39
|
-
// // && window.location.port !== '8080'
|
|
40
|
-
// // && window.location.port !== '443'
|
|
41
|
-
// // ) {
|
|
42
|
-
// // // We're loaded in some development environment
|
|
43
|
-
// // console.log("HUB: Starting HUB SIMULATOR.");
|
|
44
|
-
// // return new HubSimulate();
|
|
45
|
-
// // }
|
|
46
|
-
// else {
|
|
47
|
-
// // A web-app that must communicate with a backend in another process.
|
|
48
|
-
// console.log("HUB: Starting websocket connection.");
|
|
49
|
-
// return new HubWebSocket();
|
|
50
|
-
// }
|
|
51
|
-
}
|
|
52
|
-
// Export HubBase for convenience to save importing throughout the
|
|
53
|
-
// application.
|
|
54
|
-
export { HubBase as Hub } from './HubBase';
|
|
55
|
-
export { HubTauri };
|
|
56
|
-
export { HubWebSocket };
|
|
57
|
-
export { HubSimulate };
|
|
1
|
+
import{HubTauri}from"./HubTauri";import{HubWebSocket}from"./HubWebSocket";import{HubSimulate}from"./HubSimulate";let hubInstance=null;export function createHub(){return hubInstance||(hubInstance=void 0!==window.__TAURI__&&null!==window.__TAURI__?new HubTauri:new HubWebSocket),hubInstance}export{HubBase as Hub}from"./HubBase";export{HubTauri};export{HubWebSocket};export{HubSimulate};
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|