Skip to content

Commit 7029e56

Browse files
author
Wasin Waeosri
committed
Merge branch 'b2_servicenamelogic'
1. Change service name to be an optional parameter 2. Change server port to 8080 3. Fix UI issue
2 parents c6e67c0 + 40d6585 commit 7029e56

6 files changed

Lines changed: 27 additions & 19 deletions

File tree

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
The web browsers JavaScript runtime is a single-threaded environment by default. However, the HTML standard lets developers implement multi threads JavaScript application in web browser by introducing the [Web Workers](https://html.spec.whatwg.org/multipage/workers.html) feature that lets web browsers run JavaScripts in a main thread and a background thread (workers thread).
77

8-
This example shows how to implement the Elektron WebSocket API with JavaScript web application with Web Workers. It lets the Web Workers thread handles a connection logic with ADS WebSocket while the main thread handles the UI interaction events and displaying data.
8+
This example shows how to implement the Elektron WebSocket API with JavaScript web application with Web Workers. It allows the Web Workers thread to handle the connection logic with ADS WebSocket server while the main thread handles the UI interaction events and displaying data.
99

1010
There are two types of the Web Workers, [Dedicated Workers](https://html.spec.whatwg.org/multipage/workers.html#dedicated-workers-and-the-worker-interface) and [Shared Workers](https://html.spec.whatwg.org/multipage/workers.html#sharedworker). This example covers only how to implement the Elektron WebSocket API with JavaScript web browser application with Dedicated Workers.
1111

@@ -16,13 +16,13 @@ The example supports Chrome, Firefox and IE11 (based on the WebSocket and Web Wo
1616

1717
## Prerequisite
1818
This example requires the following dependencies softwares.
19-
1. [Node.js](https://nodejs.org/en/) - version 6.10 or higher.
20-
2. [npm](https://www.npmjs.com/) package manager (included in Node.js)
21-
3. [Express.js](https://expressjs.com/) framework
19+
1. [Node.js](https://nodejs.org/en/) runtime - version 8.9.3 or higher.
20+
2. [npm](https://www.npmjs.com/) package manager (included with Node.js runtime)
21+
3. [Express.js](https://expressjs.com/) framework (will be installed via ```npm install``` command)
2222

2323
This example also uses the following 3rd party libraries for UI presentation.
24-
1. [jQuery 3.2.1](https://jquery.com/)
25-
2. [Bootstrap 3.3.7](https://getbootstrap.com/docs/3.3/)
24+
1. [jQuery 3.2.1](https://jquery.com/) JavaScript library
25+
2. [Bootstrap 3.3.7](https://getbootstrap.com/docs/3.3/) CSS library
2626

2727
jQuery,Bootstrap and Express.js are distributed under the [MIT license](https://opensource.org/licenses/MIT). Please see more detail in the LICENSE.md file.
2828

@@ -35,7 +35,7 @@ The web application contains the following example files and folder:
3535
5. libs/jquery-3.2.1.min.js: jQuery library file
3636
6. bootstrap/css, bootstarp/fonts and bootstrap/js folders: The folders for Bootstrap CSS and libraries files
3737
7. node_modules folder: Folder for Node.js and Express.js modules for web server running
38-
8. server.js: A web server application
38+
8. server.js: A simple web server application
3939
9. package.json: The Project npm dependencies file.
4040

4141
## How to run this example
@@ -45,18 +45,19 @@ The web application contains the following example files and folder:
4545
![npm command display](images/npm_install.png "npm command display")
4646

4747
3. If the machine is behind a proxy server, you need to configure Node.js uses proxy instead of a direct HTTP connection via the following command in command prompt: ```set https_proxy=http://<proxy.server>:<port>```
48-
4. Run ```$> node server.js``` in the command prompt to start the web server at HTTP port 3000
48+
4. Run ```$> node server.js``` in the command prompt to start the web server at HTTP port 8080
4949

5050
![application display](images/run_server.png "run server")
5151

52-
5. Open web browser (IE11, Chorme and Firefox), then navigate to index.html of the web server at ```http://localhost:3000/index.html```
52+
5. Open web browser (IE11, Chorme and Firefox), then navigate to index.html of the web server at ```http://localhost:8080/index.html```
5353

5454
![application display](images/application_screen.png "application display")
5555

5656

5757
## References
5858
For further details, please check out the following resources:
5959
* [Thomson Reuters Elektron WebSocket API page](https://developers.thomsonreuters.com/websocket-api) on the [Thomson Reuters Developer Community](https://developers.thomsonreuters.com/) web site.
60+
* [Developer Webinar Recording: Introduction to Electron Websocket API](https://www.youtube.com/watch?v=CDKWMsIQfaw)
6061
* [Mozilla Developer Network: Web Workers API page](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
6162
* [Google HTML5 Rocks: The Basics of Web Workers page](https://www.html5rocks.com/en/tutorials/workers/basics/)
6263

app/market_price_app.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494

9595
//$('#messagesPre').html(`Receive: STATUS_RESP:<br/> ${JSON.stringify(data, undefined, 2)}`); //Status_resp
9696
$('#messagesPre').html('Receive: STATUS_RESP:<br/>' + JSON.stringify(data, undefined, 2)); //Display Status_resp
97+
} else if (msgtype === 'Error'){//If incoming message is ERROR_RESP
98+
$('#messagesPre').html('Receive: ERROR_RESP:<br/>' + JSON.stringify(data, undefined, 2)); //Display Status_resp
9799
} else if (msgtype === 'Ping') { //If incoming message is PING (server ping)
98100

99101
//$('#messagesPre').html(`Recieve Ping:</br> ${JSON.stringify(data, undefined, 2)}`); //Server Ping
@@ -153,14 +155,19 @@
153155
} else {
154156
itemID += 1;
155157
}
156-
//create Market Price request message
158+
159+
160+
//create Market Price request message, if user does not set service name, let the ADS use default service
157161
let itemrequestMsg = {
158162
'ID': itemID,
159163
'Key': {
160-
'Name': itemname,
161-
'Service': service
164+
'Name': itemname
162165
}
163166
};
167+
//if user set service name, request interested service name
168+
if(service !==''){
169+
itemrequestMsg.Key.Service = service
170+
}
164171

165172
let itemrequestObj = {
166173
'commandObj': itemrequestMsg,

images/application_screen.png

-15.8 KB
Loading

images/run_server.png

-4.24 KB
Loading

index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@
3030
<h4>Thomson Reuters WebSocket API with Web Workers Example</h4>
3131
<form class="form-inline">
3232
<div class="form-group">
33-
<label for="txtServerurl">Server:</label> &nbsp; <input type="text" id="txtServerurl" class="form-control">&nbsp;&nbsp;
33+
<label for="txtServerurl">Server:</label> &nbsp; <input type="text" id="txtServerurl" placeholder="ADS IP:WebSocket Port" class="form-control">&nbsp;&nbsp;
3434
<button id="btnConnect" type="button" class="btn btn-sm btn-primary">Connect</button>
3535
</div>
3636
<br/><br/>
3737
<div class="form-group">
38-
<label for="txtUsername">User:</label> &nbsp; <input type="text" id="txtUsername" class="form-control">&nbsp;&nbsp;
38+
<label for="txtUsername" >User:</label> &nbsp; <input type="text" id="txtUsername" class="form-control" placeholder="user">&nbsp;&nbsp;
3939
<button id="btnLogin" type="button" class="btn btn-sm btn-primary">Login</button> &nbsp;&nbsp;
4040
<button id="btnLogout" type="button" class="btn btn-sm btn-primary">Logout</button>
4141
</div>
4242
<br/>
4343
<br/>
4444
<div class="form-group">
45-
<label for="txtServiceName">Name:</label> &nbsp; <input type="text" id="txtServiceName" value="ELEKTRON_DD"
46-
class="form-control"> &nbsp;&nbsp;
47-
<label for="txtItemName">Name:</label>&nbsp;
48-
<input type="text" id="txtItemName" value="" class="form-control"> &nbsp;&nbsp;
45+
<!--<label for="txtServiceName">Service Name:</label> &nbsp; <input type="text" id="txtServiceName" class="form-control"> &nbsp;&nbsp;-->
46+
<label for="txtItemName">Item Name:</label>&nbsp;
47+
<input type="text" id="txtItemName" value="" placeholder="TRI.N" class="form-control"> &nbsp;&nbsp;
48+
<label for="txtServiceName">Service Name:</label> &nbsp; <input type="text" id="txtServiceName" class="form-control" placeholder="[Optional]"> &nbsp;&nbsp;
4949
<button id="btnSubscribe" type="button" class="btn btn-sm btn-primary">Subscribe</button> &nbsp;&nbsp;
5050
<button id="btnUnSubscribe" type="button" class="btn btn-sm btn-primary">Unsubscribe</button>
5151
</div>

server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let path = require('path');
44
const web_path = path.join(__dirname, './');
55

66
const app = express();
7-
const port = 3000;
7+
const port = 8080;
88

99
app.use(express.static(web_path));
1010

0 commit comments

Comments
 (0)