@hcikn/colibri 1.1.1 → 1.3.2

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/index.js CHANGED
@@ -1,4 +1,3 @@
1
- // src/Networking.ts
2
1
  function _array_like_to_array(arr, len) {
3
2
  if (len == null || len > arr.length) len = arr.length;
4
3
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -7,6 +6,45 @@ function _array_like_to_array(arr, len) {
7
6
  function _array_without_holes(arr) {
8
7
  if (Array.isArray(arr)) return _array_like_to_array(arr);
9
8
  }
9
+ function _assert_this_initialized(self) {
10
+ if (self === void 0) {
11
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
12
+ }
13
+ return self;
14
+ }
15
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
16
+ try {
17
+ var info = gen[key](arg);
18
+ var value = info.value;
19
+ } catch (error) {
20
+ reject(error);
21
+ return;
22
+ }
23
+ if (info.done) {
24
+ resolve(value);
25
+ } else {
26
+ Promise.resolve(value).then(_next, _throw);
27
+ }
28
+ }
29
+ function _async_to_generator(fn) {
30
+ return function() {
31
+ var self = this, args = arguments;
32
+ return new Promise(function(resolve, reject) {
33
+ var gen = fn.apply(self, args);
34
+ function _next(value) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
36
+ }
37
+ function _throw(err) {
38
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
39
+ }
40
+ _next(undefined);
41
+ });
42
+ };
43
+ }
44
+ function _call_super(_this, derived, args) {
45
+ derived = _get_prototype_of(derived);
46
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
47
+ }
10
48
  function _class_call_check(instance, Constructor) {
11
49
  if (!(instance instanceof Constructor)) {
12
50
  throw new TypeError("Cannot call a class as a function");
@@ -26,7 +64,27 @@ function _create_class(Constructor, protoProps, staticProps) {
26
64
  if (staticProps) _defineProperties(Constructor, staticProps);
27
65
  return Constructor;
28
66
  }
67
+ function _get_prototype_of(o) {
68
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
69
+ return o.__proto__ || Object.getPrototypeOf(o);
70
+ };
71
+ return _get_prototype_of(o);
72
+ }
73
+ function _inherits(subClass, superClass) {
74
+ if (typeof superClass !== "function" && superClass !== null) {
75
+ throw new TypeError("Super expression must either be null or a function");
76
+ }
77
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
78
+ constructor: {
79
+ value: subClass,
80
+ writable: true,
81
+ configurable: true
82
+ }
83
+ });
84
+ if (superClass) _set_prototype_of(subClass, superClass);
85
+ }
29
86
  function _instanceof(left, right) {
87
+ "@swc/helpers - instanceof";
30
88
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
31
89
  return !!right[Symbol.hasInstance](left);
32
90
  } else {
@@ -39,9 +97,26 @@ function _iterable_to_array(iter) {
39
97
  function _non_iterable_spread() {
40
98
  throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
41
99
  }
100
+ function _possible_constructor_return(self, call) {
101
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
102
+ return call;
103
+ }
104
+ return _assert_this_initialized(self);
105
+ }
106
+ function _set_prototype_of(o, p) {
107
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
108
+ o.__proto__ = p;
109
+ return o;
110
+ };
111
+ return _set_prototype_of(o, p);
112
+ }
42
113
  function _to_consumable_array(arr) {
43
114
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
44
115
  }
116
+ function _type_of(obj) {
117
+ "@swc/helpers - typeof";
118
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
119
+ }
45
120
  function _unsupported_iterable_to_array(o, minLen) {
46
121
  if (!o) return;
47
122
  if (typeof o === "string") return _array_like_to_array(o, minLen);
@@ -50,97 +125,423 @@ function _unsupported_iterable_to_array(o, minLen) {
50
125
  if (n === "Map" || n === "Set") return Array.from(n);
51
126
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
52
127
  }
53
- import { Subject } from "rxjs";
54
- import * as io from "socket.io-client";
55
- var messageSubject = new Subject();
56
- var Messages = messageSubject.asObservable();
57
- var location = "";
58
- if (typeof window !== "undefined") {
59
- location = window.location.hostname || "";
128
+ function _is_native_reflect_construct() {
129
+ try {
130
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
131
+ } catch (_) {}
132
+ return (_is_native_reflect_construct = function() {
133
+ return !!result;
134
+ })();
60
135
  }
61
- var socket = io.connect({
62
- autoConnect: false
63
- });
64
- var init = function(app, server, port) {
65
- server !== null && server !== void 0 ? server : server = location;
66
- port !== null && port !== void 0 ? port : port = 9011;
67
- if (!server.startsWith("http")) {
68
- server = "http://" + server;
136
+ function _ts_generator(thisArg, body) {
137
+ var f, y, t, _ = {
138
+ label: 0,
139
+ sent: function() {
140
+ if (t[0] & 1) throw t[1];
141
+ return t[1];
142
+ },
143
+ trys: [],
144
+ ops: []
145
+ }, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
146
+ return d(g, "next", {
147
+ value: verb(0)
148
+ }), d(g, "throw", {
149
+ value: verb(1)
150
+ }), d(g, "return", {
151
+ value: verb(2)
152
+ }), typeof Symbol === "function" && d(g, Symbol.iterator, {
153
+ value: function() {
154
+ return this;
155
+ }
156
+ }), g;
157
+ function verb(n) {
158
+ return function(v) {
159
+ return step([
160
+ n,
161
+ v
162
+ ]);
163
+ };
69
164
  }
70
- server += ":".concat(port);
71
- socket.io.uri = server;
72
- socket.io.opts.query = {
73
- app: app,
74
- version: "1"
75
- };
76
- socket.connect();
77
- console.debug("Connecting to colibri server on ".concat(server));
78
- socket.on("connect", function() {
79
- console.debug("Connected to colibri server on ".concat(server));
80
- });
81
- socket.onAny(function(channel, msg) {
82
- messageSubject.next({
83
- channel: channel,
84
- command: msg.command,
85
- payload: msg.payload
165
+ function step(op) {
166
+ if (f) throw new TypeError("Generator is already executing.");
167
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
168
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
169
+ if (y = 0, t) op = [
170
+ op[0] & 2,
171
+ t.value
172
+ ];
173
+ switch(op[0]){
174
+ case 0:
175
+ case 1:
176
+ t = op;
177
+ break;
178
+ case 4:
179
+ _.label++;
180
+ return {
181
+ value: op[1],
182
+ done: false
183
+ };
184
+ case 5:
185
+ _.label++;
186
+ y = op[1];
187
+ op = [
188
+ 0
189
+ ];
190
+ continue;
191
+ case 7:
192
+ op = _.ops.pop();
193
+ _.trys.pop();
194
+ continue;
195
+ default:
196
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
197
+ _ = 0;
198
+ continue;
199
+ }
200
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
201
+ _.label = op[1];
202
+ break;
203
+ }
204
+ if (op[0] === 6 && _.label < t[1]) {
205
+ _.label = t[1];
206
+ t = op;
207
+ break;
208
+ }
209
+ if (t && _.label < t[2]) {
210
+ _.label = t[2];
211
+ _.ops.push(op);
212
+ break;
213
+ }
214
+ if (t[2]) _.ops.pop();
215
+ _.trys.pop();
216
+ continue;
217
+ }
218
+ op = body.call(thisArg, _);
219
+ } catch (e) {
220
+ op = [
221
+ 6,
222
+ e
223
+ ];
224
+ y = 0;
225
+ } finally{
226
+ f = t = 0;
227
+ }
228
+ if (op[0] & 5) throw op[1];
229
+ return {
230
+ value: op[0] ? op[1] : void 0,
231
+ done: true
232
+ };
233
+ }
234
+ }
235
+ // src/Colibri.ts
236
+ import { connect } from "socket.io-client";
237
+ // src/ColibriError.ts
238
+ import { CustomError } from "ts-custom-error";
239
+ var ColibriError = /*#__PURE__*/ function(CustomError) {
240
+ "use strict";
241
+ _inherits(ColibriError, CustomError);
242
+ function ColibriError(message) {
243
+ _class_call_check(this, ColibriError);
244
+ return _call_super(this, ColibriError, [
245
+ message
246
+ ]);
247
+ }
248
+ return ColibriError;
249
+ }(CustomError);
250
+ // src/Colibri.ts
251
+ import { Subject } from "rxjs";
252
+ var _Colibri = /*#__PURE__*/ function() {
253
+ "use strict";
254
+ function _Colibri(app) {
255
+ var server = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() {
256
+ var _ref;
257
+ var _window_location, _window;
258
+ return (_ref = (_window = window) === null || _window === void 0 ? void 0 : (_window_location = _window.location) === null || _window_location === void 0 ? void 0 : _window_location.hostname) !== null && _ref !== void 0 ? _ref : "";
259
+ }(), port = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 9011;
260
+ _class_call_check(this, _Colibri);
261
+ this.app = app;
262
+ this.server = server;
263
+ this.port = port;
264
+ this.messageSubject = new Subject();
265
+ this.messages = this.messageSubject.asObservable();
266
+ if (server.trim().length <= 0) {
267
+ throw new ColibriError("Server Address missing or empty!");
268
+ }
269
+ if (port < 1 || port > 65535) {
270
+ throw new ColibriError("Port out of allowed range (0 - 65535)");
271
+ }
272
+ this.uri = "".concat(server, ":").concat(port);
273
+ if (!new RegExp("wss?://", "i").test(this.uri)) {
274
+ this.uri = "ws://".concat(this.uri);
275
+ }
276
+ this.uriRestApi = "".concat(this.uri, "/api/store/").concat(app, "/");
277
+ if (_Colibri.instance) throw new ColibriError("A Colibri instance already exists!");
278
+ else _Colibri.instance = this;
279
+ this.socket = connect(this.uri, {
280
+ query: {
281
+ app: app,
282
+ version: "1"
283
+ },
284
+ transports: [
285
+ "websocket"
286
+ ]
86
287
  });
87
- });
288
+ this.socket.on("connect", this.onSocketConnect.bind(this));
289
+ this.socket.onAny(this.onSocketAny.bind(this));
290
+ this.registerChannel("colibri", function(msg) {
291
+ if (msg.command === "latency") {
292
+ SendMessage("colibri", "latency", msg.payload);
293
+ }
294
+ });
295
+ }
296
+ _create_class(_Colibri, [
297
+ {
298
+ key: "onSocketConnect",
299
+ value: function onSocketConnect() {
300
+ console.debug("Connected to colibri server on ".concat(this.server));
301
+ }
302
+ },
303
+ {
304
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
305
+ key: "onSocketAny",
306
+ value: function onSocketAny(channel, msg) {
307
+ this.messageSubject.next({
308
+ channel: channel,
309
+ command: msg.command,
310
+ payload: msg.payload
311
+ });
312
+ }
313
+ },
314
+ {
315
+ /**
316
+ * Sends a single message in the given `channel`.
317
+ * @param channel message channel
318
+ * @param command message command
319
+ * @param payload message payload
320
+ */ key: "sendMessage",
321
+ value: function sendMessage(channel, command) {
322
+ var payload = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
323
+ this.socket.emit(channel, {
324
+ command: command,
325
+ payload: payload
326
+ });
327
+ }
328
+ },
329
+ {
330
+ //#region Socket Events
331
+ /**
332
+ * Adds a `handler` function listening for messages in `channel`.
333
+ * @param channel message channel
334
+ * @param handler handler to be executed when a message is received
335
+ */ key: "registerChannel",
336
+ value: function registerChannel(channel, handler) {
337
+ this.socket.on(channel, handler);
338
+ }
339
+ },
340
+ {
341
+ /**
342
+ * Removes the `handler` function listening for messages in `channel`.
343
+ * @param channel message channel
344
+ * @param handler handler to be executed when a message is received
345
+ */ key: "unregisterChannel",
346
+ value: function unregisterChannel(channel, handler) {
347
+ this.socket.off(channel, handler);
348
+ }
349
+ },
350
+ {
351
+ /**
352
+ * Adds a one-time `handler` function listening for the next message in `channel`.
353
+ * @param channel message channel
354
+ * @param handler handler to be executed when a message is received
355
+ */ key: "registerOnce",
356
+ value: function registerOnce(channel, handler) {
357
+ this.socket.once(channel, handler);
358
+ }
359
+ },
360
+ {
361
+ //#endregion
362
+ //#region Rest API
363
+ /**
364
+ * Returns the REST API Endpoint for a given `key` or null of the key is empty.
365
+ * @param key REST API storage key
366
+ * @returns
367
+ */ key: "getRestUri",
368
+ value: function getRestUri(key) {
369
+ key = key.trim();
370
+ while(key.startsWith("/"))key = key.substring(1);
371
+ return key.length === 0 ? null : this.uriRestApi + key;
372
+ }
373
+ },
374
+ {
375
+ key: "getRestObject",
376
+ value: /**
377
+ * Queries an object from the REST API identified by `key`.
378
+ * @param key REST API storage key
379
+ * @returns JSON object with data or null if object does not exist or any other error occurrs
380
+ */ // eslint-disable-next-line @typescript-eslint/no-explicit-any
381
+ function getRestObject(key) {
382
+ return _async_to_generator(function() {
383
+ var uri, response;
384
+ return _ts_generator(this, function(_state) {
385
+ switch(_state.label){
386
+ case 0:
387
+ uri = this.getRestUri(key);
388
+ if (!uri) return [
389
+ 2,
390
+ null
391
+ ];
392
+ return [
393
+ 4,
394
+ fetch(uri, {
395
+ method: "GET",
396
+ headers: {
397
+ "Content-Type": "application/json"
398
+ }
399
+ })
400
+ ];
401
+ case 1:
402
+ response = _state.sent();
403
+ if (response.status >= 400) return [
404
+ 2,
405
+ null
406
+ ];
407
+ else return [
408
+ 2,
409
+ response.json()
410
+ ];
411
+ return [
412
+ 2
413
+ ];
414
+ }
415
+ });
416
+ }).call(this);
417
+ }
418
+ },
419
+ {
420
+ key: "setRestObject",
421
+ value: /**
422
+ * Sets or updatees an object in the REST API identified by `key`.
423
+ * @param key REST API storage key
424
+ * @param data JSON data to write
425
+ * @returns true if data was written to REST API
426
+ */ function setRestObject(key, data) {
427
+ return _async_to_generator(function() {
428
+ var uri, response;
429
+ return _ts_generator(this, function(_state) {
430
+ switch(_state.label){
431
+ case 0:
432
+ uri = this.getRestUri(key);
433
+ if (!uri) return [
434
+ 2,
435
+ false
436
+ ];
437
+ return [
438
+ 4,
439
+ fetch(uri, {
440
+ method: "PUT",
441
+ headers: {
442
+ "Content-Type": "application/json"
443
+ },
444
+ body: JSON.stringify(data)
445
+ })
446
+ ];
447
+ case 1:
448
+ response = _state.sent();
449
+ return [
450
+ 2,
451
+ response.status >= 200 && response.status < 300
452
+ ];
453
+ }
454
+ });
455
+ }).call(this);
456
+ }
457
+ }
458
+ ], [
459
+ {
460
+ key: "getInstance",
461
+ value: /**
462
+ * Returns the existing Colibri instance or null if there's none yet
463
+ * @param warnIfNotInitialized true => print Log message if Colibri has not been initialized yet
464
+ * @returns
465
+ */ function getInstance() {
466
+ var warnIfNotInitialized = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
467
+ if (warnIfNotInitialized && !_Colibri.instance) {
468
+ console.warn("Colibri not initialized yet! (Instance is null)");
469
+ }
470
+ return _Colibri.instance;
471
+ }
472
+ }
473
+ ]);
474
+ return _Colibri;
475
+ }();
476
+ _Colibri.instance = null;
477
+ var Colibri = _Colibri;
478
+ var SendMessage = function SendMessage(channel, command) {
479
+ var payload = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
480
+ var _Colibri_getInstance;
481
+ return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.sendMessage(channel, command, payload);
88
482
  };
89
- var Colibri = {
90
- init: init
483
+ var RegisterChannel = function RegisterChannel(channel, handler) {
484
+ var _Colibri_getInstance;
485
+ return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.registerChannel(channel, handler);
91
486
  };
92
- var SendMessage = function(channel, command) {
93
- var payload = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
94
- socket.emit(channel, {
95
- command: command,
96
- payload: payload
97
- });
487
+ var UnregisterChannel = function UnregisterChannel(channel, handler) {
488
+ var _Colibri_getInstance;
489
+ return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.unregisterChannel(channel, handler);
98
490
  };
99
- var RegisterChannel = function(channel, handler) {
100
- socket.on(channel, handler);
491
+ var RegisterOnce = function RegisterOnce(channel, handler) {
492
+ var _Colibri_getInstance;
493
+ return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.registerOnce(channel, handler);
494
+ };
495
+ var GetRestApi = function GetRestApi(key) {
496
+ var _Colibri_getInstance;
497
+ return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.getRestObject(key);
498
+ };
499
+ var PutRestApi = function PutRestApi(key, data) {
500
+ var _Colibri_getInstance;
501
+ return (_Colibri_getInstance = Colibri.getInstance()) === null || _Colibri_getInstance === void 0 ? void 0 : _Colibri_getInstance.setRestObject(key, data);
101
502
  };
102
503
  // src/Broadcasting.ts
103
- var sendBool = function(channel, val) {
504
+ var sendBool = function sendBool(channel, val) {
104
505
  SendMessage(channel, "broadcast::bool", val);
105
506
  };
106
- var sendBoolArray = function(channel, val) {
507
+ var sendBoolArray = function sendBoolArray(channel, val) {
107
508
  SendMessage(channel, "broadcast::bool[]", val);
108
509
  };
109
- var sendNumber = function(channel, val) {
510
+ var sendNumber = function sendNumber(channel, val) {
110
511
  SendMessage(channel, "broadcast::float", val);
111
512
  };
112
- var sendNumberArray = function(channel, val) {
513
+ var sendNumberArray = function sendNumberArray(channel, val) {
113
514
  SendMessage(channel, "broadcast::float[]", val);
114
515
  };
115
- var sendString = function(channel, val) {
516
+ var sendString = function sendString(channel, val) {
116
517
  SendMessage(channel, "broadcast::string", val);
117
518
  };
118
- var sendStringArray = function(channel, val) {
519
+ var sendStringArray = function sendStringArray(channel, val) {
119
520
  SendMessage(channel, "broadcast::string[]", val);
120
521
  };
121
- var sendVector3 = function(channel, val) {
522
+ var sendVector3 = function sendVector3(channel, val) {
122
523
  SendMessage(channel, "broadcast::vector3", val);
123
524
  };
124
- var sendVector3Array = function(channel, val) {
525
+ var sendVector3Array = function sendVector3Array(channel, val) {
125
526
  SendMessage(channel, "broadcast::vector3[]", val);
126
527
  };
127
- var sendQuaternion = function(channel, val) {
528
+ var sendQuaternion = function sendQuaternion(channel, val) {
128
529
  SendMessage(channel, "broadcast::quaternion", val);
129
530
  };
130
- var sendQuaternionArray = function(channel, val) {
531
+ var sendQuaternionArray = function sendQuaternionArray(channel, val) {
131
532
  SendMessage(channel, "broadcast::quaternion[]", val);
132
533
  };
133
- var sendColor = function(channel, val) {
534
+ var sendColor = function sendColor(channel, val) {
134
535
  SendMessage(channel, "broadcast::color", val);
135
536
  };
136
- var sendColorArray = function(channel, val) {
537
+ var sendColorArray = function sendColorArray(channel, val) {
137
538
  SendMessage(channel, "broadcast::color[]", val);
138
539
  };
139
- var sendJson = function(channel, val) {
540
+ var sendJson = function sendJson(channel, val) {
140
541
  SendMessage(channel, "broadcast::json", val);
141
542
  };
142
543
  var listeners = {};
143
- var registerListener = function(channel, type, callback) {
544
+ var registerListener = function registerListener(channel, type, callback) {
144
545
  if (listeners[channel] === void 0) {
145
546
  listeners[channel] = {};
146
547
  RegisterChannel(channel, function(msg) {
@@ -156,46 +557,46 @@ var registerListener = function(channel, type, callback) {
156
557
  }
157
558
  listeners[channel][type].push(callback);
158
559
  };
159
- var receiveBool = function(channel, callback) {
560
+ var receiveBool = function receiveBool(channel, callback) {
160
561
  registerListener(channel, "broadcast::bool", callback);
161
562
  };
162
- var receiveBoolArray = function(channel, callback) {
563
+ var receiveBoolArray = function receiveBoolArray(channel, callback) {
163
564
  registerListener(channel, "broadcast::bool[]", callback);
164
565
  };
165
- var receiveNumber = function(channel, callback) {
566
+ var receiveNumber = function receiveNumber(channel, callback) {
166
567
  registerListener(channel, "broadcast::float", callback);
167
568
  };
168
- var receiveNumberArray = function(channel, callback) {
569
+ var receiveNumberArray = function receiveNumberArray(channel, callback) {
169
570
  registerListener(channel, "broadcast::float[]", callback);
170
571
  };
171
- var receiveString = function(channel, callback) {
572
+ var receiveString = function receiveString(channel, callback) {
172
573
  registerListener(channel, "broadcast::string", callback);
173
574
  };
174
- var receiveStringArray = function(channel, callback) {
575
+ var receiveStringArray = function receiveStringArray(channel, callback) {
175
576
  registerListener(channel, "broadcast::string[]", callback);
176
577
  };
177
- var receiveVector3 = function(channel, callback) {
578
+ var receiveVector3 = function receiveVector3(channel, callback) {
178
579
  registerListener(channel, "broadcast::vector3", callback);
179
580
  };
180
- var receiveVector3Array = function(channel, callback) {
581
+ var receiveVector3Array = function receiveVector3Array(channel, callback) {
181
582
  registerListener(channel, "broadcast::vector3[]", callback);
182
583
  };
183
- var receiveQuaternion = function(channel, callback) {
584
+ var receiveQuaternion = function receiveQuaternion(channel, callback) {
184
585
  registerListener(channel, "broadcast::quaternion", callback);
185
586
  };
186
- var receiveQuaternionArray = function(channel, callback) {
587
+ var receiveQuaternionArray = function receiveQuaternionArray(channel, callback) {
187
588
  registerListener(channel, "broadcast::quaternion[]", callback);
188
589
  };
189
- var receiveColor = function(channel, callback) {
590
+ var receiveColor = function receiveColor(channel, callback) {
190
591
  registerListener(channel, "broadcast::color", callback);
191
592
  };
192
- var receiveColorArray = function(channel, callback) {
593
+ var receiveColorArray = function receiveColorArray(channel, callback) {
193
594
  registerListener(channel, "broadcast::color[]", callback);
194
595
  };
195
- var receiveJson = function(channel, callback) {
596
+ var receiveJson = function receiveJson(channel, callback) {
196
597
  registerListener(channel, "broadcast::json", callback);
197
598
  };
198
- var unregister = function(channel, callback) {
599
+ var unregister = function unregister(channel, callback) {
199
600
  for(var command in listeners[channel]){
200
601
  var index = listeners[channel][command].indexOf(callback);
201
602
  if (index >= 0) {
@@ -238,62 +639,107 @@ var Sync = {
238
639
  sendIntArray: sendNumberArray
239
640
  };
240
641
  // src/RemoteLogger.ts
241
- var init2 = function() {
242
- var consoleDebug = console.debug;
243
- var consoleLog = console.log;
244
- var consoleWarn = console.warn;
245
- var consoleError = console.error;
246
- var stringify = function(obj) {
247
- if (_instanceof(obj, Error)) {
248
- return obj.message + "\n" + obj.stack;
249
- }
250
- var cache = [];
251
- var str = JSON.stringify(obj, function(_, value) {
252
- if (typeof value === "object" && value !== null) {
253
- if (cache.indexOf(value) !== -1) {
254
- return;
255
- }
256
- cache.push(value);
642
+ var RemoteLogger = /*#__PURE__*/ function() {
643
+ "use strict";
644
+ function _RemoteLogger() {
645
+ var enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
646
+ var _this = this;
647
+ _class_call_check(this, _RemoteLogger);
648
+ this.enabled = enabled;
649
+ this.consoleDebug = console.debug;
650
+ this.consoleLog = console.log;
651
+ this.consoleInfo = console.info;
652
+ this.consoleWarn = console.warn;
653
+ this.consoleError = console.error;
654
+ console.debug = function() {
655
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
656
+ args[_key] = arguments[_key];
657
+ }
658
+ _this.consoleDebug.apply(_this, _to_consumable_array(args));
659
+ _this.sendMessage("debug", args);
660
+ };
661
+ console.log = function() {
662
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
663
+ args[_key] = arguments[_key];
664
+ }
665
+ _this.consoleLog.apply(_this, _to_consumable_array(args));
666
+ _this.sendMessage("info", args);
667
+ };
668
+ console.info = function() {
669
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
670
+ args[_key] = arguments[_key];
671
+ }
672
+ _this.consoleInfo.apply(_this, _to_consumable_array(args));
673
+ _this.sendMessage("info", args);
674
+ };
675
+ console.warn = function() {
676
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
677
+ args[_key] = arguments[_key];
678
+ }
679
+ _this.consoleWarn.apply(_this, _to_consumable_array(args));
680
+ _this.sendMessage("warn", args);
681
+ };
682
+ console.error = function() {
683
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
684
+ args[_key] = arguments[_key];
685
+ }
686
+ _this.consoleError.apply(_this, _to_consumable_array(args));
687
+ _this.sendMessage("error", args);
688
+ };
689
+ }
690
+ _create_class(_RemoteLogger, [
691
+ {
692
+ key: "sendMessage",
693
+ value: function sendMessage(level, args) {
694
+ if (!this.enabled) return;
695
+ SendMessage("log", level, _to_consumable_array(args).map(stringify).join().trim());
696
+ }
697
+ },
698
+ {
699
+ key: "enable",
700
+ value: function enable() {
701
+ this.enabled = true;
702
+ }
703
+ },
704
+ {
705
+ key: "disable",
706
+ value: function disable() {
707
+ this.enabled = false;
257
708
  }
258
- return value;
259
- }, 2);
260
- return str;
261
- };
262
- console.debug = function init2() {
263
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
264
- args[_key] = arguments[_key];
265
- }
266
- consoleDebug.apply(this, Array.prototype.slice.call(args));
267
- SendMessage("log", "debug", _to_consumable_array(args).map(stringify).join().trim());
268
- };
269
- console.log = function() {
270
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
271
- args[_key] = arguments[_key];
272
709
  }
273
- consoleLog.apply(this, Array.prototype.slice.call(args));
274
- SendMessage("log", "info", _to_consumable_array(args).map(stringify).join().trim());
275
- };
276
- console.warn = function() {
277
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
278
- args[_key] = arguments[_key];
710
+ ], [
711
+ {
712
+ key: "init",
713
+ value: /**
714
+ * @deprecated use new class constructor directly
715
+ */ function init() {
716
+ var enabled = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : true;
717
+ return new _RemoteLogger(enabled);
718
+ }
279
719
  }
280
- consoleWarn.apply(this, Array.prototype.slice.call(args));
281
- SendMessage("log", "warning", _to_consumable_array(args).map(stringify).join().trim());
282
- };
283
- console.error = function() {
284
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
285
- args[_key] = arguments[_key];
720
+ ]);
721
+ return _RemoteLogger;
722
+ }();
723
+ var stringify = function stringify(obj) {
724
+ if (_instanceof(obj, Error)) {
725
+ return obj.message + "\n" + obj.stack;
726
+ }
727
+ if (typeof obj === "string") return obj;
728
+ var cache = [];
729
+ var str = JSON.stringify(obj, function(_, value) {
730
+ if ((typeof value === "undefined" ? "undefined" : _type_of(value)) === "object" && value !== null) {
731
+ if (cache.indexOf(value) !== -1) {
732
+ return;
733
+ }
734
+ cache.push(value);
286
735
  }
287
- consoleError.apply(this, Array.prototype.slice.call(args));
288
- SendMessage("log", "error", _to_consumable_array(args).map(stringify).join().trim());
289
- };
290
- };
291
- var RemoteLogger = {
292
- init: init2
736
+ return value;
737
+ }, 2);
738
+ return str;
293
739
  };
294
740
  // src/ModelSynchronization.ts
295
741
  import { BehaviorSubject } from "rxjs";
296
- var RegisterModelSync = function(registration) {
742
+ var RegisterModelSync = function RegisterModelSync(registration) {
297
743
  var name = registration.name || registration.type.name.toLowerCase();
298
744
  SendMessage(name, "model::request");
299
745
  console.log("Registering model '".concat(name, "'"));
@@ -308,7 +754,7 @@ var RegisterModelSync = function(registration) {
308
754
  }
309
755
  });
310
756
  var models = new BehaviorSubject([]);
311
- var onUpdate = function(modelData) {
757
+ var onUpdate = function onUpdate(modelData) {
312
758
  var model = models.value.find(function(m) {
313
759
  return m.id === modelData.id;
314
760
  });
@@ -330,7 +776,7 @@ var RegisterModelSync = function(registration) {
330
776
  ]));
331
777
  }
332
778
  };
333
- var onDelete = function(id) {
779
+ var onDelete = function onDelete(id) {
334
780
  var model = models.value.find(function(m) {
335
781
  return m.id === id;
336
782
  });
@@ -339,7 +785,7 @@ var RegisterModelSync = function(registration) {
339
785
  return m.id !== id;
340
786
  }));
341
787
  };
342
- var registerModel = function(model) {
788
+ var registerModel = function registerModel(model) {
343
789
  model.modelChanges$.subscribe(function(changes) {
344
790
  if (!model.ignoreNextChange) {
345
791
  SendMessage("".concat(name), "model::update", model.toJson(changes));
@@ -473,9 +919,9 @@ var SyncModel = /*#__PURE__*/ function() {
473
919
  return SyncModel;
474
920
  }();
475
921
  // src/Synced.ts
476
- var Synced = function() {
922
+ var Synced = function Synced() {
477
923
  var syncedName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
478
- return function Synced(target, key, descriptor) {
924
+ return function(target, key, descriptor) {
479
925
  if (!syncedName) syncedName = key.toString();
480
926
  syncedName = syncedName.toLowerCase();
481
927
  if (!_instanceof(target, SyncModel)) {
@@ -487,10 +933,10 @@ var Synced = function() {
487
933
  if (!(descriptor === null || descriptor === void 0 ? void 0 : descriptor.get)) {
488
934
  Reflect.deleteProperty(target, key);
489
935
  Reflect.defineProperty(target, key, {
490
- get: function() {
936
+ get: function get() {
491
937
  return original;
492
938
  },
493
- set: function(newVal) {
939
+ set: function set(newVal) {
494
940
  console.log("Set ".concat(key.toString(), " to ").concat(newVal));
495
941
  original = newVal;
496
942
  },
@@ -516,5 +962,5 @@ var Synced = function() {
516
962
  }
517
963
  };
518
964
  };
519
- export { Colibri, RegisterModelSync, RemoteLogger, Sync, SyncModel, Synced };
965
+ export { Colibri, GetRestApi, PutRestApi, RegisterChannel, RegisterModelSync, RegisterOnce, RemoteLogger, SendMessage, Sync, SyncModel, Synced, UnregisterChannel };
520
966
  //# sourceMappingURL=index.js.map