laravel-echo-api-gateway 0.5.1 → 0.5.3

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.
@@ -1,6 +1,10 @@
1
- var LaravelEchoApiGateway = (function (exports) {
1
+ var LaravelEchoApiGateway = (function (exports, axios) {
2
2
  'use strict';
3
3
 
4
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
5
+
6
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
7
+
4
8
  function _classCallCheck(instance, Constructor) {
5
9
  if (!(instance instanceof Constructor)) {
6
10
  throw new TypeError("Cannot call a class as a function");
@@ -128,58 +132,133 @@ var LaravelEchoApiGateway = (function (exports) {
128
132
  };
129
133
  }
130
134
 
131
- class Connector {
132
- /**
133
- * Create a new class instance.
134
- */
135
- constructor(options) {
136
- /**
137
- * Default connector options.
138
- */
139
- this._defaultOptions = {
140
- auth: {
141
- headers: {},
142
- },
143
- authEndpoint: '/broadcasting/auth',
144
- broadcaster: 'pusher',
145
- csrfToken: null,
146
- host: null,
147
- key: null,
148
- namespace: 'App.Events',
149
- };
150
- this.setOptions(options);
151
- this.connect();
152
- }
153
- /**
154
- * Merge the custom options with the defaults.
155
- */
156
- setOptions(options) {
157
- this.options = Object.assign(this._defaultOptions, options);
158
- if (this.csrfToken()) {
159
- this.options.auth.headers['X-CSRF-TOKEN'] = this.csrfToken();
160
- }
161
- return options;
162
- }
163
- /**
164
- * Extract the CSRF token from the page.
165
- */
166
- csrfToken() {
167
- let selector;
168
- if (typeof window !== 'undefined' && window['Laravel'] && window['Laravel'].csrfToken) {
169
- return window['Laravel'].csrfToken;
170
- }
171
- else if (this.options.csrfToken) {
172
- return this.options.csrfToken;
173
- }
174
- else if (typeof document !== 'undefined' &&
175
- typeof document.querySelector === 'function' &&
176
- (selector = document.querySelector('meta[name="csrf-token"]'))) {
177
- return selector.getAttribute('content');
178
- }
179
- return null;
180
- }
135
+ function _unsupportedIterableToArray(o, minLen) {
136
+ if (!o) return;
137
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
138
+ var n = Object.prototype.toString.call(o).slice(8, -1);
139
+ if (n === "Object" && o.constructor) n = o.constructor.name;
140
+ if (n === "Map" || n === "Set") return Array.from(o);
141
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
142
+ }
143
+
144
+ function _arrayLikeToArray(arr, len) {
145
+ if (len == null || len > arr.length) len = arr.length;
146
+
147
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
148
+
149
+ return arr2;
150
+ }
151
+
152
+ function _createForOfIteratorHelper(o, allowArrayLike) {
153
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
154
+
155
+ if (!it) {
156
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
157
+ if (it) o = it;
158
+ var i = 0;
159
+
160
+ var F = function () {};
161
+
162
+ return {
163
+ s: F,
164
+ n: function () {
165
+ if (i >= o.length) return {
166
+ done: true
167
+ };
168
+ return {
169
+ done: false,
170
+ value: o[i++]
171
+ };
172
+ },
173
+ e: function (e) {
174
+ throw e;
175
+ },
176
+ f: F
177
+ };
178
+ }
179
+
180
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
181
+ }
182
+
183
+ var normalCompletion = true,
184
+ didErr = false,
185
+ err;
186
+ return {
187
+ s: function () {
188
+ it = it.call(o);
189
+ },
190
+ n: function () {
191
+ var step = it.next();
192
+ normalCompletion = step.done;
193
+ return step;
194
+ },
195
+ e: function (e) {
196
+ didErr = true;
197
+ err = e;
198
+ },
199
+ f: function () {
200
+ try {
201
+ if (!normalCompletion && it.return != null) it.return();
202
+ } finally {
203
+ if (didErr) throw err;
204
+ }
205
+ }
206
+ };
207
+ }
208
+
209
+ class Connector {
210
+ /**
211
+ * Create a new class instance.
212
+ */
213
+ constructor(options) {
214
+ /**
215
+ * Default connector options.
216
+ */
217
+ this._defaultOptions = {
218
+ auth: {
219
+ headers: {},
220
+ },
221
+ authEndpoint: '/broadcasting/auth',
222
+ broadcaster: 'pusher',
223
+ csrfToken: null,
224
+ host: null,
225
+ key: null,
226
+ namespace: 'App.Events',
227
+ };
228
+ this.setOptions(options);
229
+ this.connect();
230
+ }
231
+ /**
232
+ * Merge the custom options with the defaults.
233
+ */
234
+ setOptions(options) {
235
+ this.options = Object.assign(this._defaultOptions, options);
236
+ if (this.csrfToken()) {
237
+ this.options.auth.headers['X-CSRF-TOKEN'] = this.csrfToken();
238
+ }
239
+ return options;
240
+ }
241
+ /**
242
+ * Extract the CSRF token from the page.
243
+ */
244
+ csrfToken() {
245
+ let selector;
246
+ if (typeof window !== 'undefined' && window['Laravel'] && window['Laravel'].csrfToken) {
247
+ return window['Laravel'].csrfToken;
248
+ }
249
+ else if (this.options.csrfToken) {
250
+ return this.options.csrfToken;
251
+ }
252
+ else if (typeof document !== 'undefined' &&
253
+ typeof document.querySelector === 'function' &&
254
+ (selector = document.querySelector('meta[name="csrf-token"]'))) {
255
+ return selector.getAttribute('content');
256
+ }
257
+ return null;
258
+ }
181
259
  }
182
260
 
261
+ var LOG_PREFIX = '[LE-AG-Websocket]';
183
262
  var Websocket = /*#__PURE__*/function () {
184
263
  function Websocket(options) {
185
264
  _classCallCheck(this, Websocket);
@@ -189,6 +268,7 @@ var LaravelEchoApiGateway = (function (exports) {
189
268
  this.internalListeners = {};
190
269
  this.channelBacklog = [];
191
270
  this.closing = false;
271
+ this.hasConnected = false;
192
272
  this.options = options;
193
273
  this.connect(this.options.host);
194
274
  return this;
@@ -199,10 +279,28 @@ var LaravelEchoApiGateway = (function (exports) {
199
279
  value: function connect(host) {
200
280
  var _this = this;
201
281
 
202
- this.options.debug && console.log('Connecting');
282
+ if (!host) {
283
+ this.options.debug && console.error(LOG_PREFIX + "Cannont connect without host !");
284
+ return;
285
+ }
286
+
287
+ this.options.debug && console.log(LOG_PREFIX + "Trying to connect to ".concat(host, "..."));
203
288
  this.websocket = new WebSocket(host);
204
289
 
290
+ this.websocket.onerror = function () {
291
+ if (!_this.hasConnected) {
292
+ setTimeout(function () {
293
+ _this.socketId = undefined;
294
+
295
+ _this.connect(host);
296
+ }, 3000);
297
+ }
298
+ };
299
+
205
300
  this.websocket.onopen = function () {
301
+ _this.options.debug && console.log(LOG_PREFIX + ' Connected !');
302
+ _this.hasConnected = true;
303
+
206
304
  _this.send({
207
305
  event: 'whoami'
208
306
  });
@@ -213,65 +311,83 @@ var LaravelEchoApiGateway = (function (exports) {
213
311
  _this.send(message);
214
312
 
215
313
  _this.buffer.splice(0, 1);
216
- }
217
- };
314
+ } // Register events only once connected, or they won't be registered if connection failed/lost
218
315
 
219
- this.websocket.onmessage = function (messageEvent) {
220
- var message = _this.parseMessage(messageEvent.data);
221
316
 
222
- if (!message) {
223
- return;
224
- }
317
+ _this.websocket.onmessage = function (messageEvent) {
318
+ var message = _this.parseMessage(messageEvent.data);
225
319
 
226
- if (message.channel) {
227
- _this.options.debug && console.log("Received event ".concat(message.event, " on channel ").concat(message.channel));
320
+ _this.options.debug && console.log(LOG_PREFIX + ' onmessage', messageEvent.data);
228
321
 
229
- if (_this.listeners[message.channel] && _this.listeners[message.channel][message.event]) {
230
- _this.listeners[message.channel][message.event](message.data);
322
+ if (!message) {
323
+ return;
231
324
  }
232
325
 
233
- return;
234
- }
326
+ if (message.channel) {
327
+ _this.options.debug && console.log("".concat(LOG_PREFIX, " Received event ").concat(message.event, " on channel ").concat(message.channel));
235
328
 
236
- if (_this.internalListeners[message.event]) {
237
- _this.internalListeners[message.event](message.data);
238
- }
329
+ if (_this.listeners[message.channel] && _this.listeners[message.channel][message.event]) {
330
+ _this.listeners[message.channel][message.event](message.data);
331
+ }
332
+
333
+ return;
334
+ }
335
+
336
+ if (_this.internalListeners[message.event]) {
337
+ _this.internalListeners[message.event](message.data);
338
+ }
339
+ }; // send ping every 60 seconds to keep connection alive
340
+
341
+
342
+ _this.pingInterval = setInterval(function () {
343
+ if (_this.websocket.readyState === _this.websocket.OPEN) {
344
+ _this.options.debug && console.log(LOG_PREFIX + ' Sending ping');
345
+
346
+ _this.send({
347
+ event: 'ping'
348
+ });
349
+ }
350
+ }, 60 * 1000);
239
351
  };
240
352
 
241
353
  this.websocket.onclose = function () {
242
- if (_this.socketId && !_this.closing || !_this.socketId) {
243
- _this.options.debug && console.info('Connection lost, reconnecting...');
244
- setTimeout(function () {
245
- _this.socketId = undefined;
354
+ _this.options.debug && console.info('Connection closed.');
246
355
 
247
- _this.connect(host);
248
- }, 1000);
356
+ if (_this.closing) {
357
+ return;
249
358
  }
359
+
360
+ _this.hasConnected = false;
361
+ _this.options.debug && console.info('Connection lost, reconnecting...');
362
+ setTimeout(function () {
363
+ _this.socketId = undefined;
364
+
365
+ _this.connect(host);
366
+ }, 1000);
250
367
  };
251
368
 
252
369
  this.on('whoami', function (_ref) {
253
370
  var socketId = _ref.socket_id;
254
371
  _this.socketId = socketId;
255
- _this.options.debug && console.log("just set socketId to ".concat(socketId));
372
+ _this.options.debug && console.log("".concat(LOG_PREFIX, " Just set socketId to ").concat(socketId)); // Handle the backlog and don't empty it, we'll need it if we lose connection
256
373
 
257
- while (_this.channelBacklog.length) {
258
- var channel = _this.channelBacklog[0];
374
+ var channel;
259
375
 
260
- _this.actuallySubscribe(channel);
376
+ var _iterator = _createForOfIteratorHelper(_this.channelBacklog),
377
+ _step;
261
378
 
262
- _this.channelBacklog.splice(0, 1);
263
- }
264
- }); // send ping every 60 seconds to keep connection alive
379
+ try {
380
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
381
+ channel = _step.value;
265
382
 
266
- this.pingInterval = setInterval(function () {
267
- if (_this.websocket.readyState === _this.websocket.OPEN) {
268
- _this.options.debug && console.log('Sending ping');
269
-
270
- _this.send({
271
- event: 'ping'
272
- });
383
+ _this.actuallySubscribe(channel);
384
+ }
385
+ } catch (err) {
386
+ _iterator.e(err);
387
+ } finally {
388
+ _iterator.f();
273
389
  }
274
- }, 60 * 1000);
390
+ });
275
391
  }
276
392
  }, {
277
393
  key: "parseMessage",
@@ -318,6 +434,7 @@ var LaravelEchoApiGateway = (function (exports) {
318
434
  if (this.getSocketId()) {
319
435
  this.actuallySubscribe(channel);
320
436
  } else {
437
+ this.options.debug && console.log("".concat(LOG_PREFIX, " subscribe - push channel backlog for channel ").concat(channel.name));
321
438
  this.channelBacklog.push(channel);
322
439
  }
323
440
  }
@@ -327,19 +444,19 @@ var LaravelEchoApiGateway = (function (exports) {
327
444
  var _this2 = this;
328
445
 
329
446
  if (channel.name.startsWith('private-') || channel.name.startsWith('presence-')) {
330
- this.options.debug && console.log("Sending auth request for channel ".concat(channel.name));
447
+ this.options.debug && console.log("".concat(LOG_PREFIX, " Sending auth request for channel ").concat(channel.name));
331
448
 
332
449
  if (this.options.bearerToken) {
333
450
  this.options.auth.headers['Authorization'] = 'Bearer ' + this.options.bearerToken;
334
451
  }
335
452
 
336
- axios.post(this.options.authEndpoint, {
453
+ axios__default['default'].post(this.options.authEndpoint, {
337
454
  socket_id: this.getSocketId(),
338
455
  channel_name: channel.name
339
456
  }, {
340
457
  headers: this.options.auth.headers || {}
341
458
  }).then(function (response) {
342
- _this2.options.debug && console.log("Subscribing to channels ".concat(channel.name));
459
+ _this2.options.debug && console.log("".concat(LOG_PREFIX, " Subscribing to private channel ").concat(channel.name));
343
460
 
344
461
  _this2.send({
345
462
  event: 'subscribe',
@@ -348,11 +465,11 @@ var LaravelEchoApiGateway = (function (exports) {
348
465
  }, response.data)
349
466
  });
350
467
  })["catch"](function (error) {
351
- _this2.options.debug && console.log("Auth request for channel ".concat(channel.name, " failed"));
468
+ _this2.options.debug && console.log("".concat(LOG_PREFIX, " Auth request for channel ").concat(channel.name, " failed"));
352
469
  _this2.options.debug && console.error(error);
353
470
  });
354
471
  } else {
355
- this.options.debug && console.log("Subscribing to channels ".concat(channel.name));
472
+ this.options.debug && console.log("".concat(LOG_PREFIX, " Subscribing to channel ").concat(channel.name));
356
473
  this.send({
357
474
  event: 'subscribe',
358
475
  data: {
@@ -364,6 +481,7 @@ var LaravelEchoApiGateway = (function (exports) {
364
481
  }, {
365
482
  key: "unsubscribe",
366
483
  value: function unsubscribe(channel) {
484
+ this.options.debug && console.log("".concat(LOG_PREFIX, " unsubscribe for channel ").concat(channel.name));
367
485
  this.send({
368
486
  event: 'unsubscribe',
369
487
  data: {
@@ -379,11 +497,14 @@ var LaravelEchoApiGateway = (function (exports) {
379
497
  key: "on",
380
498
  value: function on(event) {
381
499
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
500
+ this.options.debug && console.log("".concat(LOG_PREFIX, " on event ").concat(event, " ..."));
382
501
  this.internalListeners[event] = callback;
383
502
  }
384
503
  }, {
385
504
  key: "bind",
386
505
  value: function bind(channel, event, callback) {
506
+ this.options.debug && console.log("".concat(LOG_PREFIX, " bind event ").concat(event, " for channel ").concat(channel.name, " ..."));
507
+
387
508
  if (!this.listeners[channel.name]) {
388
509
  this.listeners[channel.name] = {};
389
510
  }
@@ -394,6 +515,7 @@ var LaravelEchoApiGateway = (function (exports) {
394
515
  key: "unbindEvent",
395
516
  value: function unbindEvent(channel, event) {
396
517
  var callback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
518
+ this.options.debug && console.log("".concat(LOG_PREFIX, " unbind event ").concat(event, " for channel ").concat(channel.name, " ..."));
397
519
 
398
520
  if (this.internalListeners[event] && (callback === null || this.internalListeners[event] === callback)) {
399
521
  delete this.internalListeners[event];
@@ -404,62 +526,63 @@ var LaravelEchoApiGateway = (function (exports) {
404
526
  return Websocket;
405
527
  }();
406
528
 
407
- /**
408
- * Event name formatter
409
- */
410
- class EventFormatter {
411
- /**
412
- * Create a new class instance.
413
- */
414
- constructor(namespace) {
415
- this.setNamespace(namespace);
416
- }
417
- /**
418
- * Format the given event name.
419
- */
420
- format(event) {
421
- if (event.charAt(0) === '.' || event.charAt(0) === '\\') {
422
- return event.substr(1);
423
- }
424
- else if (this.namespace) {
425
- event = this.namespace + '.' + event;
426
- }
427
- return event.replace(/\./g, '\\');
428
- }
429
- /**
430
- * Set the event namespace.
431
- */
432
- setNamespace(value) {
433
- this.namespace = value;
434
- }
529
+ /**
530
+ * Event name formatter
531
+ */
532
+ class EventFormatter {
533
+ /**
534
+ * Create a new class instance.
535
+ */
536
+ constructor(namespace) {
537
+ this.setNamespace(namespace);
538
+ }
539
+ /**
540
+ * Format the given event name.
541
+ */
542
+ format(event) {
543
+ if (event.charAt(0) === '.' || event.charAt(0) === '\\') {
544
+ return event.substr(1);
545
+ }
546
+ else if (this.namespace) {
547
+ event = this.namespace + '.' + event;
548
+ }
549
+ return event.replace(/\./g, '\\');
550
+ }
551
+ /**
552
+ * Set the event namespace.
553
+ */
554
+ setNamespace(value) {
555
+ this.namespace = value;
556
+ }
435
557
  }
436
558
 
437
- /**
438
- * This class represents a basic channel.
439
- */
440
- class Channel {
441
- /**
442
- * Listen for a whisper event on the channel instance.
443
- */
444
- listenForWhisper(event, callback) {
445
- return this.listen('.client-' + event, callback);
446
- }
447
- /**
448
- * Listen for an event on the channel instance.
449
- */
450
- notification(callback) {
451
- return this.listen('.Illuminate\\Notifications\\Events\\BroadcastNotificationCreated', callback);
452
- }
453
- /**
454
- * Stop listening for a whisper event on the channel instance.
455
- */
456
- stopListeningForWhisper(event, callback) {
457
- return this.stopListening('.client-' + event, callback);
458
- }
559
+ /**
560
+ * This class represents a basic channel.
561
+ */
562
+ class Channel {
563
+ /**
564
+ * Listen for a whisper event on the channel instance.
565
+ */
566
+ listenForWhisper(event, callback) {
567
+ return this.listen('.client-' + event, callback);
568
+ }
569
+ /**
570
+ * Listen for an event on the channel instance.
571
+ */
572
+ notification(callback) {
573
+ return this.listen('.Illuminate\\Notifications\\Events\\BroadcastNotificationCreated', callback);
574
+ }
575
+ /**
576
+ * Stop listening for a whisper event on the channel instance.
577
+ */
578
+ stopListeningForWhisper(event, callback) {
579
+ return this.stopListening('.client-' + event, callback);
580
+ }
459
581
  }
460
582
 
461
- /**
462
- * This class represents a Pusher channel.
583
+ var LOG_PREFIX$1 = '[LE-AG-Channel]';
584
+ /**
585
+ * This class represents a Pusher channel.
463
586
  */
464
587
 
465
588
  var Channel$1 = /*#__PURE__*/function (_BaseChannel) {
@@ -467,8 +590,8 @@ var LaravelEchoApiGateway = (function (exports) {
467
590
 
468
591
  var _super = _createSuper(Channel);
469
592
 
470
- /**
471
- * Create a new class instance.
593
+ /**
594
+ * Create a new class instance.
472
595
  */
473
596
  function Channel(socket, name, options) {
474
597
  var _this;
@@ -485,76 +608,83 @@ var LaravelEchoApiGateway = (function (exports) {
485
608
 
486
609
  return _this;
487
610
  }
488
- /**
489
- * Subscribe to a Pusher channel.
611
+ /**
612
+ * Subscribe to a Pusher channel.
490
613
  */
491
614
 
492
615
 
493
616
  _createClass(Channel, [{
494
617
  key: "subscribe",
495
618
  value: function subscribe() {
619
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " subscribe for channel ").concat(this.name, " ..."));
496
620
  this.socket.subscribe(this);
497
621
  }
498
- /**
499
- * Unsubscribe from a Pusher channel.
622
+ /**
623
+ * Unsubscribe from a Pusher channel.
500
624
  */
501
625
 
502
626
  }, {
503
627
  key: "unsubscribe",
504
628
  value: function unsubscribe() {
629
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " unsubscribe for channel ").concat(this.name, " ..."));
505
630
  this.socket.unsubscribe(this);
506
631
  }
507
- /**
508
- * Listen for an event on the channel instance.
632
+ /**
633
+ * Listen for an event on the channel instance.
509
634
  */
510
635
 
511
636
  }, {
512
637
  key: "listen",
513
638
  value: function listen(event, callback) {
639
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " listen to ").concat(event, " for channel ").concat(this.name, " ..."));
514
640
  this.on(this.eventFormatter.format(event), callback);
515
641
  return this;
516
642
  }
517
- /**
518
- * Stop listening for an event on the channel instance.
643
+ /**
644
+ * Stop listening for an event on the channel instance.
519
645
  */
520
646
 
521
647
  }, {
522
648
  key: "stopListening",
523
649
  value: function stopListening(event, callback) {
650
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " stop listening to ").concat(event, " for channel ").concat(this.name, " ..."));
524
651
  this.socket.unbindEvent(this, event, callback);
525
652
  return this;
526
653
  }
527
- /**
528
- * Register a callback to be called anytime a subscription succeeds.
654
+ /**
655
+ * Register a callback to be called anytime a subscription succeeds.
529
656
  */
530
657
 
531
658
  }, {
532
659
  key: "subscribed",
533
660
  value: function subscribed(callback) {
661
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " subscribed for channel ").concat(this.name, " ..."));
534
662
  this.on('subscription_succeeded', function () {
535
663
  callback();
536
664
  });
537
665
  return this;
538
666
  }
539
- /**
540
- * Register a callback to be called anytime a subscription error occurs.
667
+ /**
668
+ * Register a callback to be called anytime a subscription error occurs.
541
669
  */
542
670
 
543
671
  }, {
544
672
  key: "error",
545
673
  value: function error(callback) {
674
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " error for channel ").concat(this.name, " ..."));
546
675
  this.on('error', function (status) {
547
676
  callback(status);
548
677
  });
549
678
  return this;
550
679
  }
551
- /**
552
- * Bind a channel to an event.
680
+ /**
681
+ * Bind a channel to an event.
553
682
  */
554
683
 
555
684
  }, {
556
685
  key: "on",
557
686
  value: function on(event, callback) {
687
+ this.options["debug"] && console.log("".concat(LOG_PREFIX$1, " on ").concat(event, " for channel ").concat(this.name, " ..."));
558
688
  this.socket.bind(this, event, callback);
559
689
  return this;
560
690
  }
@@ -576,8 +706,8 @@ var LaravelEchoApiGateway = (function (exports) {
576
706
  // TODO: implement
577
707
  return this;
578
708
  }
579
- /**
580
- * Listen for someone joining the channel.
709
+ /**
710
+ * Listen for someone joining the channel.
581
711
  */
582
712
 
583
713
  }, {
@@ -586,8 +716,8 @@ var LaravelEchoApiGateway = (function (exports) {
586
716
  // TODO: implement
587
717
  return this;
588
718
  }
589
- /**
590
- * Listen for someone leaving the channel.
719
+ /**
720
+ * Listen for someone leaving the channel.
591
721
  */
592
722
 
593
723
  }, {
@@ -604,32 +734,37 @@ var LaravelEchoApiGateway = (function (exports) {
604
734
  var broadcaster = function broadcaster(options) {
605
735
  return new Connector$1(options);
606
736
  };
737
+ var LOG_PREFIX$2 = '[LE-AG-Connector]';
607
738
  var Connector$1 = /*#__PURE__*/function (_BaseConnector) {
608
739
  _inherits(Connector, _BaseConnector);
609
740
 
610
741
  var _super = _createSuper(Connector);
611
742
 
612
- function Connector() {
743
+ /**
744
+ * Create a new class instance.
745
+ */
746
+ function Connector(options) {
613
747
  var _this;
614
748
 
615
749
  _classCallCheck(this, Connector);
616
750
 
617
- _this = _super.apply(this, arguments);
618
- /**
619
- * All of the subscribed channel names.
751
+ _this = _super.call(this, options);
752
+ /**
753
+ * All of the subscribed channel names.
620
754
  */
621
755
 
622
756
  _this.channels = {};
623
757
  return _this;
624
758
  }
625
- /**
626
- * Create a fresh Socket.io connection.
759
+ /**
760
+ * Create a fresh Socket.io connection.
627
761
  */
628
762
 
629
763
 
630
764
  _createClass(Connector, [{
631
765
  key: "connect",
632
766
  value: function connect() {
767
+ this.options.debug && console.log(LOG_PREFIX$2 + 'Connect ...');
633
768
  this.socket = new Websocket(this.options);
634
769
  return; //
635
770
  // this.socket.on('reconnect', () => {
@@ -640,8 +775,8 @@ var LaravelEchoApiGateway = (function (exports) {
640
775
  //
641
776
  // return this.socket;
642
777
  }
643
- /**
644
- * Get a channel instance by name.
778
+ /**
779
+ * Get a channel instance by name.
645
780
  */
646
781
 
647
782
  }, {
@@ -653,8 +788,8 @@ var LaravelEchoApiGateway = (function (exports) {
653
788
 
654
789
  return this.channels[name];
655
790
  }
656
- /**
657
- * Get a private channel instance by name.
791
+ /**
792
+ * Get a private channel instance by name.
658
793
  */
659
794
 
660
795
  }, {
@@ -666,8 +801,8 @@ var LaravelEchoApiGateway = (function (exports) {
666
801
 
667
802
  return this.channels['private-' + name];
668
803
  }
669
- /**
670
- * Get a presence channel instance by name.
804
+ /**
805
+ * Get a presence channel instance by name.
671
806
  */
672
807
 
673
808
  }, {
@@ -679,8 +814,8 @@ var LaravelEchoApiGateway = (function (exports) {
679
814
 
680
815
  return this.channels['presence-' + name];
681
816
  }
682
- /**
683
- * Leave the given channel, as well as its private and presence variants.
817
+ /**
818
+ * Leave the given channel, as well as its private and presence variants.
684
819
  */
685
820
 
686
821
  }, {
@@ -693,8 +828,8 @@ var LaravelEchoApiGateway = (function (exports) {
693
828
  _this2.leaveChannel(name);
694
829
  });
695
830
  }
696
- /**
697
- * Leave the given channel.
831
+ /**
832
+ * Leave the given channel.
698
833
  */
699
834
 
700
835
  }, {
@@ -705,8 +840,8 @@ var LaravelEchoApiGateway = (function (exports) {
705
840
  delete this.channels[name];
706
841
  }
707
842
  }
708
- /**
709
- * Get the socket ID for the connection.
843
+ /**
844
+ * Get the socket ID for the connection.
710
845
  */
711
846
 
712
847
  }, {
@@ -714,13 +849,14 @@ var LaravelEchoApiGateway = (function (exports) {
714
849
  value: function socketId() {
715
850
  return this.socket.getSocketId();
716
851
  }
717
- /**
718
- * Disconnect socket connection.
852
+ /**
853
+ * Disconnect socket connection.
719
854
  */
720
855
 
721
856
  }, {
722
857
  key: "disconnect",
723
858
  value: function disconnect() {
859
+ this.options.debug && console.log(LOG_PREFIX$2 + 'Disconnect ...');
724
860
  this.socket.close();
725
861
  }
726
862
  }]);
@@ -735,4 +871,4 @@ var LaravelEchoApiGateway = (function (exports) {
735
871
 
736
872
  return exports;
737
873
 
738
- }({}));
874
+ }({}, axios));