UNPKG

@soketi/soketi-js

Version:

Laravel Echo extension that works with Soketi, a Laravel-ready WebSockets service.

52 lines (51 loc) 1.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PusherChannel = void 0; const util_1 = require("../util"); const channel_1 = require("./channel"); class PusherChannel extends channel_1.Channel { constructor(pusher, name, options) { super(); this.name = name; this.pusher = pusher; this.options = options; this.eventFormatter = new util_1.EventFormatter(this.options.namespace); this.subscribe(); } subscribe() { this.subscription = this.pusher.subscribe(this.name); } unsubscribe() { this.pusher.unsubscribe(this.name); } listen(event, callback) { this.on(this.eventFormatter.format(event), callback); return this; } stopListening(event, callback) { if (callback) { this.subscription.unbind(this.eventFormatter.format(event), callback); } else { this.subscription.unbind(this.eventFormatter.format(event)); } return this; } subscribed(callback) { this.on('pusher:subscription_succeeded', () => { callback(); }); return this; } error(callback) { this.on('pusher:subscription_error', (status) => { callback(status); }); return this; } on(event, callback) { this.subscription.bind(event, callback); return this; } } exports.PusherChannel = PusherChannel;