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