Skip to content

Commit 1ed1674

Browse files
author
Wasin Waeosri
committed
Merge branch 'v6_restructure'
1. Update the application to the update version that includes all dependencies, restructure project and README.md file
2 parents 363d4ef + c32e932 commit 1ed1674

36 files changed

+10597
-168
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
greeter.ts
22
greeter.js
3-
package.json
4-
node_modules/
53
greeter.html
4+
index_bulma.html

LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 Thomson Reuters
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Elecktron WebSocket API with TypeScript Example
2+
## Overview
3+
4+
[Elektron WebSocket API](https://developers.thomsonreuters.com/elektron/websocket-api-early-access) 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.
5+
6+
[TypeScript](https://www.typescriptlang.org) programming language is a typed superset of JavaScript that compiles to readable, standards-based JavaScript. The language is designed for application-scale JavaScript by adding optional types, classes, modules, ECMAScript 2015 features and future proposals to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript is as a first-class programming language in Microsoft Visual Studio, [Angular](https://angularjs.org/) web application platform. It also supported by various application frameworks like [React](https://github.com/Microsoft/TypeScript-React-Starter#typescript-react-starter), [NodeJS and Express framework](https://github.com/Microsoft/TypeScript-Node-Starter#typescript-node-starter), [ASP.Net Core](https://www.typescriptlang.org/docs/handbook/asp-net-core.html), [Vue.js](https://github.com/Microsoft/TypeScript-Vue-Starter#typescript-vue-starter) and more.
7+
8+
This example shows how to implement the Elektron WebSocket API JavaScript web application with TypeScript. The web application source codes are implemented in TypeScript language to connect, consume and display data from the ADS server via the Elektron WebSocket API in the web browsers. All source codes will be compiled to readable JavaScript with [Webpack](https://webpack.js.org/) JavaScript module bundler.
9+
10+
## Supported Web Browsers
11+
The example supports Chrome, Firefox and IE11 (based on the WebSocket and Web Workers browser supported platform).
12+
13+
## Prerequisite
14+
This example requires the following dependencies softwares.
15+
1. [Node.js](https://nodejs.org/en/) - version 6.10 or higher.
16+
2. [npm](https://www.npmjs.com/) package manager (included in Node.js)
17+
2. [TypeScript](https://www.typescriptlang.org)
18+
19+
This example also uses the following 3rd party libraries for UI presentation.
20+
1. [jQuery 3.2.1](https://jquery.com/)
21+
2. [Bootstrap 3.3.7](https://getbootstrap.com/docs/3.3/)
22+
23+
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.
24+
25+
## Package
26+
The project includes complete TypeScript source code, CSS files and all required static dependencies. The dynamic dependencies for compiling and building JavaScript source file are defined in *package.json* file which can be installed via ```npm install``` command.
27+
28+
The project includes the following files and folder
29+
- *src/* folder: The folder that contains all TypeScript source files
30+
- *web/* folder: The folder that contains all application web page files
31+
- *web/dist* folder: The folder that the compiled JavaScript file named *web_app.js* will be generated
32+
- *web/index.html*: The application HTML page
33+
- *web/css/cover.css*: The application CSS file
34+
- *web/libs/jquery-3.2.1.min.js*: jQuery library file
35+
- *web/bootstrap/css*, *web/bootstarp/fonts* and *web/bootstrap/js* folders: The folders for Bootstrap CSS and libraries files
36+
- package.json: Project's NPM dependencies file
37+
- tsconfig.json: Project's TypeSccript compiler options file
38+
- webpack.config.js: Project's Webpack compiler options file
39+
40+
41+
## How to run this example application
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 ```$> webpack``` in the command prompt to build and compile all TypeScript files in *src* into JavaScript source file (*/web/dist/* folder)
49+
50+
![webpack command display](images/webpack.png "webpack command display")
51+
52+
5. Copy and deploy the *web* folder into in any web server (recommend [http-server](https://www.npmjs.com/package/http-server) for quick dev/testing)
53+
6. Open web browser, then navigate to index.html of the web server (example for http-server: ```hhttp://localhost:8080/index.html```)
54+
55+
![application display](images/application.png "application display")
56+
57+
## References
58+
For further details, please check out the following resources:
59+
* [Thomson Reuters Elektron WebSocket API page](https://developers.thomsonreuters.com/elektron/websocket-api-early-access) on the [Thomson Reuters Developer Community](https://developers.thomsonreuters.com/) web site.
60+
* [TypeScript programming language: Documentation](https://www.typescriptlang.org/docs/home.html).
61+
* [Mozilla Developer Network: Web Workers API page](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
62+
63+
For any question related to this article or Elektron WebSocket API page, please use the Developer Community [Q&A Forum](https://community.developers.thomsonreuters.com/).

images/application.PNG

75.1 KB
Loading

images/npm_install.png

26.5 KB
Loading

images/webpack.PNG

41.4 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.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "elektron_ws_typescript",
3+
"version": "1.0.0",
4+
"description": "A simple project that demonstrates how to implement Elektron WebSocket with TypeScript",
5+
"main": "index.html",
6+
"dependencies": {
7+
"@types/websocket": "0.0.34"
8+
},
9+
"devDependencies": {
10+
"awesome-typescript-loader": "^3.4.0",
11+
"source-map-loader": "^0.2.3",
12+
"typescript": "^2.6.1",
13+
"webpack": "^3.8.1"
14+
},
15+
"scripts": {
16+
"test": "echo \"Error: no test specified\" && exit 1"
17+
},
18+
"author": "Wasin Waeosri <wasin.waeosri@thomsonreuters.com> (https://developers.thomsonreuters.com/)",
19+
"license": "MIT"
20+
}

src/json_msg_classes.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import { JSONLogin } from "./json_msg_interface";
2+
import { JSONLoginKey } from "./json_msg_interface";
3+
import { JSONLoginKeyElements } from "./json_msg_interface";
4+
5+
import { JSONItemRequestMsg } from "./json_msg_interface";
6+
import { JSONItemRequestKey } from "./json_msg_interface";
7+
8+
import { JSONClose } from "./json_msg_interface";
9+
10+
export { LoginMsg };
11+
export { ItemRequestMsg };
12+
export {CloseMsg};
13+
14+
const loginDomain: string = "Login";
15+
16+
class LoginMsg implements JSONLogin {
17+
Id: number;
18+
Domain: string = loginDomain;
19+
Key: JSONLoginKey;
20+
21+
constructor(
22+
Id: number,
23+
Name: string,
24+
ApplicationId: string,
25+
Position: string
26+
) {
27+
this.Id = Id;
28+
let loginMsgKey_class = new LoginMsgKey(Name, ApplicationId, Position);
29+
this.Key = loginMsgKey_class;
30+
}
31+
}
32+
33+
class LoginKeyElements implements JSONLoginKeyElements {
34+
ApplicationId: string;
35+
Position: string;
36+
constructor(ApplicationId: string, Position: string) {
37+
this.ApplicationId = ApplicationId;
38+
this.Position = Position;
39+
}
40+
}
41+
42+
class LoginMsgKey implements JSONLoginKey {
43+
Name: string;
44+
Elements: JSONLoginKeyElements;
45+
constructor(Name: string, ApplicationId: string, Position: string) {
46+
this.Name = Name;
47+
let loginKeyElements_class = new LoginKeyElements(ApplicationId, Position);
48+
this.Elements = loginKeyElements_class;
49+
}
50+
}
51+
52+
class ItemRequestMsg implements JSONItemRequestMsg {
53+
Id: number;
54+
Key: JSONItemRequestKey;
55+
constructor(Id: number, Name: string, Service: string) {
56+
this.Id = Id;
57+
let itemrequestKey_class = new ItemRequestMsgKey(Name, Service);
58+
this.Key = itemrequestKey_class;
59+
}
60+
}
61+
62+
class ItemRequestMsgKey implements JSONItemRequestKey {
63+
Name: string;
64+
Service: string;
65+
66+
constructor(Name: string, Service: string) {
67+
this.Name = Name;
68+
this.Service = Service;
69+
}
70+
}
71+
72+
73+
class CloseMsg implements JSONClose{
74+
Domain?: string;
75+
Id: number;
76+
Type: string;
77+
78+
constructor(Id: number, Domain?: string) {
79+
this.Id = Id;
80+
this.Domain = Domain;
81+
this.Type = "Close";
82+
}
83+
84+
}

src/json_msg_interface.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//Interface for Login domain JSON message
2+
export interface JSONLogin {
3+
Id:number;
4+
Domain:string;
5+
Key: JSONLoginKey;
6+
}
7+
8+
//Interface for Login domain's Key attribute JSON message
9+
export interface JSONLoginKey{
10+
Elements: JSONLoginKeyElements;
11+
Name: string;
12+
}
13+
14+
//Interface for Login domain's Key's Elements attribute JSON message
15+
export interface JSONLoginKeyElements{
16+
ApplicationId: string;
17+
Position: string;
18+
}
19+
20+
//Interface for Market Price domain item request JSON message
21+
export interface JSONItemRequestMsg {
22+
Id: number;
23+
Key: JSONItemRequestKey;
24+
}
25+
26+
//Interface for Market Price domain item request's key attribute JSON message
27+
export interface JSONItemRequestKey {
28+
Name: string;
29+
Service: string;
30+
}
31+
32+
//Interface for close JSON message
33+
export interface JSONClose {
34+
Domain?: string;
35+
Id: number;
36+
Type: string;
37+
}

0 commit comments

Comments
 (0)