Skip to content

Commit

Permalink
Introduce command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-weswit committed Jan 29, 2019
1 parent e5c3b7a commit 6d68ec4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ If you want to install a version of this demo in your local Lightstreamer Server
* Alternatively, you may plug the *robust* versions of the Proxy Data Adapter: go to the `deployment/Deployment_LS(robust)` folder and copy the `ChatAdapterNode` directory and all of its files into the `adapters` folder.
* Install the lightstreamer-adapter module.
* Create a directory where to deploy the Node.js Remote Adapter and let call it `Deployment_Node_Remote_Adapter`.
* Go to the `Deployment_Node_Remote_Adapter` folder and launch the command:<BR/>
* Go to the `Deployment_Node_Remote_Adapter` folder and launch the commands:<BR/>
`> npm install lightstreamer-adapter`<BR/>
`> npm install command-line-args`<BR/>
* Download the `nodechat.js` and the `robustconnect.js` files from this project and copy them into the `Deployment_Node_Remote_Adapter` folder.
* Launch Lightstreamer Server. The Server startup will complete only after a successful connection between the Proxy Data Adapter and the Remote Data Adapter.
* Launch the Node.js Remote Adapter: go to the `Deployment_Node_Remote_Adapter` folder and launch:<BR/>
`> node nodechat.js`<BR/>
`> node nodechat.js --host localhost --metadata_rrport 8003 --data_rrport 8001 --data_notifport 8002`<BR/>
* Test the Adapter, launching the [Lightstreamer - Basic Chat Demo - HTML Client](https://github.com/Lightstreamer/Lightstreamer-example-Chat-client-javascript) listed in [Clients Using This Adapter](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-node#clients-using-this-adapter).
* To make the [Lightstreamer - Basic Chat Demo - HTML Client](https://github.com/Lightstreamer/Lightstreamer-example-Chat-client-javascript) front-end pages get data from the newly installed Adapter Set, you need to modify the front-end pages and set the required Adapter Set name to PROXY_NODECHAT when creating the LightstreamerClient instance. So edit the `lsClient.js` file of the *Basic Chat Demo* front-end deployed under `Lightstreamer/pages/ChatDemo` and replace:<BR/>
`var lsClient = new LightstreamerClient(protocolToUse+"//localhost:"+portToUse,"CHAT");`<BR/>
Expand Down Expand Up @@ -94,5 +95,5 @@ should become like this:<BR/>

## Lightstreamer Compatibility Notes

* Compatible with Lightstreamer SDK for Node.js Adapters since 1.3
* Compatible with Lightstreamer SDK for Node.js Adapters version 1.3 or newer
- For a version of this example compatible with Lightstreamer SDK for Node.js Adapters version 1.0, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-node/tree/for_Lightstreamer_5.1).
24 changes: 14 additions & 10 deletions nodechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ var
DataProvider = require('lightstreamer-adapter').DataProvider,
net = require('./robustconnect'),
inspect = require('util').inspect,

// Remote proxy host and ports
HOST = 'localhost',
REQ_RESP_PORT = 8001,
WRITE_PORT = 8002,
META_PORT = 8003,
commandLineArgs = require('command-line-args'),

// Request/response socket channel
reqRespStream,
Expand All @@ -46,21 +41,30 @@ var

// User data just for the demo
sessions = [];

const optionDefinitions = [
{ name: 'host', type: String },
{ name: 'metadata_rrport', type: Number },
{ name: 'data_rrport', type: Number },
{ name: 'data_notifport', type: Number },
];

const options = commandLineArgs(optionDefinitions);

// Create socket connections
net.createConnection(REQ_RESP_PORT, HOST, function(stream) {
net.createConnection(options.data_rrport, options.host, function(stream) {
reqRespStream = stream;
if(notifyStream) {
initDataProvider();
}
});
net.createConnection(WRITE_PORT, HOST, function(stream) {
net.createConnection(options.data_notifport, options.host, function(stream) {
notifyStream = stream;
if(reqRespStream) {
initDataProvider();
}
});
net.createConnection(META_PORT, HOST, function(stream) {
net.createConnection(options.metadata_rrport, options.host, function(stream) {
metadataStream = stream;
initMetadataProvider();
});
Expand All @@ -75,7 +79,7 @@ function initDataProvider() {
console.log("Subcribed item: " + itemName);
if (itemName === "chat_room") {
subscribed = true;
response.success();
response.success();
} else {
response.error("No such item", "subscription");
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lightstreamer-adapter-chat",
"version": "1.0.0",
"version": "1.1.0",
"description": "Hello world application showing how to develop simple Lightstreamer adapters based on node.",
"keywords": [
"lightstreamer",
Expand Down Expand Up @@ -40,6 +40,7 @@
],

"dependencies": {
"command-line-args": "^5.0.2",
"lightstreamer-adapter": ">=1.3.0"
}
}

0 comments on commit 6d68ec4

Please sign in to comment.