this._callbacks = {};
this._socket = eio_socket;
- this._root_namespace = this;
- this._namespaces = new Object(null);
-
this._mixinEmitter();
this._bindSocketListeners();
}
WebsocketRpc.prototype.dispose = function() {
if (this._onMessageProxy) {
- this._socket.off('message', this._onMessageProxy);
+ this._socket.removeListener('message', this._onMessageProxy);
delete this._onMessageProxy;
}
- this.disposeNamespaces();
+ this.removeAllListeners();
};
-WebsocketRpc.prototype.disposeNamespaces = function() {
- for (var namespace in this._namespaces) {
- this._namespaces[namespace].dispose();
- this._namespaces[namespace] = null;
- }
-};
/**
-WebsocketRpc.prototype.namespace = function(namespace) {
- // Does this namespace already exist?
- if (this._namespaces[namespace]) {
- return this._namespaces[namespace];
- }
-
- var ns = new WebsocketRpcNamespace(this, namespace);
- ns._root_namespace = this._root_namespace;
-console.log('Created namespace', namespace);
- this._namespaces[namespace] = ns;
-
- return ns;
-};
-
-
/**
* Make an RPC call
* First argument must be the method name to call
} else {
returnFn = function noop(){};
}
-console.log(packet.method);
- this.emit.apply(this, [packet.method, returnFn].concat(packet.params));
- // Forward the call on to any matching namespaces
- this._forwardCall(packet, returnFn);
- }
-};
-
-
-/**
- * Take a call and forward it on to any matching namespaces
- */
-WebsocketRpc.prototype._forwardCall = function(packet, returnFn) {
- var ns;
-
- for (var namespace in this._namespaces) {
- ns = this._namespaces[namespace];
-
- // If the method name is in this namespace, strip the namespace string off
- // and emit the remaining method on the namespace object
- // (namespace.api.method_name() becomes method_name())
- if (packet.method.indexOf(namespace) === 0) {
- ns.emit.apply(ns, [packet.method.replace(namespace + '.', ''), returnFn].concat(packet.params));
- ns._forwardCall(packet, returnFn);
- }
+ this.emit.apply(this, [packet.method, returnFn].concat(packet.params));
}
};
-
-function WebsocketRpcNamespace(parent_rpc, new_namespace) {
- var self = this,
- to_bind, i;
-
- this._namespaces = new Object(null);
-
- this._parent = parent_rpc;
- this._namespace = new_namespace;
-
- if (this._namespace.substr(-1) !== '.')
- this._namespace += '.';
-
- // Proxy these functions from _parent, appending our namespace in the first argument
- to_bind = ['namespace', 'on', 'once', 'off', 'removeListener', 'removeAllListeners', 'emit', 'listeners', 'hasListeners'];
- for (i=0; i<to_bind.length; i++)
- this.bindFnOverride(to_bind[i], true);
-
- this.bindFnOverride('call', false, this._parent);
-
- // Proxy these functions from _parent
- to_bind = ['disposeNamespaces', '_forwardCall'];
- for (i=0; i<to_bind.length; i++)
- this[to_bind[i]] = this._parent[to_bind[i]];
-}
-
-
-WebsocketRpcNamespace.prototype.bindFnOverride = function(fn_name, append_first_arg, context) {
- var self = this;
-
- this[fn_name] = function appendNamespaceFnOverrideBound() {
- var args;
-
- if (append_first_arg) {
- args = Array.prototype.slice.call(arguments, 0, arguments.length);
- args[0] = self._namespace + args[0];
- }
-
- return self._parent[fn_name].apply(context || self, args || arguments);
- };
-};
-
-
-WebsocketRpcNamespace.prototype.dispose = function() {
- this.disposeNamespaces();
- this.call = this.on = this.off = this.namespace = this.disposeNamespaces = null;
- this._parent = null;
- this.off();
-};
-
-
-
// If running a node module, set the exports
if (typeof module === 'object' && typeof module.exports !== 'undefined') {
module.exports = WebsocketRpc;
var http_handler;
-var WebListener = function (web_config, transports) {
+var WebListener = module.exports = function (web_config, transports) {
var hs, opts, ws_opts,
that = this;
transports: ['websocket', 'polling', 'flashsocket'],
path: (global.config.http_base_path || '') + '/transport'
});
- console.log((global.config.http_base_path || '') + '/transport');
-
- //this.ws.enable('browser client minification');
- //this.ws.enable('browser client etag');
- //this.ws.set('transports', transports);
- //this.ws.set('resource', (global.config.http_base_path || '') + '/transport');
this.ws.on('connection', function(socket) {
- console.log('Connection!');
initialiseSocket(socket, function(err, authorised) {
var client;
function handleHttpRequest(request, response) {
- var uri = url.parse(request.url, true);
-
- // If this isn't a socket.io request, pass it onto the http handler
- if (uri.pathname.substr(0, 10) !== '/socket.io') {
- http_handler.serve(request, response);
- }
+ http_handler.serve(request, response);
}
function rangeCheck(addr, range) {
callback(null, true);
}
}
-
-
-
-
-
-module.exports = WebListener;