kurento-jsonrpc
Advanced tools
Comparing version 5.0.5 to 5.0.6-dev
@@ -19,2 +19,2 @@ /* | ||
exports.JsonRpcClient = JsonRpcClient; | ||
exports.JsonRpcClient = JsonRpcClient; |
@@ -17,18 +17,244 @@ /* | ||
var RpcBuilder = require('../..'); | ||
var WebSocketWithReconnection = require('./transports/webSocketWithReconnection'); | ||
var WebSocket = require('ws'); | ||
Date.now = Date.now || function() { | ||
return +new Date; | ||
}; | ||
var PING_INTERVAL = 5000; | ||
function JsonRpcClient(wsUrl, onRequest, onerror) | ||
{ | ||
var ws = new WebSocket(wsUrl); | ||
ws.addEventListener('error', onerror); | ||
var RECONNECTING = 'RECONNECTING'; | ||
var CONNECTED = 'CONNECTED'; | ||
var DISCONNECTED = 'DISCONNECTED'; | ||
var rpc = new RpcBuilder(RpcBuilder.packers.JsonRPC, ws, onRequest); | ||
var RECONNECTING = "RECONNECTING"; | ||
var CONNECTED = "CONNECTED"; | ||
var DISCONNECTED = "DISCONNECTED"; | ||
this.close = rpc.close.bind(rpc); | ||
this.sendRequest = rpc.encode.bind(rpc); | ||
}; | ||
/** | ||
* | ||
* heartbeat: interval in ms for each heartbeat message, | ||
* sendCloseMessage : true / false, before closing the connection, it sends a close_session message | ||
* <pre> | ||
* ws : { | ||
* uri : URI to conntect to, | ||
* useSockJS : true (use SockJS) / false (use WebSocket) by default, | ||
* onconnected : callback method to invoke when connection is successful, | ||
* ondisconnect : callback method to invoke when the connection is lost, | ||
* onreconnecting : callback method to invoke when the client is reconnecting, | ||
* onreconnected : callback method to invoke when the client succesfully reconnects, | ||
* }, | ||
* rpc : { | ||
* requestTimeout : timeout for a request, | ||
* sessionStatusChanged: callback method for changes in session status, | ||
* mediaRenegotiation: mediaRenegotiation | ||
* } | ||
* </pre> | ||
*/ | ||
function JsonRpcClient(configuration) { | ||
module.exports = JsonRpcClient; | ||
var self = this; | ||
var wsConfig = configuration.ws; | ||
var notReconnectIfNumLessThan = -1; | ||
var pingNextNum = 0; | ||
var enabledPings = true; | ||
var pingPongStarted = false; | ||
var pingInterval; | ||
var status = DISCONNECTED; | ||
var onreconnecting = wsConfig.onreconnecting; | ||
var onreconnected = wsConfig.onreconnected; | ||
var onconnected = wsConfig.onconnected; | ||
configuration.rpc.pull = function(params, request) { | ||
request.reply(null, "push"); | ||
} | ||
wsConfig.onreconnecting = function() { | ||
console.log("--------- ONRECONNECTING -----------"); | ||
if (status === RECONNECTING) { | ||
console.error("Websocket already in RECONNECTING state when receiving a new ONRECONNECTING message. Ignoring it"); | ||
return; | ||
} | ||
status = RECONNECTING; | ||
if (onreconnecting) { | ||
onreconnecting(); | ||
} | ||
} | ||
wsConfig.onreconnected = function() { | ||
console.log("--------- ONRECONNECTED -----------"); | ||
if (status === CONNECTED) { | ||
console.error("Websocket already in CONNECTED state when receiving a new ONRECONNECTED message. Ignoring it"); | ||
return; | ||
} | ||
status = CONNECTED; | ||
enabledPings = true; | ||
updateNotReconnectIfLessThan(); | ||
usePing(); | ||
if (onreconnected) { | ||
onreconnected(); | ||
} | ||
} | ||
wsConfig.onconnected = function() { | ||
console.log("--------- ONCONNECTED -----------"); | ||
if (status === CONNECTED) { | ||
console.error("Websocket already in CONNECTED state when receiving a new ONCONNECTED message. Ignoring it"); | ||
return; | ||
} | ||
status = CONNECTED; | ||
enabledPings = true; | ||
usePing(); | ||
if (onconnected) { | ||
onconnected(); | ||
} | ||
} | ||
var ws = new WebSocketWithReconnection(wsConfig); | ||
console.log('Connecting websocket to URI: ' + wsConfig.uri); | ||
var rpcBuilderOptions = { | ||
request_timeout: configuration.rpc.requestTimeout | ||
}; | ||
var rpc = new RpcBuilder(RpcBuilder.packers.JsonRPC, rpcBuilderOptions, ws, | ||
function(request) { | ||
console.log('Received request: ' + JSON.stringify(request)); | ||
try { | ||
var func = configuration.rpc[request.method]; | ||
if (func === undefined) { | ||
console.error("Method " + request.method + " not registered in client"); | ||
} else { | ||
func(request.params, request); | ||
} | ||
} catch (err) { | ||
console.error('Exception processing request: ' + JSON.stringify(request)); | ||
console.error(err); | ||
} | ||
}); | ||
this.send = function(method, params, callback) { | ||
if (method !== 'ping') { | ||
console.log('Request: method:' + method + " params:" + JSON.stringify(params)); | ||
} | ||
var requestTime = Date.now(); | ||
rpc.encode(method, params, function(error, result) { | ||
if (error) { | ||
try { | ||
console.error("ERROR:" + error.message + " in Request: method:" + method + " params:" + JSON.stringify(params)); | ||
if (error.data) { | ||
console.error("ERROR DATA:" + JSON.stringify(error.data)); | ||
} | ||
} catch (e) {} | ||
error.requestTime = requestTime; | ||
} | ||
if (callback) { | ||
if (result != undefined && result.message !== 'pong') { | ||
console.log('Response: ' + JSON.stringify(result)); | ||
} | ||
callback(error, result); | ||
} | ||
}); | ||
} | ||
function updateNotReconnectIfLessThan() { | ||
notReconnectIfNumLessThan = pingNextNum; | ||
console.log("notReconnectIfNumLessThan = " + notReconnectIfNumLessThan); | ||
} | ||
function sendPing() { | ||
if (enabledPings) { | ||
var params = null; | ||
if (pingNextNum == 0 || pingNextNum == notReconnectIfNumLessThan) { | ||
params = { | ||
interval: PING_INTERVAL | ||
}; | ||
} | ||
pingNextNum++; | ||
self.send('ping', params, (function(pingNum) { | ||
return function(error, result) { | ||
if (error) { | ||
if (pingNum > notReconnectIfNumLessThan) { | ||
enabledPings = false; | ||
updateNotReconnectIfLessThan(); | ||
console.log("DSS did not respond to ping message " + pingNum + ". Reconnecting... "); | ||
ws.reconnectWs(); | ||
} | ||
} | ||
} | ||
})(pingNextNum)); | ||
} else { | ||
console.log("Trying to send ping, but ping is not enabled"); | ||
} | ||
} | ||
/* | ||
* If configuration.hearbeat has any value, the ping-pong will work with the interval | ||
* of configuration.hearbeat | ||
*/ | ||
function usePing() { | ||
if (!pingPongStarted) { | ||
console.log("Starting ping (if configured)") | ||
pingPongStarted = true; | ||
if (configuration.heartbeat != undefined) { | ||
pingInterval = setInterval(sendPing, configuration.heartbeat); | ||
sendPing(); | ||
} | ||
} | ||
} | ||
this.close = function() { | ||
console.log("Closing jsonRpcClient explicitely by client"); | ||
if (pingInterval != undefined) { | ||
clearInterval(pingInterval); | ||
} | ||
pingPongStarted = false; | ||
enabledPings = false; | ||
if (configuration.sendCloseMessage) { | ||
this.send('close_session', null, function(error, result) { | ||
if (error) { | ||
console.error("Error sending close message: " + JSON.stringify(error)); | ||
} | ||
ws.close(); | ||
}); | ||
} else { | ||
ws.close(); | ||
} | ||
} | ||
// This method is only for testing | ||
this.forceClose = function(millis) { | ||
ws.forceClose(millis); | ||
} | ||
this.reconnect = function() { | ||
ws.reconnectWs(); | ||
} | ||
} | ||
module.exports = JsonRpcClient; |
{ | ||
"name": "kurento-jsonrpc", | ||
"version": "5.0.5", | ||
"version": "5.0.6-dev", | ||
"description": "RPC library for browser and Node.js", | ||
@@ -43,3 +43,3 @@ "main": "lib/index.js", | ||
"grunt-contrib-clean": "~0.5.0", | ||
"grunt-jsdoc": "~0.5.6", | ||
"grunt-jsdoc": "~0.6.8", | ||
"grunt-npm2bower-sync": "^0.4.0", | ||
@@ -49,4 +49,5 @@ "grunt-shell": "^0.7.0", | ||
"minifyify": "~3.0.12", | ||
"nodeunit": "~0.9.0" | ||
"nodeunit": "~0.9.0", | ||
"sockjs-client": "1.0.3" | ||
} | ||
} |
@@ -1,9 +0,10 @@ | ||
[![][KurentoImage]][website] | ||
[![][KurentoImage]][Kurento] | ||
Copyright © 2013-2014 Kurento. Licensed under [LGPL License]. | ||
Copyright © 2013-2016 [Kurento]. Licensed under [LGPL v2.1 License]. | ||
Kurento jsonrpc for Bower | ||
=============== | ||
Kurento json rpc | ||
========================= | ||
Kurento Json RPC. | ||
The Kurento jsonrpc project is a small RPC library for browser and Node.js. | ||
@@ -42,38 +43,103 @@ | ||
--------------- | ||
Kurento provides an open platform for video processing and streaming | ||
based on standards. | ||
This platform has several APIs and components which provide solutions | ||
to the requirements of multimedia content application developers. | ||
These include: | ||
Kurento is an open source software project providing a platform suitable | ||
for creating modular applications with advanced real-time communication | ||
capabilities. For knowing more about Kurento, please visit the Kurento | ||
project website: http://www.kurento.org. | ||
* Kurento Media Server (KMS). A full featured media server providing | ||
the capability to create and manage dynamic multimedia pipelines. | ||
* Kurento Control Server (KCS). Signaling server for KMS. It provides | ||
extra capabilities such as security, load balance, and so on. | ||
* Kurento Clients. Libraries to create applications with media | ||
capabilities. Kurento provides libraries for Java, browser JavaScript, | ||
and Node.js. | ||
Kurento is part of [FIWARE]. For further information on the relationship of | ||
FIWARE and Kurento check the [Kurento FIWARE Catalog Entry] | ||
Downloads | ||
--------- | ||
To download binary releases of Kurento components visit http://kurento.org | ||
Kurento is part of the [NUBOMEDIA] research initiative. | ||
Documentation | ||
------------- | ||
The Kurento project provides detailed [documentation] including tutorials, | ||
installation and development guides. A simplified version of the documentation | ||
can be found on [readthedocs.org]. The [Open API specification] a.k.a. Kurento | ||
Protocol is also available on [apiary.io]. | ||
Source | ||
------ | ||
The source code of this project can be cloned from the [GitHub repository]. | ||
Code for other Kurento projects can be found in the [GitHub Kurento group]. | ||
Code for other Kurento projects can be found in the [GitHub Kurento Group]. | ||
News and Website | ||
---------------- | ||
Information about Kurento can be found on our [website]. | ||
Check the [Kurento blog] | ||
Follow us on Twitter @[kurentoms]. | ||
[Bower]: http://bower.io | ||
[Bower repository]: https://github.com/Kurento/kurento-jsonrpc-js-bower | ||
[GitHub Kurento group]: https://github.com/kurento | ||
Issue tracker | ||
------------- | ||
Issues and bug reports should be posted to the [GitHub Kurento bugtracker] | ||
Licensing and distribution | ||
-------------------------- | ||
Software associated to Kurento is provided as open source under GNU Library or | ||
"Lesser" General Public License, version 2.1 (LGPL-2.1). Please check the | ||
specific terms and conditions linked to this open source license at | ||
http://opensource.org/licenses/LGPL-2.1. Please note that software derived as a | ||
result of modifying the source code of Kurento software in order to fix a bug | ||
or incorporate enhancements is considered a derivative work of the product. | ||
Software that merely uses or aggregates (i.e. links to) an otherwise unmodified | ||
version of existing software is not considered a derivative work. | ||
Contribution policy | ||
------------------- | ||
You can contribute to the Kurento community through bug-reports, bug-fixes, new | ||
code or new documentation. For contributing to the Kurento community, drop a | ||
post to the [Kurento Public Mailing List] providing full information about your | ||
contribution and its value. In your contributions, you must comply with the | ||
following guidelines | ||
* You must specify the specific contents of your contribution either through a | ||
detailed bug description, through a pull-request or through a patch. | ||
* You must specify the licensing restrictions of the code you contribute. | ||
* For newly created code to be incorporated in the Kurento code-base, you must | ||
accept Kurento to own the code copyright, so that its open source nature is | ||
guaranteed. | ||
* You must justify appropriately the need and value of your contribution. The | ||
Kurento project has no obligations in relation to accepting contributions | ||
from third parties. | ||
* The Kurento project leaders have the right of asking for further | ||
explanations, tests or validations of any code contributed to the community | ||
before it being incorporated into the Kurento code-base. You must be ready to | ||
addressing all these kind of concerns before having your code approved. | ||
Support | ||
------- | ||
The Kurento project provides community support through the [Kurento Public | ||
Mailing List] and through [StackOverflow] using the tags *kurento* and | ||
*fiware-kurento*. | ||
Before asking for support, please read first the [Kurento Netiquette Guidelines] | ||
[documentation]: http://www.kurento.org/documentation | ||
[FIWARE]: http://www.fiware.org | ||
[GitHub Kurento bugtracker]: https://github.com/Kurento/bugtracker/issues | ||
[GitHub Kurento Group]: https://github.com/kurento | ||
[kurentoms]: http://twitter.com/kurentoms | ||
[Kurento]: http://kurento.org | ||
[Kurento Blog]: http://www.kurento.org/blog | ||
[Kurento FIWARE Catalog Entry]: http://catalogue.fiware.org/enablers/stream-oriented-kurento | ||
[Kurento Netiquette Guidelines]: http://www.kurento.org/blog/kurento-netiquette-guidelines | ||
[Kurento Public Mailing list]: https://groups.google.com/forum/#!forum/kurento | ||
[KurentoImage]: https://secure.gravatar.com/avatar/21a2a12c56b2a91c8918d5779f1778bf?s=120 | ||
[LGPL v2.1 License]: http://www.gnu.org/licenses/lgpl-2.1.html | ||
[NUBOMEDIA]: http://www.nubomedia.eu | ||
[StackOverflow]: http://stackoverflow.com/search?q=kurento | ||
[GitHub repository]: https://github.com/kurento/kurento-jsonrpc-js | ||
[KurentoImage]: https://secure.gravatar.com/avatar/21a2a12c56b2a91c8918d5779f1778bf?s=120 | ||
[kurentoms]: http://twitter.com/kurentoms | ||
[LGPL License]: http://www.gnu.org/licenses/lgpl-2.1.html | ||
[website]: http://kurento.org | ||
[grunt]: http://gruntjs.com/ | ||
[Node.js project PPA]: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os | ||
[NPM repository]: https://www.npmjs.org/package/kurento-jsonrpc | ||
[nodeunit]: https://github.com/caolan/nodeunit | ||
[Read-the-docs]: http://read-the-docs.readthedocs.org/ | ||
[readthedocs.org]: http://kurento.readthedocs.org/ | ||
[Open API specification]: http://kurento.github.io/doc-kurento/ | ||
[apiary.io]: http://docs.streamoriented.apiary.io/ |
118
README.md
@@ -1,9 +0,10 @@ | ||
[![][KurentoImage]][website] | ||
[![][KurentoImage]][Kurento] | ||
Copyright © 2013-2014 Kurento. Licensed under [LGPL License]. | ||
Copyright © 2013-2016 [Kurento]. Licensed under [LGPL v2.1 License]. | ||
Kurento jsonrpc library for Node.js and browsers | ||
=============== | ||
Kurento Web SDK RPC Builder | ||
================================================ | ||
Kurento Web SDK RPC Builder. | ||
The Kurento Web SDK RPC Builer project is a small RPC library for browser and Node.js. | ||
@@ -54,3 +55,2 @@ | ||
How to test | ||
@@ -67,3 +67,2 @@ ----------- | ||
Kurento | ||
@@ -74,24 +73,24 @@ ======= | ||
--------------- | ||
Kurento provides an open platform for video processing and streaming | ||
based on standards. | ||
This platform has several APIs and components which provide solutions | ||
to the requirements of multimedia content application developers. | ||
These include: | ||
Kurento is an open source software project providing a platform suitable | ||
for creating modular applications with advanced real-time communication | ||
capabilities. For knowing more about Kurento, please visit the Kurento | ||
project website: http://www.kurento.org. | ||
* Kurento Media Server (KMS). A full featured media server providing | ||
the capability to create and manage dynamic multimedia pipelines. | ||
* Kurento Control Server (KCS). Signaling server for KMS. It provides | ||
extra capabilities such as security, load balance, and so on. | ||
* Kurento Clients. Libraries to create applications with media | ||
capabilities. Kurento provides libraries for Java, browser JavaScript, | ||
and Node.js. | ||
Kurento is part of [FIWARE]. For further information on the relationship of | ||
FIWARE and Kurento check the [Kurento FIWARE Catalog Entry] | ||
Downloads | ||
--------- | ||
To download binary releases of Kurento components visit http://kurento.org | ||
Kurento is part of the [NUBOMEDIA] research initiative. | ||
Documentation | ||
------------- | ||
The Kurento project provides detailed [documentation] including tutorials, | ||
installation and development guides. A simplified version of the documentation | ||
can be found on [readthedocs.org]. The [Open API specification] a.k.a. Kurento | ||
Protocol is also available on [apiary.io]. | ||
Source | ||
------ | ||
The source code of this project can be cloned from the [GitHub Repository]. | ||
Code for other Kurento projects can be found in the [GitHub Kurento Group]. | ||
@@ -101,14 +100,77 @@ | ||
---------------- | ||
Information about Kurento can be found on our [website]. | ||
Check the [Kurento blog] | ||
Follow us on Twitter @[kurentoms]. | ||
[GitHub Kurento group]: https://github.com/kurento | ||
Issue tracker | ||
------------- | ||
Issues and bug reports should be posted to the [GitHub Kurento bugtracker] | ||
Licensing and distribution | ||
-------------------------- | ||
Software associated to Kurento is provided as open source under GNU Library or | ||
"Lesser" General Public License, version 2.1 (LGPL-2.1). Please check the | ||
specific terms and conditions linked to this open source license at | ||
http://opensource.org/licenses/LGPL-2.1. Please note that software derived as a | ||
result of modifying the source code of Kurento software in order to fix a bug | ||
or incorporate enhancements is considered a derivative work of the product. | ||
Software that merely uses or aggregates (i.e. links to) an otherwise unmodified | ||
version of existing software is not considered a derivative work. | ||
Contribution policy | ||
------------------- | ||
You can contribute to the Kurento community through bug-reports, bug-fixes, new | ||
code or new documentation. For contributing to the Kurento community, drop a | ||
post to the [Kurento Public Mailing List] providing full information about your | ||
contribution and its value. In your contributions, you must comply with the | ||
following guidelines | ||
* You must specify the specific contents of your contribution either through a | ||
detailed bug description, through a pull-request or through a patch. | ||
* You must specify the licensing restrictions of the code you contribute. | ||
* For newly created code to be incorporated in the Kurento code-base, you must | ||
accept Kurento to own the code copyright, so that its open source nature is | ||
guaranteed. | ||
* You must justify appropriately the need and value of your contribution. The | ||
Kurento project has no obligations in relation to accepting contributions | ||
from third parties. | ||
* The Kurento project leaders have the right of asking for further | ||
explanations, tests or validations of any code contributed to the community | ||
before it being incorporated into the Kurento code-base. You must be ready to | ||
addressing all these kind of concerns before having your code approved. | ||
Support | ||
------- | ||
The Kurento project provides community support through the [Kurento Public | ||
Mailing List] and through [StackOverflow] using the tags *kurento* and | ||
*fiware-kurento*. | ||
Before asking for support, please read first the [Kurento Netiquette Guidelines] | ||
[documentation]: http://www.kurento.org/documentation | ||
[FIWARE]: http://www.fiware.org | ||
[GitHub Kurento bugtracker]: https://github.com/Kurento/bugtracker/issues | ||
[GitHub Kurento Group]: https://github.com/kurento | ||
[kurentoms]: http://twitter.com/kurentoms | ||
[Kurento]: http://kurento.org | ||
[Kurento Blog]: http://www.kurento.org/blog | ||
[Kurento FIWARE Catalog Entry]: http://catalogue.fiware.org/enablers/stream-oriented-kurento | ||
[Kurento Netiquette Guidelines]: http://www.kurento.org/blog/kurento-netiquette-guidelines | ||
[Kurento Public Mailing list]: https://groups.google.com/forum/#!forum/kurento | ||
[KurentoImage]: https://secure.gravatar.com/avatar/21a2a12c56b2a91c8918d5779f1778bf?s=120 | ||
[LGPL v2.1 License]: http://www.gnu.org/licenses/lgpl-2.1.html | ||
[NUBOMEDIA]: http://www.nubomedia.eu | ||
[StackOverflow]: http://stackoverflow.com/search?q=kurento | ||
[GitHub repository]: https://github.com/kurento/kurento-jsonrpc-js | ||
[grunt]: http://gruntjs.com/ | ||
[KurentoImage]: https://secure.gravatar.com/avatar/21a2a12c56b2a91c8918d5779f1778bf?s=120 | ||
[kurentoms]: http://twitter.com/kurentoms | ||
[LGPL License]: http://www.gnu.org/licenses/lgpl-2.1.html | ||
[Node.js project PPA]: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager#ubuntu-mint-elementary-os | ||
[NPM repository]: https://www.npmjs.org/package/kurento-jsonrpc | ||
[nodeunit]: https://github.com/caolan/nodeunit | ||
[website]: http://kurento.org | ||
[Read-the-docs]: http://read-the-docs.readthedocs.org/ | ||
[readthedocs.org]: http://kurento.readthedocs.org/ | ||
[Open API specification]: http://kurento.github.io/doc-kurento/ | ||
[apiary.io]: http://docs.streamoriented.apiary.io/ |
@@ -18,8 +18,9 @@ /* | ||
var nodeunit = require('nodeunit'); | ||
var EventTarget = require('eventtarget'); | ||
var RpcBuilder = require(".."); | ||
var JsonRpcClient = RpcBuilder.clients.JsonRpcClient; | ||
var packer = RpcBuilder.packers.JsonRPC; | ||
var ws_uri = "ws://localhost:8888/kurento"; | ||
@@ -31,3 +32,10 @@ const METHOD = 'test'; | ||
function connectCallback(){ | ||
connected = true; | ||
} | ||
function disconnectCallback(){ | ||
connected = false; | ||
} | ||
exports['encode JsonRPC 2.0'] = | ||
@@ -49,3 +57,2 @@ { | ||
'notification': function(test) | ||
@@ -463,3 +470,34 @@ { | ||
transport.dispatchEvent(event); | ||
}, | ||
'create JsonRpcClientWs with WS': function(test) | ||
{ | ||
test.expect(1); | ||
var configuration = { | ||
sendCloseMessage : false, | ||
ws : { | ||
uri : ws_uri, | ||
useSockJS: false, | ||
onconnected : connectCallback, | ||
ondisconnect : disconnectCallback, | ||
onreconnecting : disconnectCallback, | ||
onreconnected : connectCallback | ||
}, | ||
rpc : { | ||
requestTimeout : 15000 | ||
} | ||
}; | ||
var jsonRpcClientWs = new JsonRpcClient(configuration); | ||
test.ok(jsonRpcClientWs instanceof JsonRpcClient); | ||
setTimeout(function() | ||
{ | ||
jsonRpcClientWs.close(); | ||
test.done(); | ||
}, 4*1000) | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
106575
22
2035
173
14
2