UNPKG

@soketi/soketi

Version:

Just another simple, fast, and resilient open-source WebSockets server.

44 lines (43 loc) 1.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PublicChannelManager = void 0; const utils_1 = require("../utils"); class PublicChannelManager { constructor(server) { this.server = server; } join(ws, channel, message) { if (utils_1.Utils.restrictedChannelName(channel)) { return Promise.resolve({ ws, success: false, errorCode: 4009, errorMessage: 'The channel name is not allowed. Read channel conventions: https://pusher.com/docs/channels/using_channels/channels/#channel-naming-conventions', }); } if (!ws.app) { return Promise.resolve({ ws, success: false, errorCode: 4009, errorMessage: 'Subscriptions messages should be sent after the pusher:connection_established event is received.', }); } return this.server.adapter.addToChannel(ws.app.id, channel, ws).then(connections => { return { ws, success: true, channelConnections: connections, }; }); } leave(ws, channel) { return this.server.adapter.removeFromChannel(ws.app.id, channel, ws.id).then((remainingConnections) => { return { left: true, remainingConnections: remainingConnections, }; }); } } exports.PublicChannelManager = PublicChannelManager;