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