@donation-alerts/events
Version:
Listen to various Donation Alerts events.
63 lines (62 loc) • 1.84 kB
JavaScript
import { __decorate } from "tslib";
import { ReadDocumentation } from '@donation-alerts/common';
/**
* Listener for subscription-based events in Centrifugo channels.
*
* @remarks
* This class represents a connection to a specific Centrifugo channel associated with a user.
* It handles event subscriptions and provides information about the connected channel and user.
* You can use it to manage events and to remove the associated listener when it's no longer needed.
*
* @example
* ```ts
* console.log(listener.channel); // Full channel name
* console.log(listener.userId); // User's ID
*
* await listener.remove(); // Removes the listener
* ```
*/
let EventsListener = class EventsListener {
/** @internal */
constructor(channelName, userId, subscription, client) {
this._channelName = channelName;
this._userId = userId;
this._centrifugoSubscription = subscription;
this._client = client;
}
/**
* ID of the user associated with this listener.
*/
get userId() {
return this._userId;
}
/**
* Name of the Centrifugo channel associated with this listener.
*/
get channelName() {
return this._channelName;
}
/**
* Full name of the Centrifugo channel.
*
* @remarks
* Combines the base channel name and the user ID to construct the complete channel string.
*/
get channel() {
return this._centrifugoSubscription.channel;
}
/** @internal */
get _subscription() {
return this._centrifugoSubscription;
}
/**
* Removes this listener from the client.
*/
async remove() {
await this._client.removeEventsListener(this);
}
};
EventsListener = __decorate([
ReadDocumentation('events')
], EventsListener);
export { EventsListener };