From f3c1ece3d9a1b7ce2daf020c1d54ce30a527647d Mon Sep 17 00:00:00 2001 From: Rodrigo Cabello Date: Thu, 2 Feb 2017 15:39:11 +0100 Subject: [PATCH 1/4] creating hyco-ws definition type file --- hyco-ws/hyco-ws-tests.ts | 20 ++++++++++++++++++++ hyco-ws/index.d.ts | 39 +++++++++++++++++++++++++++++++++++++++ hyco-ws/tsconfig.json | 23 +++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 hyco-ws/hyco-ws-tests.ts create mode 100644 hyco-ws/index.d.ts create mode 100644 hyco-ws/tsconfig.json diff --git a/hyco-ws/hyco-ws-tests.ts b/hyco-ws/hyco-ws-tests.ts new file mode 100644 index 0000000000..c44632f784 --- /dev/null +++ b/hyco-ws/hyco-ws-tests.ts @@ -0,0 +1,20 @@ +import * as WebSocketRelay from 'hyco-ws'; + +let wss = WebSocketRelay.createRelayedServer( + { + server: WebSocketRelay.createRelayListenUri('uri_namespace', 'uri_path'), + token: WebSocketRelay.createRelayToken( + 'http://exampleurl.com}', + 'key_rule', + 'key') + }, + (ws: WebSocket) => { + console.log('New connection accepted'); + ws.onmessage = function (event) { + console.log('New message!!'); + }; + }); + +wss.on('error', function (err) { + console.log('error' + err); +}); \ No newline at end of file diff --git a/hyco-ws/index.d.ts b/hyco-ws/index.d.ts new file mode 100644 index 0000000000..0155ea557c --- /dev/null +++ b/hyco-ws/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for hyco-ws +// Project: https://github.com/Azure/azure-relay-node +// Definitions by: Manuel Rodrigo Cabello +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +/// + +declare module 'hyco-ws' { + + namespace WebSocketRelay { + + class HybridConnectionWebSocketServer extends NodeJS.EventEmitter { + constructor(options: Object); + close(callback: () => void): void; + listenUri: string; + closeRequested: boolean; + options: Object; + path: string; + clients: Array; + controlChannel: WebSocket; + } + + interface RealyConnection { + + createRelayedServer(options: Object, fn: (ws: WebSocket) => void): HybridConnectionWebSocketServer; + relayedConnect(address: string, fn: () => void): WebSocket; + createRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; + appendRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; + createRelayBaseUri(serviceBusNamespace: string, path: string): string; + createRelaySendUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; + createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any); + } + } + + var RelayConnection: WebSocketRelay.RealyConnection; + + export = RelayConnection; +} \ No newline at end of file diff --git a/hyco-ws/tsconfig.json b/hyco-ws/tsconfig.json new file mode 100644 index 0000000000..0d67bbf8da --- /dev/null +++ b/hyco-ws/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": false, + "experimentalDecorators": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hyco-ws-tests.ts" + ] +} \ No newline at end of file From f777faceb46611006e3022e72e84945f95875b18 Mon Sep 17 00:00:00 2001 From: Rodrigo Cabello Date: Thu, 2 Feb 2017 16:03:29 +0100 Subject: [PATCH 2/4] fixing typings --- hyco-ws/hyco-ws-tests.ts | 7 ++++--- hyco-ws/index.d.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hyco-ws/hyco-ws-tests.ts b/hyco-ws/hyco-ws-tests.ts index c44632f784..d24aa85c2c 100644 --- a/hyco-ws/hyco-ws-tests.ts +++ b/hyco-ws/hyco-ws-tests.ts @@ -1,6 +1,7 @@ import * as WebSocketRelay from 'hyco-ws'; +import * as WebSocket from 'ws'; -let wss = WebSocketRelay.createRelayedServer( +const wss: any = WebSocketRelay.createRelayedServer( { server: WebSocketRelay.createRelayListenUri('uri_namespace', 'uri_path'), token: WebSocketRelay.createRelayToken( @@ -10,11 +11,11 @@ let wss = WebSocketRelay.createRelayedServer( }, (ws: WebSocket) => { console.log('New connection accepted'); - ws.onmessage = function (event) { + ws.onmessage = (event: any) => { console.log('New message!!'); }; }); -wss.on('error', function (err) { +wss.on('error', (err: any) => { console.log('error' + err); }); \ No newline at end of file diff --git a/hyco-ws/index.d.ts b/hyco-ws/index.d.ts index 0155ea557c..413f883c1e 100644 --- a/hyco-ws/index.d.ts +++ b/hyco-ws/index.d.ts @@ -29,7 +29,7 @@ declare module 'hyco-ws' { appendRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; createRelayBaseUri(serviceBusNamespace: string, path: string): string; createRelaySendUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; - createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any); + createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; } } From a6cdd96ada223dfe8d6fc859148682467e48191a Mon Sep 17 00:00:00 2001 From: Rodrigo Cabello Date: Thu, 2 Feb 2017 18:59:49 +0100 Subject: [PATCH 3/4] adding web sockets definitions --- hyco-ws/hyco-ws-tests.ts | 8 ++++---- hyco-ws/index.d.ts | 30 ++++++++++++------------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/hyco-ws/hyco-ws-tests.ts b/hyco-ws/hyco-ws-tests.ts index d24aa85c2c..05b500d81c 100644 --- a/hyco-ws/hyco-ws-tests.ts +++ b/hyco-ws/hyco-ws-tests.ts @@ -1,10 +1,10 @@ -import * as WebSocketRelay from 'hyco-ws'; import * as WebSocket from 'ws'; +import * as AzureRelay from 'hyco-ws'; -const wss: any = WebSocketRelay.createRelayedServer( +const wss = AzureRelay.createRelayedServer( { - server: WebSocketRelay.createRelayListenUri('uri_namespace', 'uri_path'), - token: WebSocketRelay.createRelayToken( + server: AzureRelay.createRelayListenUri('uri_namespace', 'uri_path'), + token: AzureRelay.createRelayToken( 'http://exampleurl.com}', 'key_rule', 'key') diff --git a/hyco-ws/index.d.ts b/hyco-ws/index.d.ts index 413f883c1e..d6b07d4422 100644 --- a/hyco-ws/index.d.ts +++ b/hyco-ws/index.d.ts @@ -3,12 +3,12 @@ // Definitions by: Manuel Rodrigo Cabello // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// /// -declare module 'hyco-ws' { - namespace WebSocketRelay { +import * as WebSocket from 'ws'; + +declare namespace hycows { class HybridConnectionWebSocketServer extends NodeJS.EventEmitter { constructor(options: Object); @@ -21,19 +21,13 @@ declare module 'hyco-ws' { controlChannel: WebSocket; } - interface RealyConnection { + export function createRelayedServer(options: Object, fn: (ws: WebSocket) => void): HybridConnectionWebSocketServer; + export function relayedConnect(address: string, fn: () => void): WebSocket; + export function createRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; + export function appendRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; + export function createRelayBaseUri(serviceBusNamespace: string, path: string): string; + export function createRelaySendUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; + export function createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; +} - createRelayedServer(options: Object, fn: (ws: WebSocket) => void): HybridConnectionWebSocketServer; - relayedConnect(address: string, fn: () => void): WebSocket; - createRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; - appendRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; - createRelayBaseUri(serviceBusNamespace: string, path: string): string; - createRelaySendUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; - createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; - } - } - - var RelayConnection: WebSocketRelay.RealyConnection; - - export = RelayConnection; -} \ No newline at end of file +export = hycows; \ No newline at end of file From b2282a583592d3976af68653f7608f9b562e11ab Mon Sep 17 00:00:00 2001 From: Rodrigo Cabello Date: Thu, 2 Feb 2017 18:59:49 +0100 Subject: [PATCH 4/4] adding web sockets definitions --- hyco-ws/hyco-ws-tests.ts | 8 ++++---- hyco-ws/index.d.ts | 30 ++++++++++++------------------ hyco-ws/tsconfig.json | 2 +- hyco-ws/tslint.json | 1 + 4 files changed, 18 insertions(+), 23 deletions(-) create mode 100644 hyco-ws/tslint.json diff --git a/hyco-ws/hyco-ws-tests.ts b/hyco-ws/hyco-ws-tests.ts index d24aa85c2c..05b500d81c 100644 --- a/hyco-ws/hyco-ws-tests.ts +++ b/hyco-ws/hyco-ws-tests.ts @@ -1,10 +1,10 @@ -import * as WebSocketRelay from 'hyco-ws'; import * as WebSocket from 'ws'; +import * as AzureRelay from 'hyco-ws'; -const wss: any = WebSocketRelay.createRelayedServer( +const wss = AzureRelay.createRelayedServer( { - server: WebSocketRelay.createRelayListenUri('uri_namespace', 'uri_path'), - token: WebSocketRelay.createRelayToken( + server: AzureRelay.createRelayListenUri('uri_namespace', 'uri_path'), + token: AzureRelay.createRelayToken( 'http://exampleurl.com}', 'key_rule', 'key') diff --git a/hyco-ws/index.d.ts b/hyco-ws/index.d.ts index 413f883c1e..d6b07d4422 100644 --- a/hyco-ws/index.d.ts +++ b/hyco-ws/index.d.ts @@ -3,12 +3,12 @@ // Definitions by: Manuel Rodrigo Cabello // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -/// /// -declare module 'hyco-ws' { - namespace WebSocketRelay { +import * as WebSocket from 'ws'; + +declare namespace hycows { class HybridConnectionWebSocketServer extends NodeJS.EventEmitter { constructor(options: Object); @@ -21,19 +21,13 @@ declare module 'hyco-ws' { controlChannel: WebSocket; } - interface RealyConnection { + export function createRelayedServer(options: Object, fn: (ws: WebSocket) => void): HybridConnectionWebSocketServer; + export function relayedConnect(address: string, fn: () => void): WebSocket; + export function createRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; + export function appendRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; + export function createRelayBaseUri(serviceBusNamespace: string, path: string): string; + export function createRelaySendUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; + export function createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; +} - createRelayedServer(options: Object, fn: (ws: WebSocket) => void): HybridConnectionWebSocketServer; - relayedConnect(address: string, fn: () => void): WebSocket; - createRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; - appendRelayToken(uri: string, key_name: string, key: string, expiry?: number): string; - createRelayBaseUri(serviceBusNamespace: string, path: string): string; - createRelaySendUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; - createRelayListenUri(serviceBusNamespace: string, path: string, token?: any, id?: any): string; - } - } - - var RelayConnection: WebSocketRelay.RealyConnection; - - export = RelayConnection; -} \ No newline at end of file +export = hycows; \ No newline at end of file diff --git a/hyco-ws/tsconfig.json b/hyco-ws/tsconfig.json index 0d67bbf8da..a625ff1bab 100644 --- a/hyco-ws/tsconfig.json +++ b/hyco-ws/tsconfig.json @@ -6,7 +6,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "experimentalDecorators": true, "baseUrl": "../", "typeRoots": [ diff --git a/hyco-ws/tslint.json b/hyco-ws/tslint.json new file mode 100644 index 0000000000..2221e40e4a --- /dev/null +++ b/hyco-ws/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" } \ No newline at end of file