rpc-websockets
Advanced tools
Comparing version 2.2.0 to 2.2.1
@@ -73,3 +73,3 @@ /** | ||
function Client() { | ||
var address = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "ws://localhost:8080"; | ||
var address = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "ws://localhost:8080/rpc/1.0"; | ||
@@ -76,0 +76,0 @@ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
@@ -109,5 +109,2 @@ /** | ||
// stores all connected sockets in the appropriate namespace | ||
_this.namespaces = new _map2.default(); | ||
// stores all events as keys and subscribed users in array as value | ||
@@ -121,3 +118,3 @@ _this.events = {}; | ||
_this.wss.on("connection", function (socket) { | ||
var ns = _url2.default.parse(socket.upgradeReq.url).pathname; | ||
var path = _url2.default.parse(socket.upgradeReq.url, true).pathname.split("/"); | ||
socket._id = _uuid2.default.v1(); | ||
@@ -157,10 +154,11 @@ | ||
// store socket | ||
_this.clients.set(socket._id, socket); | ||
// use an RPC handler if rpc request | ||
if (options.rpc && "/" + path[1] === options.rpc.root_path) { | ||
if (path[2] !== options.rpc.version) return socket.close(404); | ||
if (!_this.namespaces.has(ns)) _this.namespaces.set(ns, new Array()); | ||
// store socket | ||
_this.clients.set(socket._id, socket); | ||
_this.namespaces.get(ns).push(socket._id); | ||
return _this._handleRPC(socket); | ||
return _this._handleRPC(socket); | ||
} | ||
}); | ||
@@ -214,6 +212,2 @@ | ||
// TODO: NAPRAVI novu funkciju 'of' koja prima ns name kao argument i | ||
// vraca neki objekt koji ima funkciju 'emit' koja radi samo na | ||
// klijentima iz tog ns-a | ||
// forward emitted event to subscribers | ||
@@ -256,46 +250,2 @@ this.on(name, function () { | ||
/** | ||
* Returns a requested namespace object | ||
* @method | ||
* @param {String} name - namespace identifier | ||
* @throws {TypeError} | ||
* @return {Namespace} | ||
*/ | ||
}, { | ||
key: "of", | ||
value: function of(name) { | ||
(0, _assertArgs2.default)(arguments, { | ||
"name": "string" | ||
}); | ||
var self = this; | ||
return { | ||
emit: function emit(event, params) { | ||
var socket_ids = self.namespaces.get(name); | ||
for (var i = 0, id; id = socket_ids[i]; ++i) { | ||
self.clients.get(id).send((0, _stringify2.default)({ | ||
notification: event, | ||
params: params || [] | ||
})); | ||
} | ||
}, | ||
name: name, | ||
connected: function connected() { | ||
var clients = {}; | ||
var socket_ids = self.namespaces.get(name); | ||
for (var i = 0, id; id = socket_ids[i]; ++i) { | ||
clients[id] = self.clients.get(id); | ||
}return clients; | ||
}, | ||
clients: function clients() { | ||
return self.namespaces.get(name); | ||
} | ||
}; | ||
} | ||
/** | ||
* Lists all created events. | ||
@@ -302,0 +252,0 @@ * @method |
{ | ||
"name": "rpc-websockets", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"description": "JSON-RPC 2.0 implementation over WebSockets for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
@@ -207,3 +207,3 @@ [![GitHub license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/qaap/rpc-websockets/blob/master/LICENSE) | ||
### server.of(name) | ||
### server.of(name) -> Namespace | ||
@@ -210,0 +210,0 @@ Returns a Namespace object initialized by the provided pathname upon connecting(eg: ```/chat```). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57504
1014