@soketi/soketi-js
Version:
Laravel Echo extension that works with Soketi, a Laravel-ready WebSockets service.
66 lines (65 loc) • 2.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PusherConnector = void 0;
const connector_1 = require("./connector");
const channel_1 = require("./../channel");
class PusherConnector extends connector_1.Connector {
constructor() {
super(...arguments);
this.channels = {};
}
connect() {
if (typeof this.options.client !== 'undefined') {
this.pusher = this.options.client;
}
else {
this.pusher = new Pusher(this.options.key, this.options);
}
}
listen(name, event, callback) {
return this.channel(name).listen(event, callback);
}
channel(name) {
if (!this.channels[name]) {
this.channels[name] = new channel_1.PusherChannel(this.pusher, name, this.options);
}
return this.channels[name];
}
privateChannel(name) {
if (!this.channels['private-' + name]) {
this.channels['private-' + name] = new channel_1.PusherPrivateChannel(this.pusher, 'private-' + name, this.options);
}
return this.channels['private-' + name];
}
encryptedPrivateChannel(name) {
if (!this.channels['private-encrypted-' + name]) {
this.channels['private-encrypted-' + name] = new channel_1.PusherEncryptedPrivateChannel(this.pusher, 'private-encrypted-' + name, this.options);
}
return this.channels['private-encrypted-' + name];
}
presenceChannel(name) {
if (!this.channels['presence-' + name]) {
this.channels['presence-' + name] = new channel_1.PusherPresenceChannel(this.pusher, 'presence-' + name, this.options);
}
return this.channels['presence-' + name];
}
leave(name) {
let channels = [name, 'private-' + name, 'presence-' + name];
channels.forEach((name, index) => {
this.leaveChannel(name);
});
}
leaveChannel(name) {
if (this.channels[name]) {
this.channels[name].unsubscribe();
delete this.channels[name];
}
}
socketId() {
return this.pusher.connection.socket_id;
}
disconnect() {
this.pusher.disconnect();
}
}
exports.PusherConnector = PusherConnector;