UNPKG

helene

Version:
50 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Event = void 0; const utils_1 = require("../utils"); class Event { uuid; name; isProtected; channel; server; cluster; shouldSubscribe = async () => true; constructor(name, server, channel, opts) { this.uuid = utils_1.Presentation.uuid(); this.name = name; this.server = server; this.channel = channel; this.isProtected = opts?.protected ?? false; if (opts?.user) { this.isProtected = true; this.shouldSubscribe = async function (client, event, channel) { if (!client.userId) return false; return channel === client.userId.toString(); }; } if (opts?.shouldSubscribe) { this.shouldSubscribe = opts.shouldSubscribe; } this.cluster = Boolean(opts?.cluster); } handler(channel, params) { const payload = utils_1.Presentation.encode({ uuid: utils_1.Presentation.uuid(), type: utils_1.PayloadType.EVENT, event: this.name, channel: channel.channelName, params, }); if (this.cluster && this.server?.redisTransport?.pub) { this.server.redisTransport .publish(this.name, channel.channelName, payload) .catch(console.error); return; } channel.propagate(this.name, payload); } } exports.Event = Event; //# sourceMappingURL=event.js.map