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