Skip to content

Commit 1f89d3a

Browse files
author
Wasin Waeosri
committed
change logs:
1. Change code logic to let service name is an optional parameter 2. Revise README.md both grammar and detail 3. Revise UI of index.html
1 parent c6e67c0 commit 1f89d3a

3 files changed

Lines changed: 20 additions & 12 deletions

File tree

README.md

Lines changed: 4 additions & 3 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

@@ -18,7 +18,7 @@ The example supports Chrome, Firefox and IE11 (based on the WebSocket and Web Wo
1818
This example requires the following dependencies softwares.
1919
1. [Node.js](https://nodejs.org/en/) - version 6.10 or higher.
2020
2. [npm](https://www.npmjs.com/) package manager (included in Node.js)
21-
3. [Express.js](https://expressjs.com/) framework
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.
2424
1. [jQuery 3.2.1](https://jquery.com/)
@@ -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
@@ -57,6 +57,7 @@ The web application contains the following example files and folder:
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,

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" placeholder="userk">User:</label> &nbsp; <input type="text" id="txtUsername" class="form-control">&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>

0 commit comments

Comments
 (0)