mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Added types for react-native-zeroconf package
This commit is contained in:
parent
d5d4960aae
commit
bd60e29a03
119
types/react-native-zeroconf/index.d.ts
vendored
Normal file
119
types/react-native-zeroconf/index.d.ts
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
// Type definitions for react-native-zeroconf 0.9.0
|
||||
// Project: https://github.com/balthazar/react-native-zeroconf
|
||||
// Definitions by: Peter Matta <https://github.com/mattapet>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
declare module 'react-native-zeroconf' {
|
||||
/**
|
||||
* @example
|
||||
```json
|
||||
{
|
||||
"host": "XeroxPrinter.local.",
|
||||
"addresses": [
|
||||
"192.168.1.23",
|
||||
"fe80::aebc:123:ffff:abcd"
|
||||
],
|
||||
"name": "Xerox Printer",
|
||||
"fullName": "XeroxPrinter.local._http._tcp.",
|
||||
"port": 8080,
|
||||
"txt": {}
|
||||
}
|
||||
```
|
||||
*/
|
||||
export interface Service {
|
||||
name: string;
|
||||
fullName: string;
|
||||
addresses: string[];
|
||||
host: string;
|
||||
port: number;
|
||||
txt: {
|
||||
[key: string]: any
|
||||
};
|
||||
}
|
||||
|
||||
export default class Zeroconf extends NodeJS.EventEmitter {
|
||||
/**
|
||||
* Start the zeroconf scan.
|
||||
*
|
||||
* @description This will initialize the scan from the `Zeroconf`
|
||||
* instance. Will stop another scan if any is running.
|
||||
*
|
||||
* @param type Default `http`
|
||||
* @param protocol Default `tcp`
|
||||
* @param domain Default `local`
|
||||
*/
|
||||
public scan(type?: string, protocol?: string, domain?: string): void;
|
||||
|
||||
/**
|
||||
* Stop the scan.
|
||||
*
|
||||
* @description If any scan is running, stop it. Otherwise do nothing.
|
||||
*/
|
||||
public stop(): void;
|
||||
|
||||
/**
|
||||
* Returns resolved services.
|
||||
*
|
||||
* @description Will return all names of services that have been
|
||||
* resolved.
|
||||
*/
|
||||
public getServices(): { [name: string]: Service };
|
||||
|
||||
/**
|
||||
* Remove listeners.
|
||||
*
|
||||
* @description Allow you to clean the listeners, avoiding potential
|
||||
* memory leaks.
|
||||
*
|
||||
* @see https://github.com/balthazar/react-native-zeroconf/issues/33
|
||||
*/
|
||||
public removeDeviceListeners(): void;
|
||||
|
||||
/**
|
||||
* Add listeners
|
||||
*
|
||||
* @description If you cleaned the listeners and need to get them back
|
||||
* on.
|
||||
*/
|
||||
public addDeviceListeners(): void;
|
||||
|
||||
/**
|
||||
* Triggered on scan start.
|
||||
*/
|
||||
public on(e: 'start', listener: () => any): this;
|
||||
|
||||
/**
|
||||
* Triggered on scan stop
|
||||
*/
|
||||
public on(e: 'stop', listener: () => any): this;
|
||||
|
||||
/**
|
||||
* Triggered either when a service is found or removed.
|
||||
*/
|
||||
public on(e: 'update', listener: () => any): this;
|
||||
|
||||
/**
|
||||
* Broadcast a service name as soon as it is found.
|
||||
*/
|
||||
public on(e: 'found', listener: (name: string) => any): this;
|
||||
|
||||
/**
|
||||
* Triggered when a service is resolved.
|
||||
* @description Broadcast a service object once it is fully resolved.
|
||||
*/
|
||||
public on(e: 'resolved', listener: (service: Service) => any): this;
|
||||
|
||||
/**
|
||||
* Triggered when a service is removed.
|
||||
* @description Broadcast a service name removed from the network.
|
||||
*/
|
||||
public on(e: 'remove', listener: (name: string) => any): this;
|
||||
|
||||
/**
|
||||
* Triggered when an error occurs.
|
||||
*/
|
||||
public on(e: 'error', listener: (err: Error) => any): this;
|
||||
}
|
||||
}
|
||||
21
types/react-native-zeroconf/react-native-zeroconf-tests.ts
Normal file
21
types/react-native-zeroconf/react-native-zeroconf-tests.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import Zeroconf, { Service } from 'react-native-zeroconf';
|
||||
|
||||
const zeroconf = new Zeroconf();
|
||||
|
||||
zeroconf.on('start', () => console.log('[Start]'));
|
||||
zeroconf.on('stop', () => console.log('[Stop]'));
|
||||
zeroconf.on('found', (name: string) => console.log(`[Found] '${name}'`));
|
||||
zeroconf.on('resolved', (service: Service) =>
|
||||
console.log(`[Resolved]\n${JSON.stringify(service, null, 2)}`));
|
||||
zeroconf.on('remove', (name: string) => console.log(`[Remove] '${name}'`));
|
||||
zeroconf.on('update', () => console.log('[Update]'));
|
||||
zeroconf.on('error', (error: Error) => console.log(`[Error] ${error}`));
|
||||
|
||||
zeroconf.scan('http', 'tcp', 'local.');
|
||||
const services = zeroconf.getServices();
|
||||
for (const serviceName in services) {
|
||||
const service = services[serviceName];
|
||||
console.log(`[${service.name}] - ${service.fullName}`);
|
||||
}
|
||||
|
||||
setTimeout(() => zeroconf.stop(), 5000);
|
||||
24
types/react-native-zeroconf/tsconfig.json
Normal file
24
types/react-native-zeroconf/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"jsx": "react-native",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"react-native-zeroconf-tests.ts"
|
||||
]
|
||||
}
|
||||
3
types/react-native-zeroconf/tslint.json
Normal file
3
types/react-native-zeroconf/tslint.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user