Final changes to the typings.

This commit is contained in:
James
2017-09-08 18:14:32 +02:00
parent fa09c672de
commit fca6aebeff
2 changed files with 15 additions and 48 deletions

View File

@@ -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 <https://github.com/RealTYPICAL/>
// Definitions by: James Tooley <https://github.com/RealTYPICAL>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.4
/// <reference types="node" />
/// <reference types="express" />
/// <reference types="node-uuid" />
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
};
}

View File

@@ -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();
}
}