@luxonis/visualizer-protobuf 1.8.7 → 1.8.8

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.
Files changed (51) hide show
  1. package/dist/apps/depthai-visualizer/src/connection/BaseConnection.d.ts +7 -6
  2. package/dist/apps/depthai-visualizer/src/connection/BaseConnection.d.ts.map +1 -1
  3. package/dist/apps/depthai-visualizer/src/connection/BaseConnection.js.map +1 -1
  4. package/dist/apps/depthai-visualizer/src/connection/ws/Adapter.d.ts +1 -1
  5. package/dist/apps/depthai-visualizer/src/connection/ws/Adapter.d.ts.map +1 -1
  6. package/dist/apps/depthai-visualizer/src/connection/ws/Adapter.js +6 -3
  7. package/dist/apps/depthai-visualizer/src/connection/ws/Adapter.js.map +1 -1
  8. package/dist/apps/depthai-visualizer/src/connection/ws/Connection.d.ts +6 -6
  9. package/dist/apps/depthai-visualizer/src/connection/ws/Connection.d.ts.map +1 -1
  10. package/dist/apps/depthai-visualizer/src/connection/ws/Connection.js +4 -4
  11. package/dist/apps/depthai-visualizer/src/connection/ws/Connection.js.map +1 -1
  12. package/dist/apps/depthai-visualizer/src/connection/ws/worker-utils.d.ts +83 -0
  13. package/dist/apps/depthai-visualizer/src/connection/ws/worker-utils.d.ts.map +1 -0
  14. package/dist/apps/depthai-visualizer/src/connection/ws/worker-utils.js +184 -0
  15. package/dist/apps/depthai-visualizer/src/connection/ws/worker-utils.js.map +1 -0
  16. package/dist/apps/depthai-visualizer/src/connection/ws/worker.d.ts +1 -57
  17. package/dist/apps/depthai-visualizer/src/connection/ws/worker.d.ts.map +1 -1
  18. package/dist/apps/depthai-visualizer/src/connection/ws/worker.js +2 -171
  19. package/dist/apps/depthai-visualizer/src/connection/ws/worker.js.map +1 -1
  20. package/dist/apps/depthai-visualizer/src/index.d.ts +3 -4
  21. package/dist/apps/depthai-visualizer/src/index.d.ts.map +1 -1
  22. package/dist/apps/depthai-visualizer/src/index.js +1 -2
  23. package/dist/apps/depthai-visualizer/src/index.js.map +1 -1
  24. package/dist/{index-BuuOsI5x.js → index-0Q6EqxBW.js} +7 -4
  25. package/dist/{index-PRD8Vx5h.js → index-BBXW7Wxj.js} +33 -448
  26. package/dist/{index-ByXG8O46.js → index-Bpjac43y.js} +4 -2
  27. package/dist/{index-BKodwqoN.js → index-CF21cEJo.js} +4 -2
  28. package/dist/{index-DY872ZDo.js → index-CbLiW7lk.js} +4 -2
  29. package/dist/{index-BgXnyRS5.js → index-Cl5tDqdc.js} +4 -2
  30. package/dist/{index-BYKYHdD1.js → index-DAPJpbdc.js} +4 -2
  31. package/dist/{index-DbBAYYLN.js → index-DCbNqqQc.js} +4 -2
  32. package/dist/{index-BbjcxqKn.js → index-DUnP2Xma.js} +5 -4
  33. package/dist/{index-DTSS5_f7.js → index-DkQzCBNS.js} +4 -2
  34. package/dist/{index-CzFeKxPw.js → index-DlKZDt0v.js} +4 -2
  35. package/dist/{index-CxLTPANc.js → index-F8-9liAo.js} +4 -2
  36. package/dist/{index-Du_K2fSC.js → index-H6bxF3CN.js} +4 -2
  37. package/dist/{index-tsO6geQz.js → index-QEJn3K9v.js} +4 -2
  38. package/dist/{index-CeDdrD6U.js → index-W-M5T20d.js} +4 -2
  39. package/dist/{index-CVP9pfZS.js → index-lDSplInz.js} +4 -2
  40. package/dist/{index-DiuZWhZw.js → index-ovt0UKFi.js} +4 -2
  41. package/dist/{index-iE53L-9n.js → index-pNYe-U8V.js} +4 -2
  42. package/dist/{index-BOt4IOh5.js → index-zKmjws_7.js} +4 -2
  43. package/dist/index.js +5 -3
  44. package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/Images/WorkerImageDecoder.d.ts.map +1 -1
  45. package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/Images/WorkerImageDecoder.js +1 -1
  46. package/dist/packages/studio-base/src/panels/ThreeDeeRender/renderables/Images/WorkerImageDecoder.js.map +1 -1
  47. package/dist/worker-D2k1TTky.js +10 -0
  48. package/dist/{protobuf-CjDCjqx3.js → worker-utils-Jii8lIsy.js} +1406 -1
  49. package/package.json +1 -1
  50. package/dist/index-CcszYLTP.js +0 -346
  51. package/dist/worker-CHyNU_Ed.js +0 -1059
@@ -1,3 +1,5 @@
1
+ import { Waterfall } from 'hydrated-ws';
2
+ import require$$0 from 'ms';
1
3
  import _m0 from 'protobufjs/minimal';
2
4
 
3
5
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -5239,4 +5241,1407 @@ const protobufsBySchema = Object.fromEntries(Object.entries(protobufs).map(([typ
5239
5241
  ...data
5240
5242
  }]));
5241
5243
 
5242
- export { PointsAnnotationType as P, Type as T, getDefaultExportFromCjs as a, Profile as b, commonjsGlobal as c, getAugmentedNamespace as g, protobufsBySchema as p };
5244
+ var eventemitter3 = {exports: {}};
5245
+
5246
+ (function (module) {
5247
+
5248
+ var has = Object.prototype.hasOwnProperty
5249
+ , prefix = '~';
5250
+
5251
+ /**
5252
+ * Constructor to create a storage for our `EE` objects.
5253
+ * An `Events` instance is a plain object whose properties are event names.
5254
+ *
5255
+ * @constructor
5256
+ * @private
5257
+ */
5258
+ function Events() {}
5259
+
5260
+ //
5261
+ // We try to not inherit from `Object.prototype`. In some engines creating an
5262
+ // instance in this way is faster than calling `Object.create(null)` directly.
5263
+ // If `Object.create(null)` is not supported we prefix the event names with a
5264
+ // character to make sure that the built-in object properties are not
5265
+ // overridden or used as an attack vector.
5266
+ //
5267
+ if (Object.create) {
5268
+ Events.prototype = Object.create(null);
5269
+
5270
+ //
5271
+ // This hack is needed because the `__proto__` property is still inherited in
5272
+ // some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
5273
+ //
5274
+ if (!new Events().__proto__) prefix = false;
5275
+ }
5276
+
5277
+ /**
5278
+ * Representation of a single event listener.
5279
+ *
5280
+ * @param {Function} fn The listener function.
5281
+ * @param {*} context The context to invoke the listener with.
5282
+ * @param {Boolean} [once=false] Specify if the listener is a one-time listener.
5283
+ * @constructor
5284
+ * @private
5285
+ */
5286
+ function EE(fn, context, once) {
5287
+ this.fn = fn;
5288
+ this.context = context;
5289
+ this.once = once || false;
5290
+ }
5291
+
5292
+ /**
5293
+ * Add a listener for a given event.
5294
+ *
5295
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
5296
+ * @param {(String|Symbol)} event The event name.
5297
+ * @param {Function} fn The listener function.
5298
+ * @param {*} context The context to invoke the listener with.
5299
+ * @param {Boolean} once Specify if the listener is a one-time listener.
5300
+ * @returns {EventEmitter}
5301
+ * @private
5302
+ */
5303
+ function addListener(emitter, event, fn, context, once) {
5304
+ if (typeof fn !== 'function') {
5305
+ throw new TypeError('The listener must be a function');
5306
+ }
5307
+
5308
+ var listener = new EE(fn, context || emitter, once)
5309
+ , evt = prefix ? prefix + event : event;
5310
+
5311
+ if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
5312
+ else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
5313
+ else emitter._events[evt] = [emitter._events[evt], listener];
5314
+
5315
+ return emitter;
5316
+ }
5317
+
5318
+ /**
5319
+ * Clear event by name.
5320
+ *
5321
+ * @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
5322
+ * @param {(String|Symbol)} evt The Event name.
5323
+ * @private
5324
+ */
5325
+ function clearEvent(emitter, evt) {
5326
+ if (--emitter._eventsCount === 0) emitter._events = new Events();
5327
+ else delete emitter._events[evt];
5328
+ }
5329
+
5330
+ /**
5331
+ * Minimal `EventEmitter` interface that is molded against the Node.js
5332
+ * `EventEmitter` interface.
5333
+ *
5334
+ * @constructor
5335
+ * @public
5336
+ */
5337
+ function EventEmitter() {
5338
+ this._events = new Events();
5339
+ this._eventsCount = 0;
5340
+ }
5341
+
5342
+ /**
5343
+ * Return an array listing the events for which the emitter has registered
5344
+ * listeners.
5345
+ *
5346
+ * @returns {Array}
5347
+ * @public
5348
+ */
5349
+ EventEmitter.prototype.eventNames = function eventNames() {
5350
+ var names = []
5351
+ , events
5352
+ , name;
5353
+
5354
+ if (this._eventsCount === 0) return names;
5355
+
5356
+ for (name in (events = this._events)) {
5357
+ if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
5358
+ }
5359
+
5360
+ if (Object.getOwnPropertySymbols) {
5361
+ return names.concat(Object.getOwnPropertySymbols(events));
5362
+ }
5363
+
5364
+ return names;
5365
+ };
5366
+
5367
+ /**
5368
+ * Return the listeners registered for a given event.
5369
+ *
5370
+ * @param {(String|Symbol)} event The event name.
5371
+ * @returns {Array} The registered listeners.
5372
+ * @public
5373
+ */
5374
+ EventEmitter.prototype.listeners = function listeners(event) {
5375
+ var evt = prefix ? prefix + event : event
5376
+ , handlers = this._events[evt];
5377
+
5378
+ if (!handlers) return [];
5379
+ if (handlers.fn) return [handlers.fn];
5380
+
5381
+ for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
5382
+ ee[i] = handlers[i].fn;
5383
+ }
5384
+
5385
+ return ee;
5386
+ };
5387
+
5388
+ /**
5389
+ * Return the number of listeners listening to a given event.
5390
+ *
5391
+ * @param {(String|Symbol)} event The event name.
5392
+ * @returns {Number} The number of listeners.
5393
+ * @public
5394
+ */
5395
+ EventEmitter.prototype.listenerCount = function listenerCount(event) {
5396
+ var evt = prefix ? prefix + event : event
5397
+ , listeners = this._events[evt];
5398
+
5399
+ if (!listeners) return 0;
5400
+ if (listeners.fn) return 1;
5401
+ return listeners.length;
5402
+ };
5403
+
5404
+ /**
5405
+ * Calls each of the listeners registered for a given event.
5406
+ *
5407
+ * @param {(String|Symbol)} event The event name.
5408
+ * @returns {Boolean} `true` if the event had listeners, else `false`.
5409
+ * @public
5410
+ */
5411
+ EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
5412
+ var evt = prefix ? prefix + event : event;
5413
+
5414
+ if (!this._events[evt]) return false;
5415
+
5416
+ var listeners = this._events[evt]
5417
+ , len = arguments.length
5418
+ , args
5419
+ , i;
5420
+
5421
+ if (listeners.fn) {
5422
+ if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
5423
+
5424
+ switch (len) {
5425
+ case 1: return listeners.fn.call(listeners.context), true;
5426
+ case 2: return listeners.fn.call(listeners.context, a1), true;
5427
+ case 3: return listeners.fn.call(listeners.context, a1, a2), true;
5428
+ case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
5429
+ case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
5430
+ case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
5431
+ }
5432
+
5433
+ for (i = 1, args = new Array(len -1); i < len; i++) {
5434
+ args[i - 1] = arguments[i];
5435
+ }
5436
+
5437
+ listeners.fn.apply(listeners.context, args);
5438
+ } else {
5439
+ var length = listeners.length
5440
+ , j;
5441
+
5442
+ for (i = 0; i < length; i++) {
5443
+ if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
5444
+
5445
+ switch (len) {
5446
+ case 1: listeners[i].fn.call(listeners[i].context); break;
5447
+ case 2: listeners[i].fn.call(listeners[i].context, a1); break;
5448
+ case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
5449
+ case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
5450
+ default:
5451
+ if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
5452
+ args[j - 1] = arguments[j];
5453
+ }
5454
+
5455
+ listeners[i].fn.apply(listeners[i].context, args);
5456
+ }
5457
+ }
5458
+ }
5459
+
5460
+ return true;
5461
+ };
5462
+
5463
+ /**
5464
+ * Add a listener for a given event.
5465
+ *
5466
+ * @param {(String|Symbol)} event The event name.
5467
+ * @param {Function} fn The listener function.
5468
+ * @param {*} [context=this] The context to invoke the listener with.
5469
+ * @returns {EventEmitter} `this`.
5470
+ * @public
5471
+ */
5472
+ EventEmitter.prototype.on = function on(event, fn, context) {
5473
+ return addListener(this, event, fn, context, false);
5474
+ };
5475
+
5476
+ /**
5477
+ * Add a one-time listener for a given event.
5478
+ *
5479
+ * @param {(String|Symbol)} event The event name.
5480
+ * @param {Function} fn The listener function.
5481
+ * @param {*} [context=this] The context to invoke the listener with.
5482
+ * @returns {EventEmitter} `this`.
5483
+ * @public
5484
+ */
5485
+ EventEmitter.prototype.once = function once(event, fn, context) {
5486
+ return addListener(this, event, fn, context, true);
5487
+ };
5488
+
5489
+ /**
5490
+ * Remove the listeners of a given event.
5491
+ *
5492
+ * @param {(String|Symbol)} event The event name.
5493
+ * @param {Function} fn Only remove the listeners that match this function.
5494
+ * @param {*} context Only remove the listeners that have this context.
5495
+ * @param {Boolean} once Only remove one-time listeners.
5496
+ * @returns {EventEmitter} `this`.
5497
+ * @public
5498
+ */
5499
+ EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
5500
+ var evt = prefix ? prefix + event : event;
5501
+
5502
+ if (!this._events[evt]) return this;
5503
+ if (!fn) {
5504
+ clearEvent(this, evt);
5505
+ return this;
5506
+ }
5507
+
5508
+ var listeners = this._events[evt];
5509
+
5510
+ if (listeners.fn) {
5511
+ if (
5512
+ listeners.fn === fn &&
5513
+ (!once || listeners.once) &&
5514
+ (!context || listeners.context === context)
5515
+ ) {
5516
+ clearEvent(this, evt);
5517
+ }
5518
+ } else {
5519
+ for (var i = 0, events = [], length = listeners.length; i < length; i++) {
5520
+ if (
5521
+ listeners[i].fn !== fn ||
5522
+ (once && !listeners[i].once) ||
5523
+ (context && listeners[i].context !== context)
5524
+ ) {
5525
+ events.push(listeners[i]);
5526
+ }
5527
+ }
5528
+
5529
+ //
5530
+ // Reset the array, or remove it completely if we have no more listeners.
5531
+ //
5532
+ if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
5533
+ else clearEvent(this, evt);
5534
+ }
5535
+
5536
+ return this;
5537
+ };
5538
+
5539
+ /**
5540
+ * Remove all listeners, or those of the specified event.
5541
+ *
5542
+ * @param {(String|Symbol)} [event] The event name.
5543
+ * @returns {EventEmitter} `this`.
5544
+ * @public
5545
+ */
5546
+ EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
5547
+ var evt;
5548
+
5549
+ if (event) {
5550
+ evt = prefix ? prefix + event : event;
5551
+ if (this._events[evt]) clearEvent(this, evt);
5552
+ } else {
5553
+ this._events = new Events();
5554
+ this._eventsCount = 0;
5555
+ }
5556
+
5557
+ return this;
5558
+ };
5559
+
5560
+ //
5561
+ // Alias methods names because people roll like that.
5562
+ //
5563
+ EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
5564
+ EventEmitter.prototype.addListener = EventEmitter.prototype.on;
5565
+
5566
+ //
5567
+ // Expose the prefix.
5568
+ //
5569
+ EventEmitter.prefixed = prefix;
5570
+
5571
+ //
5572
+ // Allow `EventEmitter` to be imported as module namespace.
5573
+ //
5574
+ EventEmitter.EventEmitter = EventEmitter;
5575
+
5576
+ //
5577
+ // Expose the module.
5578
+ //
5579
+ {
5580
+ module.exports = EventEmitter;
5581
+ }
5582
+ } (eventemitter3));
5583
+
5584
+ var eventemitter3Exports = eventemitter3.exports;
5585
+ var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
5586
+
5587
+ var BinaryOpcode;
5588
+ (function (BinaryOpcode) {
5589
+ BinaryOpcode[BinaryOpcode["MESSAGE_DATA"] = 1] = "MESSAGE_DATA";
5590
+ BinaryOpcode[BinaryOpcode["TIME"] = 2] = "TIME";
5591
+ BinaryOpcode[BinaryOpcode["SERVICE_CALL_RESPONSE"] = 3] = "SERVICE_CALL_RESPONSE";
5592
+ BinaryOpcode[BinaryOpcode["FETCH_ASSET_RESPONSE"] = 4] = "FETCH_ASSET_RESPONSE";
5593
+ })(BinaryOpcode || (BinaryOpcode = {}));
5594
+ var ClientBinaryOpcode;
5595
+ (function (ClientBinaryOpcode) {
5596
+ ClientBinaryOpcode[ClientBinaryOpcode["MESSAGE_DATA"] = 1] = "MESSAGE_DATA";
5597
+ ClientBinaryOpcode[ClientBinaryOpcode["SERVICE_CALL_REQUEST"] = 2] = "SERVICE_CALL_REQUEST";
5598
+ })(ClientBinaryOpcode || (ClientBinaryOpcode = {}));
5599
+ var StatusLevel;
5600
+ (function (StatusLevel) {
5601
+ StatusLevel[StatusLevel["INFO"] = 0] = "INFO";
5602
+ StatusLevel[StatusLevel["WARNING"] = 1] = "WARNING";
5603
+ StatusLevel[StatusLevel["ERROR"] = 2] = "ERROR";
5604
+ })(StatusLevel || (StatusLevel = {}));
5605
+ var ServerCapability;
5606
+ (function (ServerCapability) {
5607
+ ServerCapability["clientPublish"] = "clientPublish";
5608
+ ServerCapability["time"] = "time";
5609
+ ServerCapability["parameters"] = "parameters";
5610
+ ServerCapability["parametersSubscribe"] = "parametersSubscribe";
5611
+ ServerCapability["services"] = "services";
5612
+ ServerCapability["connectionGraph"] = "connectionGraph";
5613
+ ServerCapability["assets"] = "assets";
5614
+ })(ServerCapability || (ServerCapability = {}));
5615
+ var FetchAssetStatus;
5616
+ (function (FetchAssetStatus) {
5617
+ FetchAssetStatus[FetchAssetStatus["SUCCESS"] = 0] = "SUCCESS";
5618
+ FetchAssetStatus[FetchAssetStatus["ERROR"] = 1] = "ERROR";
5619
+ })(FetchAssetStatus || (FetchAssetStatus = {}));
5620
+
5621
+ const textDecoder = new TextDecoder();
5622
+ function parseServerMessage(buffer) {
5623
+ const view = new DataView(buffer);
5624
+ let offset = 0;
5625
+ const op = view.getUint8(offset);
5626
+ offset += 1;
5627
+ switch (op) {
5628
+ case BinaryOpcode.MESSAGE_DATA: {
5629
+ const subscriptionId = view.getUint32(offset, true);
5630
+ offset += 4;
5631
+ const timestamp = view.getBigUint64(offset, true);
5632
+ offset += 8;
5633
+ const data = new DataView(buffer, offset);
5634
+ return { op, subscriptionId, timestamp, data };
5635
+ }
5636
+ case BinaryOpcode.TIME: {
5637
+ const timestamp = view.getBigUint64(offset, true);
5638
+ return { op, timestamp };
5639
+ }
5640
+ case BinaryOpcode.SERVICE_CALL_RESPONSE: {
5641
+ const serviceId = view.getUint32(offset, true);
5642
+ offset += 4;
5643
+ const callId = view.getUint32(offset, true);
5644
+ offset += 4;
5645
+ const encodingLength = view.getUint32(offset, true);
5646
+ offset += 4;
5647
+ const encodingBytes = new DataView(buffer, offset, encodingLength);
5648
+ const encoding = textDecoder.decode(encodingBytes);
5649
+ offset += encodingLength;
5650
+ const data = new DataView(buffer, offset, buffer.byteLength - offset);
5651
+ return { op, serviceId, callId, encoding, data };
5652
+ }
5653
+ case BinaryOpcode.FETCH_ASSET_RESPONSE: {
5654
+ const requestId = view.getUint32(offset, true);
5655
+ offset += 4;
5656
+ const status = view.getUint8(offset);
5657
+ offset += 1;
5658
+ const errorMsgLength = view.getUint32(offset, true);
5659
+ offset += 4;
5660
+ const error = textDecoder.decode(new DataView(buffer, offset, errorMsgLength));
5661
+ offset += errorMsgLength;
5662
+ switch (status) {
5663
+ case FetchAssetStatus.SUCCESS: {
5664
+ const data = new DataView(buffer, offset, buffer.byteLength - offset);
5665
+ return { op, requestId, status, data };
5666
+ }
5667
+ case FetchAssetStatus.ERROR:
5668
+ return { op, requestId, status, error };
5669
+ default:
5670
+ throw new Error(`Unrecognized fetch asset status: ${status}`);
5671
+ }
5672
+ }
5673
+ }
5674
+ throw new Error(`Unrecognized server opcode in binary message: ${op.toString(16)}`);
5675
+ }
5676
+
5677
+ const textEncoder = new TextEncoder();
5678
+ class FoxgloveClient {
5679
+ static SUPPORTED_SUBPROTOCOL = "foxglove.websocket.v1";
5680
+ #emitter = new EventEmitter();
5681
+ #ws;
5682
+ #nextSubscriptionId = 0;
5683
+ #nextAdvertisementId = 0;
5684
+ constructor({ ws }) {
5685
+ this.#ws = ws;
5686
+ this.#reconnect();
5687
+ }
5688
+ on(name, listener) {
5689
+ this.#emitter.on(name, listener);
5690
+ }
5691
+ off(name, listener) {
5692
+ this.#emitter.off(name, listener);
5693
+ }
5694
+ #reconnect() {
5695
+ this.#ws.binaryType = "arraybuffer";
5696
+ this.#ws.onerror = (event) => {
5697
+ this.#emitter.emit("error", event.error);
5698
+ };
5699
+ this.#ws.onopen = (_event) => {
5700
+ if (this.#ws.protocol !== FoxgloveClient.SUPPORTED_SUBPROTOCOL) {
5701
+ throw new Error(`Expected subprotocol ${FoxgloveClient.SUPPORTED_SUBPROTOCOL}, got '${this.#ws.protocol}'`);
5702
+ }
5703
+ this.#emitter.emit("open");
5704
+ };
5705
+ this.#ws.onmessage = (event) => {
5706
+ let message;
5707
+ try {
5708
+ if (event.data instanceof ArrayBuffer) {
5709
+ message = parseServerMessage(event.data);
5710
+ }
5711
+ else {
5712
+ message = JSON.parse(event.data);
5713
+ }
5714
+ }
5715
+ catch (error) {
5716
+ this.#emitter.emit("error", error);
5717
+ return;
5718
+ }
5719
+ switch (message.op) {
5720
+ case "serverInfo":
5721
+ this.#emitter.emit("serverInfo", message);
5722
+ return;
5723
+ case "status":
5724
+ this.#emitter.emit("status", message);
5725
+ return;
5726
+ case "advertise":
5727
+ this.#emitter.emit("advertise", message.channels);
5728
+ return;
5729
+ case "unadvertise":
5730
+ this.#emitter.emit("unadvertise", message.channelIds);
5731
+ return;
5732
+ case "parameterValues":
5733
+ this.#emitter.emit("parameterValues", message);
5734
+ return;
5735
+ case "advertiseServices":
5736
+ this.#emitter.emit("advertiseServices", message.services);
5737
+ return;
5738
+ case "unadvertiseServices":
5739
+ this.#emitter.emit("unadvertiseServices", message.serviceIds);
5740
+ return;
5741
+ case "connectionGraphUpdate":
5742
+ this.#emitter.emit("connectionGraphUpdate", message);
5743
+ return;
5744
+ case BinaryOpcode.MESSAGE_DATA:
5745
+ this.#emitter.emit("message", message);
5746
+ return;
5747
+ case BinaryOpcode.TIME:
5748
+ this.#emitter.emit("time", message);
5749
+ return;
5750
+ case BinaryOpcode.SERVICE_CALL_RESPONSE:
5751
+ this.#emitter.emit("serviceCallResponse", message);
5752
+ return;
5753
+ case BinaryOpcode.FETCH_ASSET_RESPONSE:
5754
+ this.#emitter.emit("fetchAssetResponse", message);
5755
+ return;
5756
+ }
5757
+ this.#emitter.emit("error", new Error(`Unrecognized server opcode: ${message.op}`));
5758
+ };
5759
+ this.#ws.onclose = (event) => {
5760
+ this.#emitter.emit("close", event);
5761
+ };
5762
+ }
5763
+ close() {
5764
+ this.#ws.close();
5765
+ }
5766
+ subscribe(channelId) {
5767
+ const id = this.#nextSubscriptionId++;
5768
+ const subscriptions = [{ id, channelId }];
5769
+ this.#send({ op: "subscribe", subscriptions });
5770
+ return id;
5771
+ }
5772
+ unsubscribe(subscriptionId) {
5773
+ this.#send({ op: "unsubscribe", subscriptionIds: [subscriptionId] });
5774
+ }
5775
+ advertise(clientChannel) {
5776
+ const id = ++this.#nextAdvertisementId;
5777
+ const channels = [{ id, ...clientChannel }];
5778
+ this.#send({ op: "advertise", channels });
5779
+ return id;
5780
+ }
5781
+ unadvertise(channelId) {
5782
+ this.#send({ op: "unadvertise", channelIds: [channelId] });
5783
+ }
5784
+ getParameters(parameterNames, id) {
5785
+ this.#send({ op: "getParameters", parameterNames, id });
5786
+ }
5787
+ setParameters(parameters, id) {
5788
+ this.#send({ op: "setParameters", parameters, id });
5789
+ }
5790
+ subscribeParameterUpdates(parameterNames) {
5791
+ this.#send({ op: "subscribeParameterUpdates", parameterNames });
5792
+ }
5793
+ unsubscribeParameterUpdates(parameterNames) {
5794
+ this.#send({ op: "unsubscribeParameterUpdates", parameterNames });
5795
+ }
5796
+ sendMessage(channelId, data) {
5797
+ const payload = new Uint8Array(5 + data.byteLength);
5798
+ const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
5799
+ view.setUint8(0, ClientBinaryOpcode.MESSAGE_DATA);
5800
+ view.setUint32(1, channelId, true);
5801
+ payload.set(data, 5);
5802
+ this.#ws.send(payload);
5803
+ }
5804
+ sendServiceCallRequest(request) {
5805
+ const encoding = textEncoder.encode(request.encoding);
5806
+ const payload = new Uint8Array(1 + 4 + 4 + 4 + encoding.length + request.data.byteLength);
5807
+ const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
5808
+ let offset = 0;
5809
+ view.setUint8(offset, ClientBinaryOpcode.SERVICE_CALL_REQUEST);
5810
+ offset += 1;
5811
+ view.setUint32(offset, request.serviceId, true);
5812
+ offset += 4;
5813
+ view.setUint32(offset, request.callId, true);
5814
+ offset += 4;
5815
+ view.setUint32(offset, request.encoding.length, true);
5816
+ offset += 4;
5817
+ payload.set(encoding, offset);
5818
+ offset += encoding.length;
5819
+ const data = new Uint8Array(request.data.buffer, request.data.byteOffset, request.data.byteLength);
5820
+ payload.set(data, offset);
5821
+ this.#ws.send(payload);
5822
+ }
5823
+ subscribeConnectionGraph() {
5824
+ this.#send({ op: "subscribeConnectionGraph" });
5825
+ }
5826
+ unsubscribeConnectionGraph() {
5827
+ this.#send({ op: "unsubscribeConnectionGraph" });
5828
+ }
5829
+ fetchAsset(uri, requestId) {
5830
+ this.#send({ op: "fetchAsset", uri, requestId });
5831
+ }
5832
+ /**
5833
+ * @deprecated Use `sendServiceCallRequest` instead
5834
+ */
5835
+ sendCallServiceRequest(request) {
5836
+ this.sendServiceCallRequest(request);
5837
+ }
5838
+ #send(message) {
5839
+ this.#ws.send(JSON.stringify(message));
5840
+ }
5841
+ }
5842
+
5843
+ var browser = {exports: {}};
5844
+
5845
+ /**
5846
+ * This is the common logic for both the Node.js and web browser
5847
+ * implementations of `debug()`.
5848
+ */
5849
+
5850
+ function setup(env) {
5851
+ createDebug.debug = createDebug;
5852
+ createDebug.default = createDebug;
5853
+ createDebug.coerce = coerce;
5854
+ createDebug.disable = disable;
5855
+ createDebug.enable = enable;
5856
+ createDebug.enabled = enabled;
5857
+ createDebug.humanize = require$$0;
5858
+ createDebug.destroy = destroy;
5859
+
5860
+ Object.keys(env).forEach(key => {
5861
+ createDebug[key] = env[key];
5862
+ });
5863
+
5864
+ /**
5865
+ * The currently active debug mode names, and names to skip.
5866
+ */
5867
+
5868
+ createDebug.names = [];
5869
+ createDebug.skips = [];
5870
+
5871
+ /**
5872
+ * Map of special "%n" handling functions, for the debug "format" argument.
5873
+ *
5874
+ * Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
5875
+ */
5876
+ createDebug.formatters = {};
5877
+
5878
+ /**
5879
+ * Selects a color for a debug namespace
5880
+ * @param {String} namespace The namespace string for the debug instance to be colored
5881
+ * @return {Number|String} An ANSI color code for the given namespace
5882
+ * @api private
5883
+ */
5884
+ function selectColor(namespace) {
5885
+ let hash = 0;
5886
+
5887
+ for (let i = 0; i < namespace.length; i++) {
5888
+ hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
5889
+ hash |= 0; // Convert to 32bit integer
5890
+ }
5891
+
5892
+ return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
5893
+ }
5894
+ createDebug.selectColor = selectColor;
5895
+
5896
+ /**
5897
+ * Create a debugger with the given `namespace`.
5898
+ *
5899
+ * @param {String} namespace
5900
+ * @return {Function}
5901
+ * @api public
5902
+ */
5903
+ function createDebug(namespace) {
5904
+ let prevTime;
5905
+ let enableOverride = null;
5906
+ let namespacesCache;
5907
+ let enabledCache;
5908
+
5909
+ function debug(...args) {
5910
+ // Disabled?
5911
+ if (!debug.enabled) {
5912
+ return;
5913
+ }
5914
+
5915
+ const self = debug;
5916
+
5917
+ // Set `diff` timestamp
5918
+ const curr = Number(new Date());
5919
+ const ms = curr - (prevTime || curr);
5920
+ self.diff = ms;
5921
+ self.prev = prevTime;
5922
+ self.curr = curr;
5923
+ prevTime = curr;
5924
+
5925
+ args[0] = createDebug.coerce(args[0]);
5926
+
5927
+ if (typeof args[0] !== 'string') {
5928
+ // Anything else let's inspect with %O
5929
+ args.unshift('%O');
5930
+ }
5931
+
5932
+ // Apply any `formatters` transformations
5933
+ let index = 0;
5934
+ args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
5935
+ // If we encounter an escaped % then don't increase the array index
5936
+ if (match === '%%') {
5937
+ return '%';
5938
+ }
5939
+ index++;
5940
+ const formatter = createDebug.formatters[format];
5941
+ if (typeof formatter === 'function') {
5942
+ const val = args[index];
5943
+ match = formatter.call(self, val);
5944
+
5945
+ // Now we need to remove `args[index]` since it's inlined in the `format`
5946
+ args.splice(index, 1);
5947
+ index--;
5948
+ }
5949
+ return match;
5950
+ });
5951
+
5952
+ // Apply env-specific formatting (colors, etc.)
5953
+ createDebug.formatArgs.call(self, args);
5954
+
5955
+ const logFn = self.log || createDebug.log;
5956
+ logFn.apply(self, args);
5957
+ }
5958
+
5959
+ debug.namespace = namespace;
5960
+ debug.useColors = createDebug.useColors();
5961
+ debug.color = createDebug.selectColor(namespace);
5962
+ debug.extend = extend;
5963
+ debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
5964
+
5965
+ Object.defineProperty(debug, 'enabled', {
5966
+ enumerable: true,
5967
+ configurable: false,
5968
+ get: () => {
5969
+ if (enableOverride !== null) {
5970
+ return enableOverride;
5971
+ }
5972
+ if (namespacesCache !== createDebug.namespaces) {
5973
+ namespacesCache = createDebug.namespaces;
5974
+ enabledCache = createDebug.enabled(namespace);
5975
+ }
5976
+
5977
+ return enabledCache;
5978
+ },
5979
+ set: v => {
5980
+ enableOverride = v;
5981
+ }
5982
+ });
5983
+
5984
+ // Env-specific initialization logic for debug instances
5985
+ if (typeof createDebug.init === 'function') {
5986
+ createDebug.init(debug);
5987
+ }
5988
+
5989
+ return debug;
5990
+ }
5991
+
5992
+ function extend(namespace, delimiter) {
5993
+ const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
5994
+ newDebug.log = this.log;
5995
+ return newDebug;
5996
+ }
5997
+
5998
+ /**
5999
+ * Enables a debug mode by namespaces. This can include modes
6000
+ * separated by a colon and wildcards.
6001
+ *
6002
+ * @param {String} namespaces
6003
+ * @api public
6004
+ */
6005
+ function enable(namespaces) {
6006
+ createDebug.save(namespaces);
6007
+ createDebug.namespaces = namespaces;
6008
+
6009
+ createDebug.names = [];
6010
+ createDebug.skips = [];
6011
+
6012
+ let i;
6013
+ const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
6014
+ const len = split.length;
6015
+
6016
+ for (i = 0; i < len; i++) {
6017
+ if (!split[i]) {
6018
+ // ignore empty strings
6019
+ continue;
6020
+ }
6021
+
6022
+ namespaces = split[i].replace(/\*/g, '.*?');
6023
+
6024
+ if (namespaces[0] === '-') {
6025
+ createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
6026
+ } else {
6027
+ createDebug.names.push(new RegExp('^' + namespaces + '$'));
6028
+ }
6029
+ }
6030
+ }
6031
+
6032
+ /**
6033
+ * Disable debug output.
6034
+ *
6035
+ * @return {String} namespaces
6036
+ * @api public
6037
+ */
6038
+ function disable() {
6039
+ const namespaces = [
6040
+ ...createDebug.names.map(toNamespace),
6041
+ ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
6042
+ ].join(',');
6043
+ createDebug.enable('');
6044
+ return namespaces;
6045
+ }
6046
+
6047
+ /**
6048
+ * Returns true if the given mode name is enabled, false otherwise.
6049
+ *
6050
+ * @param {String} name
6051
+ * @return {Boolean}
6052
+ * @api public
6053
+ */
6054
+ function enabled(name) {
6055
+ if (name[name.length - 1] === '*') {
6056
+ return true;
6057
+ }
6058
+
6059
+ let i;
6060
+ let len;
6061
+
6062
+ for (i = 0, len = createDebug.skips.length; i < len; i++) {
6063
+ if (createDebug.skips[i].test(name)) {
6064
+ return false;
6065
+ }
6066
+ }
6067
+
6068
+ for (i = 0, len = createDebug.names.length; i < len; i++) {
6069
+ if (createDebug.names[i].test(name)) {
6070
+ return true;
6071
+ }
6072
+ }
6073
+
6074
+ return false;
6075
+ }
6076
+
6077
+ /**
6078
+ * Convert regexp to namespace
6079
+ *
6080
+ * @param {RegExp} regxep
6081
+ * @return {String} namespace
6082
+ * @api private
6083
+ */
6084
+ function toNamespace(regexp) {
6085
+ return regexp.toString()
6086
+ .substring(2, regexp.toString().length - 2)
6087
+ .replace(/\.\*\?$/, '*');
6088
+ }
6089
+
6090
+ /**
6091
+ * Coerce `val`.
6092
+ *
6093
+ * @param {Mixed} val
6094
+ * @return {Mixed}
6095
+ * @api private
6096
+ */
6097
+ function coerce(val) {
6098
+ if (val instanceof Error) {
6099
+ return val.stack || val.message;
6100
+ }
6101
+ return val;
6102
+ }
6103
+
6104
+ /**
6105
+ * XXX DO NOT USE. This is a temporary stub function.
6106
+ * XXX It WILL be removed in the next major release.
6107
+ */
6108
+ function destroy() {
6109
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
6110
+ }
6111
+
6112
+ createDebug.enable(createDebug.load());
6113
+
6114
+ return createDebug;
6115
+ }
6116
+
6117
+ var common = setup;
6118
+
6119
+ /* eslint-env browser */
6120
+
6121
+ (function (module, exports) {
6122
+ /**
6123
+ * This is the web browser implementation of `debug()`.
6124
+ */
6125
+
6126
+ exports.formatArgs = formatArgs;
6127
+ exports.save = save;
6128
+ exports.load = load;
6129
+ exports.useColors = useColors;
6130
+ exports.storage = localstorage();
6131
+ exports.destroy = (() => {
6132
+ let warned = false;
6133
+
6134
+ return () => {
6135
+ if (!warned) {
6136
+ warned = true;
6137
+ console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
6138
+ }
6139
+ };
6140
+ })();
6141
+
6142
+ /**
6143
+ * Colors.
6144
+ */
6145
+
6146
+ exports.colors = [
6147
+ '#0000CC',
6148
+ '#0000FF',
6149
+ '#0033CC',
6150
+ '#0033FF',
6151
+ '#0066CC',
6152
+ '#0066FF',
6153
+ '#0099CC',
6154
+ '#0099FF',
6155
+ '#00CC00',
6156
+ '#00CC33',
6157
+ '#00CC66',
6158
+ '#00CC99',
6159
+ '#00CCCC',
6160
+ '#00CCFF',
6161
+ '#3300CC',
6162
+ '#3300FF',
6163
+ '#3333CC',
6164
+ '#3333FF',
6165
+ '#3366CC',
6166
+ '#3366FF',
6167
+ '#3399CC',
6168
+ '#3399FF',
6169
+ '#33CC00',
6170
+ '#33CC33',
6171
+ '#33CC66',
6172
+ '#33CC99',
6173
+ '#33CCCC',
6174
+ '#33CCFF',
6175
+ '#6600CC',
6176
+ '#6600FF',
6177
+ '#6633CC',
6178
+ '#6633FF',
6179
+ '#66CC00',
6180
+ '#66CC33',
6181
+ '#9900CC',
6182
+ '#9900FF',
6183
+ '#9933CC',
6184
+ '#9933FF',
6185
+ '#99CC00',
6186
+ '#99CC33',
6187
+ '#CC0000',
6188
+ '#CC0033',
6189
+ '#CC0066',
6190
+ '#CC0099',
6191
+ '#CC00CC',
6192
+ '#CC00FF',
6193
+ '#CC3300',
6194
+ '#CC3333',
6195
+ '#CC3366',
6196
+ '#CC3399',
6197
+ '#CC33CC',
6198
+ '#CC33FF',
6199
+ '#CC6600',
6200
+ '#CC6633',
6201
+ '#CC9900',
6202
+ '#CC9933',
6203
+ '#CCCC00',
6204
+ '#CCCC33',
6205
+ '#FF0000',
6206
+ '#FF0033',
6207
+ '#FF0066',
6208
+ '#FF0099',
6209
+ '#FF00CC',
6210
+ '#FF00FF',
6211
+ '#FF3300',
6212
+ '#FF3333',
6213
+ '#FF3366',
6214
+ '#FF3399',
6215
+ '#FF33CC',
6216
+ '#FF33FF',
6217
+ '#FF6600',
6218
+ '#FF6633',
6219
+ '#FF9900',
6220
+ '#FF9933',
6221
+ '#FFCC00',
6222
+ '#FFCC33'
6223
+ ];
6224
+
6225
+ /**
6226
+ * Currently only WebKit-based Web Inspectors, Firefox >= v31,
6227
+ * and the Firebug extension (any Firefox version) are known
6228
+ * to support "%c" CSS customizations.
6229
+ *
6230
+ * TODO: add a `localStorage` variable to explicitly enable/disable colors
6231
+ */
6232
+
6233
+ // eslint-disable-next-line complexity
6234
+ function useColors() {
6235
+ // NB: In an Electron preload script, document will be defined but not fully
6236
+ // initialized. Since we know we're in Chrome, we'll just detect this case
6237
+ // explicitly
6238
+ if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
6239
+ return true;
6240
+ }
6241
+
6242
+ // Internet Explorer and Edge do not support colors.
6243
+ if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
6244
+ return false;
6245
+ }
6246
+
6247
+ // Is webkit? http://stackoverflow.com/a/16459606/376773
6248
+ // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
6249
+ return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
6250
+ // Is firebug? http://stackoverflow.com/a/398120/376773
6251
+ (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
6252
+ // Is firefox >= v31?
6253
+ // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
6254
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
6255
+ // Double check webkit in userAgent just in case we are in a worker
6256
+ (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
6257
+ }
6258
+
6259
+ /**
6260
+ * Colorize log arguments if enabled.
6261
+ *
6262
+ * @api public
6263
+ */
6264
+
6265
+ function formatArgs(args) {
6266
+ args[0] = (this.useColors ? '%c' : '') +
6267
+ this.namespace +
6268
+ (this.useColors ? ' %c' : ' ') +
6269
+ args[0] +
6270
+ (this.useColors ? '%c ' : ' ') +
6271
+ '+' + module.exports.humanize(this.diff);
6272
+
6273
+ if (!this.useColors) {
6274
+ return;
6275
+ }
6276
+
6277
+ const c = 'color: ' + this.color;
6278
+ args.splice(1, 0, c, 'color: inherit');
6279
+
6280
+ // The final "%c" is somewhat tricky, because there could be other
6281
+ // arguments passed either before or after the %c, so we need to
6282
+ // figure out the correct index to insert the CSS into
6283
+ let index = 0;
6284
+ let lastC = 0;
6285
+ args[0].replace(/%[a-zA-Z%]/g, match => {
6286
+ if (match === '%%') {
6287
+ return;
6288
+ }
6289
+ index++;
6290
+ if (match === '%c') {
6291
+ // We only are interested in the *last* %c
6292
+ // (the user may have provided their own)
6293
+ lastC = index;
6294
+ }
6295
+ });
6296
+
6297
+ args.splice(lastC, 0, c);
6298
+ }
6299
+
6300
+ /**
6301
+ * Invokes `console.debug()` when available.
6302
+ * No-op when `console.debug` is not a "function".
6303
+ * If `console.debug` is not available, falls back
6304
+ * to `console.log`.
6305
+ *
6306
+ * @api public
6307
+ */
6308
+ exports.log = console.debug || console.log || (() => {});
6309
+
6310
+ /**
6311
+ * Save `namespaces`.
6312
+ *
6313
+ * @param {String} namespaces
6314
+ * @api private
6315
+ */
6316
+ function save(namespaces) {
6317
+ try {
6318
+ if (namespaces) {
6319
+ exports.storage.setItem('debug', namespaces);
6320
+ } else {
6321
+ exports.storage.removeItem('debug');
6322
+ }
6323
+ } catch (error) {
6324
+ // Swallow
6325
+ // XXX (@Qix-) should we be logging these?
6326
+ }
6327
+ }
6328
+
6329
+ /**
6330
+ * Load `namespaces`.
6331
+ *
6332
+ * @return {String} returns the previously persisted debug modes
6333
+ * @api private
6334
+ */
6335
+ function load() {
6336
+ let r;
6337
+ try {
6338
+ r = exports.storage.getItem('debug');
6339
+ } catch (error) {
6340
+ // Swallow
6341
+ // XXX (@Qix-) should we be logging these?
6342
+ }
6343
+
6344
+ // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
6345
+ if (!r && typeof process !== 'undefined' && 'env' in process) {
6346
+ r = process.env.DEBUG;
6347
+ }
6348
+
6349
+ return r;
6350
+ }
6351
+
6352
+ /**
6353
+ * Localstorage attempts to return the localstorage.
6354
+ *
6355
+ * This is necessary because safari throws
6356
+ * when a user disables cookies/localstorage
6357
+ * and you attempt to access it.
6358
+ *
6359
+ * @return {LocalStorage}
6360
+ * @api private
6361
+ */
6362
+
6363
+ function localstorage() {
6364
+ try {
6365
+ // TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
6366
+ // The Browser also has localStorage in the global context.
6367
+ return localStorage;
6368
+ } catch (error) {
6369
+ // Swallow
6370
+ // XXX (@Qix-) should we be logging these?
6371
+ }
6372
+ }
6373
+
6374
+ module.exports = common(exports);
6375
+
6376
+ const {formatters} = module.exports;
6377
+
6378
+ /**
6379
+ * Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
6380
+ */
6381
+
6382
+ formatters.j = function (v) {
6383
+ try {
6384
+ return JSON.stringify(v);
6385
+ } catch (error) {
6386
+ return '[UnexpectedJSONParseError]: ' + error.message;
6387
+ }
6388
+ };
6389
+ } (browser, browser.exports));
6390
+
6391
+ var browserExports = browser.exports;
6392
+ var createDebug = /*@__PURE__*/getDefaultExportFromCjs(browserExports);
6393
+
6394
+ createDebug("foxglove:server");
6395
+ new TextEncoder();
6396
+ ({
6397
+ subscribe: undefined,
6398
+ unsubscribe: undefined,
6399
+ advertise: ServerCapability.clientPublish,
6400
+ unadvertise: ServerCapability.clientPublish,
6401
+ [ClientBinaryOpcode.MESSAGE_DATA]: ServerCapability.clientPublish,
6402
+ getParameters: ServerCapability.parameters,
6403
+ setParameters: ServerCapability.parameters,
6404
+ subscribeParameterUpdates: ServerCapability.parametersSubscribe,
6405
+ unsubscribeParameterUpdates: ServerCapability.parametersSubscribe,
6406
+ [ClientBinaryOpcode.SERVICE_CALL_REQUEST]: ServerCapability.services,
6407
+ subscribeConnectionGraph: ServerCapability.connectionGraph,
6408
+ unsubscribeConnectionGraph: ServerCapability.connectionGraph,
6409
+ fetchAsset: ServerCapability.assets,
6410
+ });
6411
+
6412
+ function recordToDataView(record) {
6413
+ const text = JSON.stringify(record);
6414
+ if (!text) {
6415
+ throw new Error("Invalid record");
6416
+ }
6417
+ const encoder = new TextEncoder();
6418
+ const data = encoder.encode(text);
6419
+ const dataView = new DataView(data.buffer);
6420
+ return dataView;
6421
+ }
6422
+
6423
+ class WsWorker {
6424
+ #ws;
6425
+ #client;
6426
+ subscriptions = new Map();
6427
+ services = new Map();
6428
+ serviceCalls = new Map();
6429
+ createWs(url, onReconnect) {
6430
+ this.#ws = new Waterfall(url, FoxgloveClient.SUPPORTED_SUBPROTOCOL, {
6431
+ connectionTimeout: 2000,
6432
+ retryPolicy: _attempt => {
6433
+ onReconnect();
6434
+ return 1_000;
6435
+ },
6436
+ factory: url => {
6437
+ const rawWs = new WebSocket(url, FoxgloveClient.SUPPORTED_SUBPROTOCOL);
6438
+ rawWs.binaryType = "arraybuffer";
6439
+ return rawWs;
6440
+ }
6441
+ });
6442
+ }
6443
+ createClient() {
6444
+ this.#client = new FoxgloveClient({
6445
+ ws: this.#ws
6446
+ });
6447
+ this.#client.on("open", () => this.send({
6448
+ type: "open"
6449
+ }));
6450
+ this.#client.on("close", () => this.send({
6451
+ type: "close"
6452
+ }));
6453
+ this.#client.on("error", error => this.send({
6454
+ type: "error",
6455
+ error
6456
+ }));
6457
+ this.#client.on("message", ({
6458
+ subscriptionId,
6459
+ data
6460
+ }) => {
6461
+ const subscription = this.subscriptions.get(subscriptionId);
6462
+ if (subscription) {
6463
+ this.sendWithTransfer({
6464
+ type: "message",
6465
+ data: {
6466
+ ...subscription,
6467
+ buffer: data
6468
+ }
6469
+ }, [data.buffer]);
6470
+ }
6471
+ });
6472
+ }
6473
+ getPublicChannels() {
6474
+ return [...this.subscriptions.values()].map(({
6475
+ kind,
6476
+ topic
6477
+ }) => ({
6478
+ kind,
6479
+ topic
6480
+ }));
6481
+ }
6482
+ getPublicServices() {
6483
+ return [...this.services.values()].map(service => service.name);
6484
+ }
6485
+ handleAdvertisements() {
6486
+ this.#client.on("advertise", channels => {
6487
+ const data = this.getPublicChannels();
6488
+ for (const channel of channels) {
6489
+ const subscriptionId = this.#client.subscribe(channel.id);
6490
+ const kind = protobufsBySchema[channel.schemaName]?.kind ?? 'annotations';
6491
+ this.subscriptions.set(subscriptionId, {
6492
+ topic: channel.topic,
6493
+ schema: channel.schemaName,
6494
+ kind
6495
+ });
6496
+ data.push({
6497
+ topic: channel.topic,
6498
+ kind
6499
+ });
6500
+ }
6501
+ this.send({
6502
+ type: "channels",
6503
+ data
6504
+ });
6505
+ });
6506
+ this.#client.on("unadvertise", channels => {
6507
+ for (const channel of channels) {
6508
+ this.subscriptions.delete(channel);
6509
+ }
6510
+ const data = this.getPublicChannels();
6511
+ this.send({
6512
+ type: "channels",
6513
+ data
6514
+ });
6515
+ });
6516
+ this.#client.on("advertiseServices", advertisedServices => {
6517
+ const data = this.getPublicServices();
6518
+ for (const service of advertisedServices) {
6519
+ this.services.set(service.name, service);
6520
+ data.push(service.name);
6521
+ }
6522
+ this.send({
6523
+ type: "services",
6524
+ data
6525
+ });
6526
+ });
6527
+ this.#client.on("unadvertiseServices", unadvertisedServices => {
6528
+ for (const unadvertisedService of unadvertisedServices) {
6529
+ for (const [name, service] of this.services) {
6530
+ if (service.id === unadvertisedService) {
6531
+ this.services.delete(name);
6532
+ }
6533
+ }
6534
+ }
6535
+ const data = this.getPublicServices();
6536
+ this.send({
6537
+ type: "services",
6538
+ data
6539
+ });
6540
+ });
6541
+ }
6542
+ handleServiceResponses() {
6543
+ this.#client.on("serviceCallResponse", event => {
6544
+ const name = this.serviceCalls.get(event.callId) ?? 'unknown';
6545
+ this.serviceCalls.delete(event.callId);
6546
+ this.sendWithTransfer({
6547
+ type: "service_response",
6548
+ data: {
6549
+ name,
6550
+ ok: true,
6551
+ serviceCallId: event.callId,
6552
+ buffer: event.data,
6553
+ error: null
6554
+ }
6555
+ }, [event.data.buffer]);
6556
+ });
6557
+ }
6558
+ constructor(wsUrl, send, sendWithTransfer) {
6559
+ this.send = send;
6560
+ this.sendWithTransfer = sendWithTransfer;
6561
+ const onReconnect = () => {
6562
+ this.services.clear();
6563
+ this.subscriptions.clear();
6564
+ send({
6565
+ type: "reconnect"
6566
+ });
6567
+ };
6568
+ try {
6569
+ this.createWs(wsUrl, onReconnect);
6570
+ this.createClient();
6571
+ this.handleAdvertisements();
6572
+ this.handleServiceResponses();
6573
+ } catch (error) {
6574
+ // try-catch is needed to catch `Mixed Content` errors in Chrome, where the client
6575
+ // attempts to load `ws://` from `https://`. (Safari would catch these in `ws.onerror`
6576
+ // but with `undefined` as an error.)
6577
+ send({
6578
+ type: "error",
6579
+ error: error ?? {
6580
+ message: "Insecure WebSocket connection"
6581
+ }
6582
+ });
6583
+ }
6584
+ }
6585
+ rawSend(data) {
6586
+ if (this.#ws.readyState === this.#ws.OPEN) {
6587
+ this.#ws.send(data);
6588
+ }
6589
+ }
6590
+ close() {
6591
+ this.#client.close();
6592
+ }
6593
+ callService({
6594
+ name,
6595
+ serviceCallId,
6596
+ body = {}
6597
+ }) {
6598
+ const service = this.services.get(name);
6599
+ if (!service) {
6600
+ this.send({
6601
+ type: "service_response",
6602
+ data: {
6603
+ name,
6604
+ serviceCallId,
6605
+ ok: false,
6606
+ error: "Service was not advertised",
6607
+ buffer: null
6608
+ }
6609
+ });
6610
+ return;
6611
+ }
6612
+ if (this.#ws.readyState === this.#ws.OPEN) {
6613
+ this.serviceCalls.set(serviceCallId, name);
6614
+ this.#client.sendServiceCallRequest({
6615
+ serviceId: service.id,
6616
+ callId: serviceCallId,
6617
+ encoding: "json",
6618
+ data: recordToDataView(body)
6619
+ });
6620
+ }
6621
+ }
6622
+ }
6623
+ function createWsWorkerMessageListener(send, sendWithTransfer) {
6624
+ let wsWorker = null;
6625
+ return async event => {
6626
+ const {
6627
+ type,
6628
+ data
6629
+ } = event.data;
6630
+ switch (type) {
6631
+ case "open":
6632
+ wsWorker = new WsWorker(data.wsUrl, send, sendWithTransfer);
6633
+ break;
6634
+ case "close":
6635
+ wsWorker?.close();
6636
+ break;
6637
+ case "send":
6638
+ wsWorker?.rawSend(data);
6639
+ break;
6640
+ case "call_service":
6641
+ wsWorker?.callService(data);
6642
+ break;
6643
+ }
6644
+ };
6645
+ }
6646
+
6647
+ export { EventEmitter as E, PointsAnnotationType as P, Type as T, getDefaultExportFromCjs as a, Profile as b, commonjsGlobal as c, createWsWorkerMessageListener as d, getAugmentedNamespace as g, protobufsBySchema as p };