mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Merge pull request #19795 from RealTYPICAL/master
Add typings for peer-dial
This commit is contained in:
commit
dddb59f25b
93
types/peer-dial/index.d.ts
vendored
Normal file
93
types/peer-dial/index.d.ts
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
// Type definitions for peer-dial 0.0
|
||||
// Project: https://github.com/fraunhoferfokus/peer-dial
|
||||
// Definitions by: James Tooley <https://github.com/RealTYPICAL>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
47
types/peer-dial/peer-dial-tests.ts
Normal file
47
types/peer-dial/peer-dial-tests.ts
Normal file
@ -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();
|
||||
}
|
||||
22
types/peer-dial/tsconfig.json
Normal file
22
types/peer-dial/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/peer-dial/tslint.json
Normal file
1
types/peer-dial/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user