diff --git a/types/peer-dial/index.d.ts b/types/peer-dial/index.d.ts new file mode 100644 index 0000000000..4d3af378b6 --- /dev/null +++ b/types/peer-dial/index.d.ts @@ -0,0 +1,93 @@ +// Type definitions for peer-dial 0.0 +// Project: https://github.com/fraunhoferfokus/peer-dial +// Definitions by: James Tooley +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/// + +import * as events from "events"; +import * as express from "express"; +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 { + 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: 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; +} + +export interface App { + name: string; + state: string; + allowStop: boolean; + pid: string; + 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 { + 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; +} + +export 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..cb4238da62 --- /dev/null +++ b/types/peer-dial/peer-dial-tests.ts @@ -0,0 +1,47 @@ +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; + launch(launchData: string): void { + } +} +const app = new AppImpl(); +class DelegateImpl implements Delegate { + getApp(appName: string): App { + return app; + } + launchApp(appName: string, launchData: string, callback: (data: string) => void): void { + } + stopApp(appName: string, pid: string, callback: (data: boolean) => void): void { + } +} +function testServer() { + const object = new Server({ + expressApp: express(), + prefix: '/dial', + port: 3000, + corsAllowOrigins: '*', + manufacturer: 'testing', + modelName: 'testing', + 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) { + dialDevice.launchApp("YouTube", "something", "text/plain", (data: string, err: any) => { + }); + } + }); + }); + }); + client.start(); +} 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" }