Did more work on typings.

This commit is contained in:
James
2017-09-06 17:46:08 +02:00
parent 0b991edc75
commit fa09c672de
2 changed files with 96 additions and 22 deletions

View File

@@ -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 <https://github.com/RealTYPICAL/>
/// <reference types="node" />
/// <reference types="express" />
@@ -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;

View File

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