@luxonis/visualizer-protobuf 1.3.1 → 1.4.0
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/PanelContextMenu-DPJvSBDO.js +7315 -0
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/BaseConnection.d.ts +8 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/BaseConnection.d.ts.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/BaseConnection.js.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/webrtc/Connection.d.ts +5 -4
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/webrtc/Connection.d.ts.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/webrtc/Connection.js +14 -9
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/webrtc/Connection.js.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Adapter.d.ts +2 -2
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Adapter.d.ts.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Adapter.js +12 -11
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Adapter.js.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Connection.d.ts +5 -4
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Connection.d.ts.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Connection.js +5 -2
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/Connection.js.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/worker.d.ts +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/worker.d.ts.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/worker.js +4 -3
- package/dist/apps/depthai-visualizer/src/frontend/src/connection/ws/worker.js.map +1 -1
- package/dist/apps/depthai-visualizer/src/frontend/src/utils/encoding.d.ts +2 -0
- package/dist/apps/depthai-visualizer/src/frontend/src/utils/encoding.d.ts.map +1 -0
- package/dist/apps/depthai-visualizer/src/frontend/src/utils/encoding.js +11 -0
- package/dist/apps/depthai-visualizer/src/frontend/src/utils/encoding.js.map +1 -0
- package/dist/index-BPAaP7MM.js +26690 -0
- package/dist/index-BTMHJklc.js +40 -0
- package/dist/index-Cy8naJ0D.js +70679 -0
- package/dist/index-DtpxBg2w.js +6711 -0
- package/dist/index.js +1 -1
- package/dist/worker-uxpVEQk0.js +1013 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1013 @@
|
|
|
1
|
+
import { Waterfall } from 'hydrated-ws';
|
|
2
|
+
import { E as EventEmitter } from './index-E-b7zaCM.js';
|
|
3
|
+
import { a as getDefaultExportFromCjs } from './_commonjsHelpers-Dr0z5XX9.js';
|
|
4
|
+
import require$$0 from 'ms';
|
|
5
|
+
|
|
6
|
+
var BinaryOpcode;
|
|
7
|
+
(function (BinaryOpcode) {
|
|
8
|
+
BinaryOpcode[BinaryOpcode["MESSAGE_DATA"] = 1] = "MESSAGE_DATA";
|
|
9
|
+
BinaryOpcode[BinaryOpcode["TIME"] = 2] = "TIME";
|
|
10
|
+
BinaryOpcode[BinaryOpcode["SERVICE_CALL_RESPONSE"] = 3] = "SERVICE_CALL_RESPONSE";
|
|
11
|
+
BinaryOpcode[BinaryOpcode["FETCH_ASSET_RESPONSE"] = 4] = "FETCH_ASSET_RESPONSE";
|
|
12
|
+
})(BinaryOpcode || (BinaryOpcode = {}));
|
|
13
|
+
var ClientBinaryOpcode;
|
|
14
|
+
(function (ClientBinaryOpcode) {
|
|
15
|
+
ClientBinaryOpcode[ClientBinaryOpcode["MESSAGE_DATA"] = 1] = "MESSAGE_DATA";
|
|
16
|
+
ClientBinaryOpcode[ClientBinaryOpcode["SERVICE_CALL_REQUEST"] = 2] = "SERVICE_CALL_REQUEST";
|
|
17
|
+
})(ClientBinaryOpcode || (ClientBinaryOpcode = {}));
|
|
18
|
+
var StatusLevel;
|
|
19
|
+
(function (StatusLevel) {
|
|
20
|
+
StatusLevel[StatusLevel["INFO"] = 0] = "INFO";
|
|
21
|
+
StatusLevel[StatusLevel["WARNING"] = 1] = "WARNING";
|
|
22
|
+
StatusLevel[StatusLevel["ERROR"] = 2] = "ERROR";
|
|
23
|
+
})(StatusLevel || (StatusLevel = {}));
|
|
24
|
+
var ServerCapability;
|
|
25
|
+
(function (ServerCapability) {
|
|
26
|
+
ServerCapability["clientPublish"] = "clientPublish";
|
|
27
|
+
ServerCapability["time"] = "time";
|
|
28
|
+
ServerCapability["parameters"] = "parameters";
|
|
29
|
+
ServerCapability["parametersSubscribe"] = "parametersSubscribe";
|
|
30
|
+
ServerCapability["services"] = "services";
|
|
31
|
+
ServerCapability["connectionGraph"] = "connectionGraph";
|
|
32
|
+
ServerCapability["assets"] = "assets";
|
|
33
|
+
})(ServerCapability || (ServerCapability = {}));
|
|
34
|
+
var FetchAssetStatus;
|
|
35
|
+
(function (FetchAssetStatus) {
|
|
36
|
+
FetchAssetStatus[FetchAssetStatus["SUCCESS"] = 0] = "SUCCESS";
|
|
37
|
+
FetchAssetStatus[FetchAssetStatus["ERROR"] = 1] = "ERROR";
|
|
38
|
+
})(FetchAssetStatus || (FetchAssetStatus = {}));
|
|
39
|
+
|
|
40
|
+
const textDecoder = new TextDecoder();
|
|
41
|
+
function parseServerMessage(buffer) {
|
|
42
|
+
const view = new DataView(buffer);
|
|
43
|
+
let offset = 0;
|
|
44
|
+
const op = view.getUint8(offset);
|
|
45
|
+
offset += 1;
|
|
46
|
+
switch (op) {
|
|
47
|
+
case BinaryOpcode.MESSAGE_DATA: {
|
|
48
|
+
const subscriptionId = view.getUint32(offset, true);
|
|
49
|
+
offset += 4;
|
|
50
|
+
const timestamp = view.getBigUint64(offset, true);
|
|
51
|
+
offset += 8;
|
|
52
|
+
const data = new DataView(buffer, offset);
|
|
53
|
+
return { op, subscriptionId, timestamp, data };
|
|
54
|
+
}
|
|
55
|
+
case BinaryOpcode.TIME: {
|
|
56
|
+
const timestamp = view.getBigUint64(offset, true);
|
|
57
|
+
return { op, timestamp };
|
|
58
|
+
}
|
|
59
|
+
case BinaryOpcode.SERVICE_CALL_RESPONSE: {
|
|
60
|
+
const serviceId = view.getUint32(offset, true);
|
|
61
|
+
offset += 4;
|
|
62
|
+
const callId = view.getUint32(offset, true);
|
|
63
|
+
offset += 4;
|
|
64
|
+
const encodingLength = view.getUint32(offset, true);
|
|
65
|
+
offset += 4;
|
|
66
|
+
const encodingBytes = new DataView(buffer, offset, encodingLength);
|
|
67
|
+
const encoding = textDecoder.decode(encodingBytes);
|
|
68
|
+
offset += encodingLength;
|
|
69
|
+
const data = new DataView(buffer, offset, buffer.byteLength - offset);
|
|
70
|
+
return { op, serviceId, callId, encoding, data };
|
|
71
|
+
}
|
|
72
|
+
case BinaryOpcode.FETCH_ASSET_RESPONSE: {
|
|
73
|
+
const requestId = view.getUint32(offset, true);
|
|
74
|
+
offset += 4;
|
|
75
|
+
const status = view.getUint8(offset);
|
|
76
|
+
offset += 1;
|
|
77
|
+
const errorMsgLength = view.getUint32(offset, true);
|
|
78
|
+
offset += 4;
|
|
79
|
+
const error = textDecoder.decode(new DataView(buffer, offset, errorMsgLength));
|
|
80
|
+
offset += errorMsgLength;
|
|
81
|
+
switch (status) {
|
|
82
|
+
case FetchAssetStatus.SUCCESS: {
|
|
83
|
+
const data = new DataView(buffer, offset, buffer.byteLength - offset);
|
|
84
|
+
return { op, requestId, status, data };
|
|
85
|
+
}
|
|
86
|
+
case FetchAssetStatus.ERROR:
|
|
87
|
+
return { op, requestId, status, error };
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unrecognized fetch asset status: ${status}`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`Unrecognized server opcode in binary message: ${op.toString(16)}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const textEncoder = new TextEncoder();
|
|
97
|
+
class FoxgloveClient {
|
|
98
|
+
static SUPPORTED_SUBPROTOCOL = "foxglove.websocket.v1";
|
|
99
|
+
#emitter = new EventEmitter();
|
|
100
|
+
#ws;
|
|
101
|
+
#nextSubscriptionId = 0;
|
|
102
|
+
#nextAdvertisementId = 0;
|
|
103
|
+
constructor({ ws }) {
|
|
104
|
+
this.#ws = ws;
|
|
105
|
+
this.#reconnect();
|
|
106
|
+
}
|
|
107
|
+
on(name, listener) {
|
|
108
|
+
this.#emitter.on(name, listener);
|
|
109
|
+
}
|
|
110
|
+
off(name, listener) {
|
|
111
|
+
this.#emitter.off(name, listener);
|
|
112
|
+
}
|
|
113
|
+
#reconnect() {
|
|
114
|
+
this.#ws.binaryType = "arraybuffer";
|
|
115
|
+
this.#ws.onerror = (event) => {
|
|
116
|
+
this.#emitter.emit("error", event.error);
|
|
117
|
+
};
|
|
118
|
+
this.#ws.onopen = (_event) => {
|
|
119
|
+
if (this.#ws.protocol !== FoxgloveClient.SUPPORTED_SUBPROTOCOL) {
|
|
120
|
+
throw new Error(`Expected subprotocol ${FoxgloveClient.SUPPORTED_SUBPROTOCOL}, got '${this.#ws.protocol}'`);
|
|
121
|
+
}
|
|
122
|
+
this.#emitter.emit("open");
|
|
123
|
+
};
|
|
124
|
+
this.#ws.onmessage = (event) => {
|
|
125
|
+
let message;
|
|
126
|
+
try {
|
|
127
|
+
if (event.data instanceof ArrayBuffer) {
|
|
128
|
+
message = parseServerMessage(event.data);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
message = JSON.parse(event.data);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
catch (error) {
|
|
135
|
+
this.#emitter.emit("error", error);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
switch (message.op) {
|
|
139
|
+
case "serverInfo":
|
|
140
|
+
this.#emitter.emit("serverInfo", message);
|
|
141
|
+
return;
|
|
142
|
+
case "status":
|
|
143
|
+
this.#emitter.emit("status", message);
|
|
144
|
+
return;
|
|
145
|
+
case "advertise":
|
|
146
|
+
this.#emitter.emit("advertise", message.channels);
|
|
147
|
+
return;
|
|
148
|
+
case "unadvertise":
|
|
149
|
+
this.#emitter.emit("unadvertise", message.channelIds);
|
|
150
|
+
return;
|
|
151
|
+
case "parameterValues":
|
|
152
|
+
this.#emitter.emit("parameterValues", message);
|
|
153
|
+
return;
|
|
154
|
+
case "advertiseServices":
|
|
155
|
+
this.#emitter.emit("advertiseServices", message.services);
|
|
156
|
+
return;
|
|
157
|
+
case "unadvertiseServices":
|
|
158
|
+
this.#emitter.emit("unadvertiseServices", message.serviceIds);
|
|
159
|
+
return;
|
|
160
|
+
case "connectionGraphUpdate":
|
|
161
|
+
this.#emitter.emit("connectionGraphUpdate", message);
|
|
162
|
+
return;
|
|
163
|
+
case BinaryOpcode.MESSAGE_DATA:
|
|
164
|
+
this.#emitter.emit("message", message);
|
|
165
|
+
return;
|
|
166
|
+
case BinaryOpcode.TIME:
|
|
167
|
+
this.#emitter.emit("time", message);
|
|
168
|
+
return;
|
|
169
|
+
case BinaryOpcode.SERVICE_CALL_RESPONSE:
|
|
170
|
+
this.#emitter.emit("serviceCallResponse", message);
|
|
171
|
+
return;
|
|
172
|
+
case BinaryOpcode.FETCH_ASSET_RESPONSE:
|
|
173
|
+
this.#emitter.emit("fetchAssetResponse", message);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
this.#emitter.emit("error", new Error(`Unrecognized server opcode: ${message.op}`));
|
|
177
|
+
};
|
|
178
|
+
this.#ws.onclose = (event) => {
|
|
179
|
+
this.#emitter.emit("close", event);
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
close() {
|
|
183
|
+
this.#ws.close();
|
|
184
|
+
}
|
|
185
|
+
subscribe(channelId) {
|
|
186
|
+
const id = this.#nextSubscriptionId++;
|
|
187
|
+
const subscriptions = [{ id, channelId }];
|
|
188
|
+
this.#send({ op: "subscribe", subscriptions });
|
|
189
|
+
return id;
|
|
190
|
+
}
|
|
191
|
+
unsubscribe(subscriptionId) {
|
|
192
|
+
this.#send({ op: "unsubscribe", subscriptionIds: [subscriptionId] });
|
|
193
|
+
}
|
|
194
|
+
advertise(clientChannel) {
|
|
195
|
+
const id = ++this.#nextAdvertisementId;
|
|
196
|
+
const channels = [{ id, ...clientChannel }];
|
|
197
|
+
this.#send({ op: "advertise", channels });
|
|
198
|
+
return id;
|
|
199
|
+
}
|
|
200
|
+
unadvertise(channelId) {
|
|
201
|
+
this.#send({ op: "unadvertise", channelIds: [channelId] });
|
|
202
|
+
}
|
|
203
|
+
getParameters(parameterNames, id) {
|
|
204
|
+
this.#send({ op: "getParameters", parameterNames, id });
|
|
205
|
+
}
|
|
206
|
+
setParameters(parameters, id) {
|
|
207
|
+
this.#send({ op: "setParameters", parameters, id });
|
|
208
|
+
}
|
|
209
|
+
subscribeParameterUpdates(parameterNames) {
|
|
210
|
+
this.#send({ op: "subscribeParameterUpdates", parameterNames });
|
|
211
|
+
}
|
|
212
|
+
unsubscribeParameterUpdates(parameterNames) {
|
|
213
|
+
this.#send({ op: "unsubscribeParameterUpdates", parameterNames });
|
|
214
|
+
}
|
|
215
|
+
sendMessage(channelId, data) {
|
|
216
|
+
const payload = new Uint8Array(5 + data.byteLength);
|
|
217
|
+
const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
218
|
+
view.setUint8(0, ClientBinaryOpcode.MESSAGE_DATA);
|
|
219
|
+
view.setUint32(1, channelId, true);
|
|
220
|
+
payload.set(data, 5);
|
|
221
|
+
this.#ws.send(payload);
|
|
222
|
+
}
|
|
223
|
+
sendServiceCallRequest(request) {
|
|
224
|
+
const encoding = textEncoder.encode(request.encoding);
|
|
225
|
+
const payload = new Uint8Array(1 + 4 + 4 + 4 + encoding.length + request.data.byteLength);
|
|
226
|
+
const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
|
|
227
|
+
let offset = 0;
|
|
228
|
+
view.setUint8(offset, ClientBinaryOpcode.SERVICE_CALL_REQUEST);
|
|
229
|
+
offset += 1;
|
|
230
|
+
view.setUint32(offset, request.serviceId, true);
|
|
231
|
+
offset += 4;
|
|
232
|
+
view.setUint32(offset, request.callId, true);
|
|
233
|
+
offset += 4;
|
|
234
|
+
view.setUint32(offset, request.encoding.length, true);
|
|
235
|
+
offset += 4;
|
|
236
|
+
payload.set(encoding, offset);
|
|
237
|
+
offset += encoding.length;
|
|
238
|
+
const data = new Uint8Array(request.data.buffer, request.data.byteOffset, request.data.byteLength);
|
|
239
|
+
payload.set(data, offset);
|
|
240
|
+
this.#ws.send(payload);
|
|
241
|
+
}
|
|
242
|
+
subscribeConnectionGraph() {
|
|
243
|
+
this.#send({ op: "subscribeConnectionGraph" });
|
|
244
|
+
}
|
|
245
|
+
unsubscribeConnectionGraph() {
|
|
246
|
+
this.#send({ op: "unsubscribeConnectionGraph" });
|
|
247
|
+
}
|
|
248
|
+
fetchAsset(uri, requestId) {
|
|
249
|
+
this.#send({ op: "fetchAsset", uri, requestId });
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* @deprecated Use `sendServiceCallRequest` instead
|
|
253
|
+
*/
|
|
254
|
+
sendCallServiceRequest(request) {
|
|
255
|
+
this.sendServiceCallRequest(request);
|
|
256
|
+
}
|
|
257
|
+
#send(message) {
|
|
258
|
+
this.#ws.send(JSON.stringify(message));
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
var browser = {exports: {}};
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* This is the common logic for both the Node.js and web browser
|
|
266
|
+
* implementations of `debug()`.
|
|
267
|
+
*/
|
|
268
|
+
|
|
269
|
+
function setup(env) {
|
|
270
|
+
createDebug.debug = createDebug;
|
|
271
|
+
createDebug.default = createDebug;
|
|
272
|
+
createDebug.coerce = coerce;
|
|
273
|
+
createDebug.disable = disable;
|
|
274
|
+
createDebug.enable = enable;
|
|
275
|
+
createDebug.enabled = enabled;
|
|
276
|
+
createDebug.humanize = require$$0;
|
|
277
|
+
createDebug.destroy = destroy;
|
|
278
|
+
|
|
279
|
+
Object.keys(env).forEach(key => {
|
|
280
|
+
createDebug[key] = env[key];
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* The currently active debug mode names, and names to skip.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
createDebug.names = [];
|
|
288
|
+
createDebug.skips = [];
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
292
|
+
*
|
|
293
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
294
|
+
*/
|
|
295
|
+
createDebug.formatters = {};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Selects a color for a debug namespace
|
|
299
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
300
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
301
|
+
* @api private
|
|
302
|
+
*/
|
|
303
|
+
function selectColor(namespace) {
|
|
304
|
+
let hash = 0;
|
|
305
|
+
|
|
306
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
307
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
308
|
+
hash |= 0; // Convert to 32bit integer
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
312
|
+
}
|
|
313
|
+
createDebug.selectColor = selectColor;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Create a debugger with the given `namespace`.
|
|
317
|
+
*
|
|
318
|
+
* @param {String} namespace
|
|
319
|
+
* @return {Function}
|
|
320
|
+
* @api public
|
|
321
|
+
*/
|
|
322
|
+
function createDebug(namespace) {
|
|
323
|
+
let prevTime;
|
|
324
|
+
let enableOverride = null;
|
|
325
|
+
let namespacesCache;
|
|
326
|
+
let enabledCache;
|
|
327
|
+
|
|
328
|
+
function debug(...args) {
|
|
329
|
+
// Disabled?
|
|
330
|
+
if (!debug.enabled) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const self = debug;
|
|
335
|
+
|
|
336
|
+
// Set `diff` timestamp
|
|
337
|
+
const curr = Number(new Date());
|
|
338
|
+
const ms = curr - (prevTime || curr);
|
|
339
|
+
self.diff = ms;
|
|
340
|
+
self.prev = prevTime;
|
|
341
|
+
self.curr = curr;
|
|
342
|
+
prevTime = curr;
|
|
343
|
+
|
|
344
|
+
args[0] = createDebug.coerce(args[0]);
|
|
345
|
+
|
|
346
|
+
if (typeof args[0] !== 'string') {
|
|
347
|
+
// Anything else let's inspect with %O
|
|
348
|
+
args.unshift('%O');
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// Apply any `formatters` transformations
|
|
352
|
+
let index = 0;
|
|
353
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
354
|
+
// If we encounter an escaped % then don't increase the array index
|
|
355
|
+
if (match === '%%') {
|
|
356
|
+
return '%';
|
|
357
|
+
}
|
|
358
|
+
index++;
|
|
359
|
+
const formatter = createDebug.formatters[format];
|
|
360
|
+
if (typeof formatter === 'function') {
|
|
361
|
+
const val = args[index];
|
|
362
|
+
match = formatter.call(self, val);
|
|
363
|
+
|
|
364
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
365
|
+
args.splice(index, 1);
|
|
366
|
+
index--;
|
|
367
|
+
}
|
|
368
|
+
return match;
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Apply env-specific formatting (colors, etc.)
|
|
372
|
+
createDebug.formatArgs.call(self, args);
|
|
373
|
+
|
|
374
|
+
const logFn = self.log || createDebug.log;
|
|
375
|
+
logFn.apply(self, args);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
debug.namespace = namespace;
|
|
379
|
+
debug.useColors = createDebug.useColors();
|
|
380
|
+
debug.color = createDebug.selectColor(namespace);
|
|
381
|
+
debug.extend = extend;
|
|
382
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
383
|
+
|
|
384
|
+
Object.defineProperty(debug, 'enabled', {
|
|
385
|
+
enumerable: true,
|
|
386
|
+
configurable: false,
|
|
387
|
+
get: () => {
|
|
388
|
+
if (enableOverride !== null) {
|
|
389
|
+
return enableOverride;
|
|
390
|
+
}
|
|
391
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
392
|
+
namespacesCache = createDebug.namespaces;
|
|
393
|
+
enabledCache = createDebug.enabled(namespace);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return enabledCache;
|
|
397
|
+
},
|
|
398
|
+
set: v => {
|
|
399
|
+
enableOverride = v;
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// Env-specific initialization logic for debug instances
|
|
404
|
+
if (typeof createDebug.init === 'function') {
|
|
405
|
+
createDebug.init(debug);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
return debug;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
function extend(namespace, delimiter) {
|
|
412
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
413
|
+
newDebug.log = this.log;
|
|
414
|
+
return newDebug;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
419
|
+
* separated by a colon and wildcards.
|
|
420
|
+
*
|
|
421
|
+
* @param {String} namespaces
|
|
422
|
+
* @api public
|
|
423
|
+
*/
|
|
424
|
+
function enable(namespaces) {
|
|
425
|
+
createDebug.save(namespaces);
|
|
426
|
+
createDebug.namespaces = namespaces;
|
|
427
|
+
|
|
428
|
+
createDebug.names = [];
|
|
429
|
+
createDebug.skips = [];
|
|
430
|
+
|
|
431
|
+
let i;
|
|
432
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
433
|
+
const len = split.length;
|
|
434
|
+
|
|
435
|
+
for (i = 0; i < len; i++) {
|
|
436
|
+
if (!split[i]) {
|
|
437
|
+
// ignore empty strings
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
442
|
+
|
|
443
|
+
if (namespaces[0] === '-') {
|
|
444
|
+
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
|
445
|
+
} else {
|
|
446
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Disable debug output.
|
|
453
|
+
*
|
|
454
|
+
* @return {String} namespaces
|
|
455
|
+
* @api public
|
|
456
|
+
*/
|
|
457
|
+
function disable() {
|
|
458
|
+
const namespaces = [
|
|
459
|
+
...createDebug.names.map(toNamespace),
|
|
460
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
461
|
+
].join(',');
|
|
462
|
+
createDebug.enable('');
|
|
463
|
+
return namespaces;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
468
|
+
*
|
|
469
|
+
* @param {String} name
|
|
470
|
+
* @return {Boolean}
|
|
471
|
+
* @api public
|
|
472
|
+
*/
|
|
473
|
+
function enabled(name) {
|
|
474
|
+
if (name[name.length - 1] === '*') {
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
let i;
|
|
479
|
+
let len;
|
|
480
|
+
|
|
481
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
482
|
+
if (createDebug.skips[i].test(name)) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
488
|
+
if (createDebug.names[i].test(name)) {
|
|
489
|
+
return true;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return false;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Convert regexp to namespace
|
|
498
|
+
*
|
|
499
|
+
* @param {RegExp} regxep
|
|
500
|
+
* @return {String} namespace
|
|
501
|
+
* @api private
|
|
502
|
+
*/
|
|
503
|
+
function toNamespace(regexp) {
|
|
504
|
+
return regexp.toString()
|
|
505
|
+
.substring(2, regexp.toString().length - 2)
|
|
506
|
+
.replace(/\.\*\?$/, '*');
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Coerce `val`.
|
|
511
|
+
*
|
|
512
|
+
* @param {Mixed} val
|
|
513
|
+
* @return {Mixed}
|
|
514
|
+
* @api private
|
|
515
|
+
*/
|
|
516
|
+
function coerce(val) {
|
|
517
|
+
if (val instanceof Error) {
|
|
518
|
+
return val.stack || val.message;
|
|
519
|
+
}
|
|
520
|
+
return val;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
525
|
+
* XXX It WILL be removed in the next major release.
|
|
526
|
+
*/
|
|
527
|
+
function destroy() {
|
|
528
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
createDebug.enable(createDebug.load());
|
|
532
|
+
|
|
533
|
+
return createDebug;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
var common = setup;
|
|
537
|
+
|
|
538
|
+
/* eslint-env browser */
|
|
539
|
+
|
|
540
|
+
(function (module, exports) {
|
|
541
|
+
/**
|
|
542
|
+
* This is the web browser implementation of `debug()`.
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
exports.formatArgs = formatArgs;
|
|
546
|
+
exports.save = save;
|
|
547
|
+
exports.load = load;
|
|
548
|
+
exports.useColors = useColors;
|
|
549
|
+
exports.storage = localstorage();
|
|
550
|
+
exports.destroy = (() => {
|
|
551
|
+
let warned = false;
|
|
552
|
+
|
|
553
|
+
return () => {
|
|
554
|
+
if (!warned) {
|
|
555
|
+
warned = true;
|
|
556
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
})();
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Colors.
|
|
563
|
+
*/
|
|
564
|
+
|
|
565
|
+
exports.colors = [
|
|
566
|
+
'#0000CC',
|
|
567
|
+
'#0000FF',
|
|
568
|
+
'#0033CC',
|
|
569
|
+
'#0033FF',
|
|
570
|
+
'#0066CC',
|
|
571
|
+
'#0066FF',
|
|
572
|
+
'#0099CC',
|
|
573
|
+
'#0099FF',
|
|
574
|
+
'#00CC00',
|
|
575
|
+
'#00CC33',
|
|
576
|
+
'#00CC66',
|
|
577
|
+
'#00CC99',
|
|
578
|
+
'#00CCCC',
|
|
579
|
+
'#00CCFF',
|
|
580
|
+
'#3300CC',
|
|
581
|
+
'#3300FF',
|
|
582
|
+
'#3333CC',
|
|
583
|
+
'#3333FF',
|
|
584
|
+
'#3366CC',
|
|
585
|
+
'#3366FF',
|
|
586
|
+
'#3399CC',
|
|
587
|
+
'#3399FF',
|
|
588
|
+
'#33CC00',
|
|
589
|
+
'#33CC33',
|
|
590
|
+
'#33CC66',
|
|
591
|
+
'#33CC99',
|
|
592
|
+
'#33CCCC',
|
|
593
|
+
'#33CCFF',
|
|
594
|
+
'#6600CC',
|
|
595
|
+
'#6600FF',
|
|
596
|
+
'#6633CC',
|
|
597
|
+
'#6633FF',
|
|
598
|
+
'#66CC00',
|
|
599
|
+
'#66CC33',
|
|
600
|
+
'#9900CC',
|
|
601
|
+
'#9900FF',
|
|
602
|
+
'#9933CC',
|
|
603
|
+
'#9933FF',
|
|
604
|
+
'#99CC00',
|
|
605
|
+
'#99CC33',
|
|
606
|
+
'#CC0000',
|
|
607
|
+
'#CC0033',
|
|
608
|
+
'#CC0066',
|
|
609
|
+
'#CC0099',
|
|
610
|
+
'#CC00CC',
|
|
611
|
+
'#CC00FF',
|
|
612
|
+
'#CC3300',
|
|
613
|
+
'#CC3333',
|
|
614
|
+
'#CC3366',
|
|
615
|
+
'#CC3399',
|
|
616
|
+
'#CC33CC',
|
|
617
|
+
'#CC33FF',
|
|
618
|
+
'#CC6600',
|
|
619
|
+
'#CC6633',
|
|
620
|
+
'#CC9900',
|
|
621
|
+
'#CC9933',
|
|
622
|
+
'#CCCC00',
|
|
623
|
+
'#CCCC33',
|
|
624
|
+
'#FF0000',
|
|
625
|
+
'#FF0033',
|
|
626
|
+
'#FF0066',
|
|
627
|
+
'#FF0099',
|
|
628
|
+
'#FF00CC',
|
|
629
|
+
'#FF00FF',
|
|
630
|
+
'#FF3300',
|
|
631
|
+
'#FF3333',
|
|
632
|
+
'#FF3366',
|
|
633
|
+
'#FF3399',
|
|
634
|
+
'#FF33CC',
|
|
635
|
+
'#FF33FF',
|
|
636
|
+
'#FF6600',
|
|
637
|
+
'#FF6633',
|
|
638
|
+
'#FF9900',
|
|
639
|
+
'#FF9933',
|
|
640
|
+
'#FFCC00',
|
|
641
|
+
'#FFCC33'
|
|
642
|
+
];
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
646
|
+
* and the Firebug extension (any Firefox version) are known
|
|
647
|
+
* to support "%c" CSS customizations.
|
|
648
|
+
*
|
|
649
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
650
|
+
*/
|
|
651
|
+
|
|
652
|
+
// eslint-disable-next-line complexity
|
|
653
|
+
function useColors() {
|
|
654
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
655
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
656
|
+
// explicitly
|
|
657
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
658
|
+
return true;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Internet Explorer and Edge do not support colors.
|
|
662
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
663
|
+
return false;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
667
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
668
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
669
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
670
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
671
|
+
// Is firefox >= v31?
|
|
672
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
673
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
674
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
675
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
/**
|
|
679
|
+
* Colorize log arguments if enabled.
|
|
680
|
+
*
|
|
681
|
+
* @api public
|
|
682
|
+
*/
|
|
683
|
+
|
|
684
|
+
function formatArgs(args) {
|
|
685
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
686
|
+
this.namespace +
|
|
687
|
+
(this.useColors ? ' %c' : ' ') +
|
|
688
|
+
args[0] +
|
|
689
|
+
(this.useColors ? '%c ' : ' ') +
|
|
690
|
+
'+' + module.exports.humanize(this.diff);
|
|
691
|
+
|
|
692
|
+
if (!this.useColors) {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
const c = 'color: ' + this.color;
|
|
697
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
698
|
+
|
|
699
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
700
|
+
// arguments passed either before or after the %c, so we need to
|
|
701
|
+
// figure out the correct index to insert the CSS into
|
|
702
|
+
let index = 0;
|
|
703
|
+
let lastC = 0;
|
|
704
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
705
|
+
if (match === '%%') {
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
index++;
|
|
709
|
+
if (match === '%c') {
|
|
710
|
+
// We only are interested in the *last* %c
|
|
711
|
+
// (the user may have provided their own)
|
|
712
|
+
lastC = index;
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
args.splice(lastC, 0, c);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
/**
|
|
720
|
+
* Invokes `console.debug()` when available.
|
|
721
|
+
* No-op when `console.debug` is not a "function".
|
|
722
|
+
* If `console.debug` is not available, falls back
|
|
723
|
+
* to `console.log`.
|
|
724
|
+
*
|
|
725
|
+
* @api public
|
|
726
|
+
*/
|
|
727
|
+
exports.log = console.debug || console.log || (() => {});
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Save `namespaces`.
|
|
731
|
+
*
|
|
732
|
+
* @param {String} namespaces
|
|
733
|
+
* @api private
|
|
734
|
+
*/
|
|
735
|
+
function save(namespaces) {
|
|
736
|
+
try {
|
|
737
|
+
if (namespaces) {
|
|
738
|
+
exports.storage.setItem('debug', namespaces);
|
|
739
|
+
} else {
|
|
740
|
+
exports.storage.removeItem('debug');
|
|
741
|
+
}
|
|
742
|
+
} catch (error) {
|
|
743
|
+
// Swallow
|
|
744
|
+
// XXX (@Qix-) should we be logging these?
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Load `namespaces`.
|
|
750
|
+
*
|
|
751
|
+
* @return {String} returns the previously persisted debug modes
|
|
752
|
+
* @api private
|
|
753
|
+
*/
|
|
754
|
+
function load() {
|
|
755
|
+
let r;
|
|
756
|
+
try {
|
|
757
|
+
r = exports.storage.getItem('debug');
|
|
758
|
+
} catch (error) {
|
|
759
|
+
// Swallow
|
|
760
|
+
// XXX (@Qix-) should we be logging these?
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
764
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
765
|
+
r = process.env.DEBUG;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
return r;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
/**
|
|
772
|
+
* Localstorage attempts to return the localstorage.
|
|
773
|
+
*
|
|
774
|
+
* This is necessary because safari throws
|
|
775
|
+
* when a user disables cookies/localstorage
|
|
776
|
+
* and you attempt to access it.
|
|
777
|
+
*
|
|
778
|
+
* @return {LocalStorage}
|
|
779
|
+
* @api private
|
|
780
|
+
*/
|
|
781
|
+
|
|
782
|
+
function localstorage() {
|
|
783
|
+
try {
|
|
784
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
785
|
+
// The Browser also has localStorage in the global context.
|
|
786
|
+
return localStorage;
|
|
787
|
+
} catch (error) {
|
|
788
|
+
// Swallow
|
|
789
|
+
// XXX (@Qix-) should we be logging these?
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
module.exports = common(exports);
|
|
794
|
+
|
|
795
|
+
const {formatters} = module.exports;
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
799
|
+
*/
|
|
800
|
+
|
|
801
|
+
formatters.j = function (v) {
|
|
802
|
+
try {
|
|
803
|
+
return JSON.stringify(v);
|
|
804
|
+
} catch (error) {
|
|
805
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
806
|
+
}
|
|
807
|
+
};
|
|
808
|
+
} (browser, browser.exports));
|
|
809
|
+
|
|
810
|
+
var browserExports = browser.exports;
|
|
811
|
+
var createDebug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
|
|
812
|
+
|
|
813
|
+
createDebug("foxglove:server");
|
|
814
|
+
new TextEncoder();
|
|
815
|
+
({
|
|
816
|
+
subscribe: undefined,
|
|
817
|
+
unsubscribe: undefined,
|
|
818
|
+
advertise: ServerCapability.clientPublish,
|
|
819
|
+
unadvertise: ServerCapability.clientPublish,
|
|
820
|
+
[ClientBinaryOpcode.MESSAGE_DATA]: ServerCapability.clientPublish,
|
|
821
|
+
getParameters: ServerCapability.parameters,
|
|
822
|
+
setParameters: ServerCapability.parameters,
|
|
823
|
+
subscribeParameterUpdates: ServerCapability.parametersSubscribe,
|
|
824
|
+
unsubscribeParameterUpdates: ServerCapability.parametersSubscribe,
|
|
825
|
+
[ClientBinaryOpcode.SERVICE_CALL_REQUEST]: ServerCapability.services,
|
|
826
|
+
subscribeConnectionGraph: ServerCapability.connectionGraph,
|
|
827
|
+
unsubscribeConnectionGraph: ServerCapability.connectionGraph,
|
|
828
|
+
fetchAsset: ServerCapability.assets,
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
function recordToDataView(record) {
|
|
832
|
+
const text = JSON.stringify(record);
|
|
833
|
+
if (!text) {
|
|
834
|
+
throw new Error("Invalid record");
|
|
835
|
+
}
|
|
836
|
+
const encoder = new TextEncoder();
|
|
837
|
+
const data = encoder.encode(text);
|
|
838
|
+
const dataView = new DataView(data.buffer);
|
|
839
|
+
return dataView;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
843
|
+
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
844
|
+
// file, You can obtain one at http://mozilla.org/MPL/2.0/
|
|
845
|
+
|
|
846
|
+
class WsWorker {
|
|
847
|
+
#ws;
|
|
848
|
+
#client;
|
|
849
|
+
subscriptions = new Map();
|
|
850
|
+
services = new Map();
|
|
851
|
+
createWs(url, onClose) {
|
|
852
|
+
this.#ws = new Waterfall(url, FoxgloveClient.SUPPORTED_SUBPROTOCOL, {
|
|
853
|
+
connectionTimeout: 2000,
|
|
854
|
+
retryPolicy: _attempt => {
|
|
855
|
+
onClose();
|
|
856
|
+
return 1_000;
|
|
857
|
+
},
|
|
858
|
+
factory: url => {
|
|
859
|
+
const rawWs = new WebSocket(url, FoxgloveClient.SUPPORTED_SUBPROTOCOL);
|
|
860
|
+
rawWs.binaryType = "arraybuffer";
|
|
861
|
+
return rawWs;
|
|
862
|
+
}
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
createClient(onClose) {
|
|
866
|
+
this.#client = new FoxgloveClient({
|
|
867
|
+
ws: this.#ws
|
|
868
|
+
});
|
|
869
|
+
this.#client.on("open", () => send({
|
|
870
|
+
type: "open"
|
|
871
|
+
}));
|
|
872
|
+
this.#client.on("close", onClose);
|
|
873
|
+
this.#client.on("error", error => send({
|
|
874
|
+
type: "error",
|
|
875
|
+
error
|
|
876
|
+
}));
|
|
877
|
+
this.#client.on("message", ({
|
|
878
|
+
subscriptionId,
|
|
879
|
+
data
|
|
880
|
+
}) => {
|
|
881
|
+
const subscription = this.subscriptions.get(subscriptionId);
|
|
882
|
+
if (subscription) {
|
|
883
|
+
sendWithTransfer({
|
|
884
|
+
type: "message",
|
|
885
|
+
data: {
|
|
886
|
+
...subscription,
|
|
887
|
+
buffer: data
|
|
888
|
+
}
|
|
889
|
+
}, [data.buffer]);
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
handleAdvertisements() {
|
|
894
|
+
this.#client.on("advertise", channels => {
|
|
895
|
+
const data = [];
|
|
896
|
+
for (const channel of channels) {
|
|
897
|
+
const subscriptionId = this.#client.subscribe(channel.id);
|
|
898
|
+
this.subscriptions.set(subscriptionId, {
|
|
899
|
+
topic: channel.topic,
|
|
900
|
+
schema: channel.schemaName
|
|
901
|
+
});
|
|
902
|
+
data.push({
|
|
903
|
+
topic: channel.topic,
|
|
904
|
+
schemaName: channel.schemaName
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
send({
|
|
908
|
+
type: "channels",
|
|
909
|
+
data
|
|
910
|
+
});
|
|
911
|
+
});
|
|
912
|
+
this.#client.on("advertiseServices", advertisedServices => {
|
|
913
|
+
const data = [];
|
|
914
|
+
for (const service of advertisedServices) {
|
|
915
|
+
this.services.set(service.name, service);
|
|
916
|
+
data.push(service.name);
|
|
917
|
+
}
|
|
918
|
+
send({
|
|
919
|
+
type: "services",
|
|
920
|
+
data
|
|
921
|
+
});
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
handleServiceResponses() {
|
|
925
|
+
this.#client.on("serviceCallResponse", event => {
|
|
926
|
+
sendWithTransfer({
|
|
927
|
+
type: "service_response",
|
|
928
|
+
data: {
|
|
929
|
+
ok: true,
|
|
930
|
+
serviceCallId: event.callId,
|
|
931
|
+
buffer: event.data,
|
|
932
|
+
error: null
|
|
933
|
+
}
|
|
934
|
+
}, [event.data.buffer]);
|
|
935
|
+
});
|
|
936
|
+
}
|
|
937
|
+
constructor(wsUrl) {
|
|
938
|
+
const onClose = () => send({
|
|
939
|
+
type: "close",
|
|
940
|
+
data: null
|
|
941
|
+
});
|
|
942
|
+
try {
|
|
943
|
+
this.createWs(wsUrl, onClose);
|
|
944
|
+
this.createClient(onClose);
|
|
945
|
+
this.handleAdvertisements();
|
|
946
|
+
this.handleServiceResponses();
|
|
947
|
+
} catch (error) {
|
|
948
|
+
// try-catch is needed to catch `Mixed Content` errors in Chrome, where the client
|
|
949
|
+
// attempts to load `ws://` from `https://`. (Safari would catch these in `ws.onerror`
|
|
950
|
+
// but with `undefined` as an error.)
|
|
951
|
+
send({
|
|
952
|
+
type: "error",
|
|
953
|
+
error: error ?? {
|
|
954
|
+
message: "Insecure WebSocket connection"
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
send(data) {
|
|
960
|
+
this.#ws.send(data);
|
|
961
|
+
}
|
|
962
|
+
close() {
|
|
963
|
+
this.#client.close();
|
|
964
|
+
}
|
|
965
|
+
callService({
|
|
966
|
+
name,
|
|
967
|
+
serviceCallId,
|
|
968
|
+
body = {}
|
|
969
|
+
}) {
|
|
970
|
+
const service = this.services.get(name);
|
|
971
|
+
if (!service) {
|
|
972
|
+
send({
|
|
973
|
+
type: "service_response",
|
|
974
|
+
data: {
|
|
975
|
+
serviceCallId,
|
|
976
|
+
ok: false,
|
|
977
|
+
error: "Service was not advertised",
|
|
978
|
+
buffer: null
|
|
979
|
+
}
|
|
980
|
+
});
|
|
981
|
+
return;
|
|
982
|
+
}
|
|
983
|
+
this.#client.sendServiceCallRequest({
|
|
984
|
+
serviceId: service.id,
|
|
985
|
+
callId: serviceCallId,
|
|
986
|
+
encoding: "json",
|
|
987
|
+
data: recordToDataView(body)
|
|
988
|
+
});
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
let wsWorker = null;
|
|
992
|
+
const send = self.postMessage;
|
|
993
|
+
const sendWithTransfer = self.postMessage;
|
|
994
|
+
self.addEventListener("message", async event => {
|
|
995
|
+
const {
|
|
996
|
+
type,
|
|
997
|
+
data
|
|
998
|
+
} = event.data;
|
|
999
|
+
switch (type) {
|
|
1000
|
+
case "open":
|
|
1001
|
+
wsWorker = new WsWorker(data.wsUrl);
|
|
1002
|
+
break;
|
|
1003
|
+
case "close":
|
|
1004
|
+
wsWorker?.close();
|
|
1005
|
+
break;
|
|
1006
|
+
case "send":
|
|
1007
|
+
wsWorker?.send(data);
|
|
1008
|
+
break;
|
|
1009
|
+
case "call_service":
|
|
1010
|
+
wsWorker?.callService(data);
|
|
1011
|
+
break;
|
|
1012
|
+
}
|
|
1013
|
+
});
|