Server : nginx/1.18.0 System : Linux localhost 6.14.3-x86_64-linode168 #1 SMP PREEMPT_DYNAMIC Mon Apr 21 19:47:55 EDT 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.16 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/ecommerce/node_modules/pusher-js/src/core/channels/ |
import Channel from './channel';
import * as Collections from '../utils/collections';
import ChannelTable from './channel_table';
import Factory from '../utils/factory';
import Pusher from '../pusher';
import Logger from '../logger';
import * as Errors from '../errors';
import urlStore from '../utils/url_store';
/** Handles a channel map. */
export default class Channels {
channels: ChannelTable;
constructor() {
this.channels = {};
}
/** Creates or retrieves an existing channel by its name.
*
* @param {String} name
* @param {Pusher} pusher
* @return {Channel}
*/
add(name: string, pusher: Pusher) {
if (!this.channels[name]) {
this.channels[name] = createChannel(name, pusher);
}
return this.channels[name];
}
/** Returns a list of all channels
*
* @return {Array}
*/
all(): Channel[] {
return Collections.values(this.channels);
}
/** Finds a channel by its name.
*
* @param {String} name
* @return {Channel} channel or null if it doesn't exist
*/
find(name: string) {
return this.channels[name];
}
/** Removes a channel from the map.
*
* @param {String} name
*/
remove(name: string) {
var channel = this.channels[name];
delete this.channels[name];
return channel;
}
/** Proxies disconnection signal to all channels. */
disconnect() {
Collections.objectApply(this.channels, function(channel) {
channel.disconnect();
});
}
}
function createChannel(name: string, pusher: Pusher): Channel {
if (name.indexOf('private-encrypted-') === 0) {
if (pusher.config.nacl) {
return Factory.createEncryptedChannel(name, pusher, pusher.config.nacl);
}
let errMsg =
'Tried to subscribe to a private-encrypted- channel but no nacl implementation available';
let suffix = urlStore.buildLogSuffix('encryptedChannelSupport');
throw new Errors.UnsupportedFeature(`${errMsg}. ${suffix}`);
} else if (name.indexOf('private-') === 0) {
return Factory.createPrivateChannel(name, pusher);
} else if (name.indexOf('presence-') === 0) {
return Factory.createPresenceChannel(name, pusher);
} else {
return Factory.createChannel(name, pusher);
}
}