69 lines
1.5 KiB
JavaScript
69 lines
1.5 KiB
JavaScript
var SCEmitter = require('sc-emitter').SCEmitter;
|
|
|
|
var SCChannel = function (name, client, options) {
|
|
var self = this;
|
|
|
|
SCEmitter.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(SCEmitter.prototype);
|
|
|
|
SCChannel.prototype.setOptions = function (options) {
|
|
if (!options) {
|
|
options = {};
|
|
}
|
|
this.waitForAuth = options.waitForAuth || 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;
|