From d6f3a60ad5c0a4df89883af30cd778fe60df2315 Mon Sep 17 00:00:00 2001 From: Quentin Lampin Date: Wed, 12 Oct 2016 14:46:01 +0200 Subject: [PATCH] add type definitions for bonjour (#11885) * add type definitions for bonjour * fixed project URL (brackets) --- bonjour/bonjour-tests.ts | 21 ++++++++++++ bonjour/bonjour.d.ts | 71 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 bonjour/bonjour-tests.ts create mode 100644 bonjour/bonjour.d.ts diff --git a/bonjour/bonjour-tests.ts b/bonjour/bonjour-tests.ts new file mode 100644 index 0000000000..b97794b071 --- /dev/null +++ b/bonjour/bonjour-tests.ts @@ -0,0 +1,21 @@ +/// +import * as bonjour from 'bonjour'; + +var bonjourOptions: bonjour.BonjourOptions; +var bonjourInstance: bonjour.Bonjour; + +var serviceOptions: bonjour.ServiceOptions; +var service: bonjour.Service; + +var browserOptions: bonjour.BrowserOptions; +var browser: bonjour.Browser; + +bonjourOptions = { interface: '192.168.1.1', port: 5353 }; +bonjourInstance = new bonjour.Bonjour(bonjourOptions); + +serviceOptions = { name: 'My Web Server', type: 'http', port: 3000 }; +service = bonjourInstance.publish(serviceOptions); + +browserOptions = { protocol: 'tcp', type: 'http' }; +browser = bonjour.find(browserOptions); + diff --git a/bonjour/bonjour.d.ts b/bonjour/bonjour.d.ts new file mode 100644 index 0000000000..0ffd9f1171 --- /dev/null +++ b/bonjour/bonjour.d.ts @@ -0,0 +1,71 @@ +// Type definitions for bonjour v3.5.0 +// Project: https://github.com/watson/bonjour +// Definitions by: Quentin Lampin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "bonjour" { + export interface BonjourOptions { + multicast?: boolean; + interface?: string; + port?: number; + ip?: string; + ttl?: number; + loopback?: boolean; + reuseAddr?: boolean; + } + + export interface BrowserOptions { + type?: string; + subtypes?: string[]; + protocol?: string; + txt?: Object; + } + + export interface ServiceOptions { + name: string; + host?: string; + port: number; + type: string; + subtypes?: string[]; + protocol?: 'udp'|'tcp'; + txt?: Object; + } + + export interface Service { + name: string; + type: string; + subtypes: string[]; + protocol: string; + host: string; + port: number; + fqdn: string; + rawTxt: Object; + txt: Object; + published: boolean; + + stop: (cb: ()=>any) => void; + start: () => void; + } + + export class Bonjour { + + constructor(opts: BonjourOptions); + publish(options: ServiceOptions):Service; + unpublishAll(cb: ()=>any): void; + find(options:BrowserOptions, onUp: ()=>any): Browser; + findOne(options:any, cb: (service: Service)=>any): Browser; + destroy():void; + } + + export class Browser { + services: Service[]; + + start():void; + update():void; + stop():void; + } + + export function find(options: BrowserOptions, onUp?: ()=>any): Browser; + export function findOne(options: BrowserOptions): Browser; + +}