diff --git a/hyco-ws/hyco-ws-tests.ts b/hyco-ws/hyco-ws-tests.ts new file mode 100644 index 0000000000..05b500d81c --- /dev/null +++ b/hyco-ws/hyco-ws-tests.ts @@ -0,0 +1,21 @@ +import * as WebSocket from 'ws'; +import * as AzureRelay from 'hyco-ws'; + +const wss = AzureRelay.createRelayedServer( + { + server: AzureRelay.createRelayListenUri('uri_namespace', 'uri_path'), + token: AzureRelay.createRelayToken( + 'http://exampleurl.com}', + 'key_rule', + 'key') + }, + (ws: WebSocket) => { + console.log('New connection accepted'); + ws.onmessage = (event: any) => { + console.log('New message!!'); + }; + }); + +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 new file mode 100644 index 0000000000..053c7fba18 --- /dev/null +++ b/hyco-ws/index.d.ts @@ -0,0 +1,27 @@ +// Type definitions for hyco-ws 1.0 +// Project: https://github.com/Azure/azure-relay-node +// Definitions by: Manuel Rodrigo Cabello +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as WebSocket from 'ws'; + +export class HybridConnectionWebSocketServer extends NodeJS.EventEmitter { + constructor(options: any); + close(callback: () => void): void; + listenUri: string; + closeRequested: boolean; + options: any; + path: string; + clients: WebSocket[]; + controlChannel: WebSocket; +} + +export function createRelayedServer(options: any, 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; \ No newline at end of file diff --git a/hyco-ws/tsconfig.json b/hyco-ws/tsconfig.json new file mode 100644 index 0000000000..a625ff1bab --- /dev/null +++ b/hyco-ws/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "experimentalDecorators": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "hyco-ws-tests.ts" + ] +} \ No newline at end of file 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