@omneedia/socketcluster
Version:
SocketCluster - A Highly parallelized WebSocket server cluster to make the most of multi-core machines/instances.
71 lines (52 loc) • 1.62 kB
JavaScript
var Emitter = require('component-emitter');
var SCChannel = function (name, client, options) {
var self = this;
Emitter.call(this);
this.PENDING = 'pending';
this.SUBSCRIBED = 'subscribed';
this.UNSUBSCRIBED = 'unsubscribed';
this.name = name;
this.state = this.UNSUBSCRIBED;
this.client = client;
this.options = options || {};
this.setOptions(this.options);
};
SCChannel.prototype = Object.create(Emitter.prototype);
SCChannel.prototype.setOptions = function (options) {
if (!options) {
options = {};
}
this.waitForAuth = options.waitForAuth || false;
this.batch = options.batch || false;
if (options.data !== undefined) {
this.data = options.data;
}
};
SCChannel.prototype.getState = function () {
return this.state;
};
SCChannel.prototype.subscribe = function (options) {
this.client.subscribe(this.name, options);
};
SCChannel.prototype.unsubscribe = function () {
this.client.unsubscribe(this.name);
};
SCChannel.prototype.isSubscribed = function (includePending) {
return this.client.isSubscribed(this.name, includePending);
};
SCChannel.prototype.publish = function (data, callback) {
this.client.publish(this.name, data, callback);
};
SCChannel.prototype.watch = function (handler) {
this.client.watch(this.name, handler);
};
SCChannel.prototype.unwatch = function (handler) {
this.client.unwatch(this.name, handler);
};
SCChannel.prototype.watchers = function () {
return this.client.watchers(this.name);
};
SCChannel.prototype.destroy = function () {
this.client.destroyChannel(this.name);
};
module.exports.SCChannel = SCChannel;