From 0b991edc75a2082ae8e4cdc1ebe05cf2bbd46f3e Mon Sep 17 00:00:00 2001 From: James Date: Thu, 31 Aug 2017 18:38:48 +0200 Subject: [PATCH 1/3] Initial API without namespaces. --- types/peer-dial/index.d.ts | 98 ++++++++++++++++++++++++++++++ types/peer-dial/peer-dial-tests.ts | 1 + types/peer-dial/tsconfig.json | 22 +++++++ types/peer-dial/tslint.json | 1 + 4 files changed, 122 insertions(+) create mode 100644 types/peer-dial/index.d.ts create mode 100644 types/peer-dial/peer-dial-tests.ts create mode 100644 types/peer-dial/tsconfig.json create mode 100644 types/peer-dial/tslint.json diff --git a/types/peer-dial/index.d.ts b/types/peer-dial/index.d.ts new file mode 100644 index 0000000000..1c638ab3d4 --- /dev/null +++ b/types/peer-dial/index.d.ts @@ -0,0 +1,98 @@ +/** Declaration file generated by dts-gen */ + +/// +/// +/// + +import * as events from "events"; +import * as express from "express"; +import * as uuid from "node-uuid"; + +//TODO: Needs namespaces for all of this. + +export class Server extends events.EventEmitter{ + constructor(options: ServerOptions); + + start(): void; + + stop(): void; + + corsOptionsAppsDelegate(req: string, callback: (err: any, data: CorsOptions) => void): void; + +} + +export interface CorsOptions { + origin: boolean; + methods: string[]; + exposedHeaders: string[]; +} + +export interface ServerOptions { + expressApp: express.Express; + prefix: string; + port: number; + host: string; + uuid: uuid.UUIDOptions; + friendlyName: string; + manufacturer: string; + modelName: string; + maxContentLength: number; + extraHeaders: Object; + delegate: Delegate; + corsAllowOrigins: boolean; +} + +export class Delegate { + + getApp(appName: string) : App; + + launchApp(appName: string, launchData: string, callback: (data: string) => void) : void; + + stopApp(appName: string, pid: string, callback: (data: boolean) => void) : void; +} + +export interface App { + name: string; + state: string; + allowStop: boolean; + pid: string; + + launch(launchData: string): void; +} + +export class Client extends events.EventEmitter { + constructor(); + + getDialDevice(deviceDescriptionUrl: string, callback?: (data: DialDevice, err: any) => void) : void; + + start() : void; + + refresh() : void; + + stop() : void; +} + +export class DialDevice { + constructor(deviceInfo: DeviceInfo); + + getAppInfoXml(appName: string, callback?: (data: string, err: any) => void) :void; + + getAppInfo(appName: string, callback?: (data: Object, err: any) => void): void; + + launchApp(appName: string, launchData: string, contentType: string, callback?: (data: string, err: any) => void): void; + + stopApp(appName: string, pid: string, callback?: (data: number, err: any) => void): void; +} + +interface DeviceInfo { + descriptionUrl: string; + applicationUrl: string; + deviceType: string; + friendlyName: string; + manufacturer: string; + modelName: string; + UDN: string; + iconList: Object[] | { + icon: Object + }; +} diff --git a/types/peer-dial/peer-dial-tests.ts b/types/peer-dial/peer-dial-tests.ts new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/types/peer-dial/peer-dial-tests.ts @@ -0,0 +1 @@ + diff --git a/types/peer-dial/tsconfig.json b/types/peer-dial/tsconfig.json new file mode 100644 index 0000000000..5cfd0105d1 --- /dev/null +++ b/types/peer-dial/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "peer-dial-tests.ts" + ] +} diff --git a/types/peer-dial/tslint.json b/types/peer-dial/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/peer-dial/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From fa09c672de4658e456f472c3ffa51a62e8d1e436 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 6 Sep 2017 17:46:08 +0200 Subject: [PATCH 2/3] Did more work on typings. --- types/peer-dial/index.d.ts | 54 +++++++++++++++---------- types/peer-dial/peer-dial-tests.ts | 64 ++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 22 deletions(-) diff --git a/types/peer-dial/index.d.ts b/types/peer-dial/index.d.ts index 1c638ab3d4..1e01f3b287 100644 --- a/types/peer-dial/index.d.ts +++ b/types/peer-dial/index.d.ts @@ -1,4 +1,6 @@ -/** Declaration file generated by dts-gen */ +// Type definitions for peer-dial 0.0.7 +// Project: https://github.com/fraunhoferfokus/peer-dial +// Definitions by: James Tooley /// /// @@ -8,9 +10,7 @@ import * as events from "events"; import * as express from "express"; import * as uuid from "node-uuid"; -//TODO: Needs namespaces for all of this. - -export class Server extends events.EventEmitter{ +export class Server extends events.EventEmitter { constructor(options: ServerOptions); start(): void; @@ -31,24 +31,24 @@ export interface ServerOptions { expressApp: express.Express; prefix: string; port: number; - host: string; - uuid: uuid.UUIDOptions; - friendlyName: string; + host?: string; + uuid?: uuid.UUIDOptions; + friendlyName?: string; manufacturer: string; modelName: string; - maxContentLength: number; - extraHeaders: Object; + maxContentLength?: number; + extraHeaders?: Object; delegate: Delegate; - corsAllowOrigins: boolean; + corsAllowOrigins: string | boolean; } -export class Delegate { +export interface Delegate { - getApp(appName: string) : App; + getApp(appName: string): App; - launchApp(appName: string, launchData: string, callback: (data: string) => void) : void; + launchApp(appName: string, launchData: string, callback: (data: string) => void): void; - stopApp(appName: string, pid: string, callback: (data: boolean) => void) : void; + stopApp(appName: string, pid: string, callback: (data: boolean) => void): void; } export interface App { @@ -60,24 +60,34 @@ export interface App { launch(launchData: string): void; } +export interface AppInfo { + dialVer: string; + name: string; + options: AppInfoOptions; + state: string; + xmlns: string; +} + +export interface AppInfoOptions { + allowStop: string; +} + export class Client extends events.EventEmitter { - constructor(); + getDialDevice(deviceDescriptionUrl: string, callback?: (data: DialDevice, err: any) => void): void; - getDialDevice(deviceDescriptionUrl: string, callback?: (data: DialDevice, err: any) => void) : void; + start(): void; - start() : void; + refresh(): void; - refresh() : void; - - stop() : void; + stop(): void; } export class DialDevice { constructor(deviceInfo: DeviceInfo); - getAppInfoXml(appName: string, callback?: (data: string, err: any) => void) :void; + getAppInfoXml(appName: string, callback?: (data: string, err: any) => void): void; - getAppInfo(appName: string, callback?: (data: Object, err: any) => void): void; + getAppInfo(appName: string, callback?: (data: AppInfo, err: any) => void): void; launchApp(appName: string, launchData: string, contentType: string, callback?: (data: string, err: any) => void): void; diff --git a/types/peer-dial/peer-dial-tests.ts b/types/peer-dial/peer-dial-tests.ts index 8b13789179..72863ef647 100644 --- a/types/peer-dial/peer-dial-tests.ts +++ b/types/peer-dial/peer-dial-tests.ts @@ -1 +1,65 @@ +import { Server, Client, App, AppInfo, CorsOptions, ServerOptions, Delegate, DialDevice, DeviceInfo } from 'peer-dial'; +import * as express from 'express'; + +class AppImpl implements App { + + name: string; + state: string; + allowStop: boolean; + pid: string; + + public launch(launchData: string): void{ + + } +} + +const app = new AppImpl(); + +class DelegateImpl implements Delegate { + + public getApp(appName: string): App{ + return app; + } + + public launchApp(appName: string, launchData: string, callback: (data: string) => void): void{ + + } + + public stopApp(appName: string, pid: string, callback: (data: boolean) => void): void { + + } +} + +const delegate = new DelegateImpl(); + +function testServer() { + + const object = new Server({ + expressApp: express(), + prefix: '/dial', + port: 3000, + corsAllowOrigins: '*', + manufacturer: 'testing', + modelName: 'testing', + delegate: delegate + }); +} + +function testClient() { + const client = new Client(); + client.on("ready", () => { + + }).on('found', (deviceDescriptionUrl: string, ssdpHeaders: string) => { + client.getDialDevice(deviceDescriptionUrl, (dialDevice: DialDevice, err: any) => { + dialDevice.getAppInfo('YouTube', (appInfo: AppInfo, err: any) => { + if(appInfo) { + dialDevice.launchApp("YouTube", "something", "text/plain", (data: string, err: any) => { + + }); + } + }); + }); + }); + client.start(); +} \ No newline at end of file From fca6aebeff579f85bbe66f1c889ef2875d6590c8 Mon Sep 17 00:00:00 2001 From: James Date: Fri, 8 Sep 2017 18:14:32 +0200 Subject: [PATCH 3/3] Final changes to the typings. --- types/peer-dial/index.d.ts | 31 ++++++++--------------------- types/peer-dial/peer-dial-tests.ts | 32 +++++++----------------------- 2 files changed, 15 insertions(+), 48 deletions(-) diff --git a/types/peer-dial/index.d.ts b/types/peer-dial/index.d.ts index 1e01f3b287..4d3af378b6 100644 --- a/types/peer-dial/index.d.ts +++ b/types/peer-dial/index.d.ts @@ -1,10 +1,10 @@ -// Type definitions for peer-dial 0.0.7 +// Type definitions for peer-dial 0.0 // Project: https://github.com/fraunhoferfokus/peer-dial -// Definitions by: James Tooley +// Definitions by: James Tooley +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 /// -/// -/// import * as events from "events"; import * as express from "express"; @@ -12,13 +12,9 @@ import * as uuid from "node-uuid"; export class Server extends events.EventEmitter { constructor(options: ServerOptions); - start(): void; - stop(): void; - corsOptionsAppsDelegate(req: string, callback: (err: any, data: CorsOptions) => void): void; - } export interface CorsOptions { @@ -37,17 +33,14 @@ export interface ServerOptions { manufacturer: string; modelName: string; maxContentLength?: number; - extraHeaders?: Object; + extraHeaders?: object; delegate: Delegate; corsAllowOrigins: string | boolean; } export interface Delegate { - getApp(appName: string): App; - launchApp(appName: string, launchData: string, callback: (data: string) => void): void; - stopApp(appName: string, pid: string, callback: (data: boolean) => void): void; } @@ -56,7 +49,6 @@ export interface App { state: string; allowStop: boolean; pid: string; - launch(launchData: string): void; } @@ -74,27 +66,20 @@ export interface AppInfoOptions { export class Client extends events.EventEmitter { getDialDevice(deviceDescriptionUrl: string, callback?: (data: DialDevice, err: any) => void): void; - start(): void; - refresh(): void; - stop(): void; } export class DialDevice { constructor(deviceInfo: DeviceInfo); - getAppInfoXml(appName: string, callback?: (data: string, err: any) => void): void; - getAppInfo(appName: string, callback?: (data: AppInfo, err: any) => void): void; - launchApp(appName: string, launchData: string, contentType: string, callback?: (data: string, err: any) => void): void; - stopApp(appName: string, pid: string, callback?: (data: number, err: any) => void): void; } -interface DeviceInfo { +export interface DeviceInfo { descriptionUrl: string; applicationUrl: string; deviceType: string; @@ -102,7 +87,7 @@ interface DeviceInfo { manufacturer: string; modelName: string; UDN: string; - iconList: Object[] | { - icon: Object + iconList: object[] | { + icon: object }; } diff --git a/types/peer-dial/peer-dial-tests.ts b/types/peer-dial/peer-dial-tests.ts index 72863ef647..cb4238da62 100644 --- a/types/peer-dial/peer-dial-tests.ts +++ b/types/peer-dial/peer-dial-tests.ts @@ -1,40 +1,25 @@ - import { Server, Client, App, AppInfo, CorsOptions, ServerOptions, Delegate, DialDevice, DeviceInfo } from 'peer-dial'; import * as express from 'express'; class AppImpl implements App { - name: string; state: string; allowStop: boolean; pid: string; - - public launch(launchData: string): void{ - + launch(launchData: string): void { } } - const app = new AppImpl(); - class DelegateImpl implements Delegate { - - public getApp(appName: string): App{ + getApp(appName: string): App { return app; } - - public launchApp(appName: string, launchData: string, callback: (data: string) => void): void{ - + launchApp(appName: string, launchData: string, callback: (data: string) => void): void { } - - public stopApp(appName: string, pid: string, callback: (data: boolean) => void): void { - + stopApp(appName: string, pid: string, callback: (data: boolean) => void): void { } } - -const delegate = new DelegateImpl(); - function testServer() { - const object = new Server({ expressApp: express(), prefix: '/dial', @@ -42,24 +27,21 @@ function testServer() { corsAllowOrigins: '*', manufacturer: 'testing', modelName: 'testing', - delegate: delegate + delegate: new DelegateImpl() }); } - function testClient() { const client = new Client(); client.on("ready", () => { - }).on('found', (deviceDescriptionUrl: string, ssdpHeaders: string) => { client.getDialDevice(deviceDescriptionUrl, (dialDevice: DialDevice, err: any) => { dialDevice.getAppInfo('YouTube', (appInfo: AppInfo, err: any) => { - if(appInfo) { + if (appInfo) { dialDevice.launchApp("YouTube", "something", "text/plain", (data: string, err: any) => { - }); } }); }); }); client.start(); -} \ No newline at end of file +}