Skip to content

Commit 709787e

Browse files
author
Wasin Waeosri
committed
Merge branch 'b1_expressCode'
1. Update project to run web server locally with nodejs and expressjs 2. Update project code to match ADS 3.2 WebSocket API 3. Revise README.md
2 parents b82912f + eefdd2c commit 709787e

8 files changed

Lines changed: 311 additions & 6 deletions

File tree

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,30 @@
11
# Elektron WebSocket API with Web Workers Example
22
## Overview
33

4-
[Elektron WebSocket API](https://developers.thomsonreuters.com/elektron/websocket-api) enables easy integration into a multitude of client technology environments such as scripting and web. This API runs directly on your TREP infrastructure or the Thomson Reuters platform and presents data in an open (JSON) readable format. The API supports all Thomson Reuters Elektron data models and can be integrated into multiple client technology standards e.g. Python, R, .Net etc.
4+
[Elektron WebSocket API](https://developers.thomsonreuters.com/websocket-api) enables easy integration into a multitude of client technology environments such as scripting and web. This API runs directly on your TREP infrastructure or the Thomson Reuters platform and presents data in an open (JSON) readable format. The API supports all Thomson Reuters Elektron data models and can be integrated into multiple client technology standards e.g. Python, R, .Net etc.
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

88
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.
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

12+
*Note: The initial release of this API is for deployed TREP customers only (i.e. to use it you will need an installed version of TREP 3.2).
13+
1214
## Supported Web Browsers
1315
The example supports Chrome, Firefox and IE11 (based on the WebSocket and Web Workers browser supported platform).
1416

1517
## Prerequisite
16-
This example uses the following 3rd party libraries.
18+
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
22+
23+
This example also uses the following 3rd party libraries for UI presentation.
1724
1. [jQuery 3.2.1](https://jquery.com/)
1825
2. [Bootstrap 3.3.7](https://getbootstrap.com/docs/3.3/)
1926

20-
Both of jQuery and Bootstrap are distributed under the [MIT license](https://opensource.org/licenses/MIT). Please see more detail in the LICENSE.md file.
27+
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.
2128

2229
## Example files and folders
2330
The web application contains the following example files and folder:
@@ -27,14 +34,29 @@ The web application contains the following example files and folder:
2734
4. css/cover.css: The application CSS file
2835
5. libs/jquery-3.2.1.min.js: jQuery library file
2936
6. bootstrap/css, bootstarp/fonts and bootstrap/js folders: The folders for Bootstrap CSS and libraries files
37+
7. node_modules folder: Folder for Node.js and Express.js modules for web server running
38+
8. server.js: A web server application
39+
9. package.json: The Project npm dependencies file.
3040

3141
## How to run this example
32-
1. Deploy the project in any web server (recommend [http-server](https://www.npmjs.com/package/http-server) for quick dev/testing)
33-
2. Open <web server>/index.html in the web browsers (IE11, Chorme and Firefox)
42+
1. Unzip or download the example project folder into a directory of your choice
43+
2. Run ```$> npm install``` in the command prompt to install all the dependencies required to run the sample in a subdirectory called *node_modules/*.
44+
45+
![npm command display](images/npm_install.png "npm command display")
46+
47+
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
49+
50+
![application display](images/run_server.png "run server")
51+
52+
5. Open web browser (IE11, Chorme and Firefox), then navigate to index.html of the web server at ```http://localhost:300/index.html```
53+
54+
![application display](images/application_screen.png "application display")
55+
3456

3557
## References
3658
For further details, please check out the following resources:
37-
* [Thomson Reuters Elektron WebSocket API page](https://developers.thomsonreuters.com/elektron/websocket-api) on the [Thomson Reuters Developer Community](https://developers.thomsonreuters.com/) web site.
59+
* [Thomson Reuters Elektron WebSocket API page](https://developers.thomsonreuters.com/websocket-api) on the [Thomson Reuters Developer Community](https://developers.thomsonreuters.com/) web site.
3860
* [Mozilla Developer Network: Web Workers API page](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API).
3961
* [Google HTML5 Rocks: The Basics of Web Workers page](https://www.html5rocks.com/en/tutorials/workers/basics/)
4062

images/application_screen.png

108 KB
Loading

images/npm_install.png

25.4 KB
Loading

images/run_server.png

23.9 KB
Loading

node_modules/.gitignore

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 249 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "elecktron_ws_worker",
3+
"version": "1.0.0",
4+
"description": "The example project that provides how to implement JavaScript applicatiion with Web Workers for Elektron WebSocket API",
5+
"main": "server.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "Wasin Waeosri <wasin.waeosri@thomsonreuters.com> (https://developers.thomsonreuters.com/)",
10+
"license": "MIT",
11+
"dependencies": {
12+
"express": "^4.16.2"
13+
}
14+
}

server.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const express = require('express');
2+
let path = require('path');
3+
4+
const web_path = path.join(__dirname, './');
5+
6+
const app = express();
7+
const port = 3000;
8+
9+
app.use(express.static(web_path));
10+
11+
app.get("*", function(req,res){
12+
res.sendFile(path.join(web_path,"index.html"));
13+
});
14+
15+
16+
app.listen(port, ()=> console.log(`Application is running at port ${port}`));

0 commit comments

Comments
 (0)