Skip to content

Commit 745bec9

Browse files
added types
1 parent 6b1d217 commit 745bec9

2 files changed

Lines changed: 144 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@
3838
"bugs": {
3939
"url": "https://github.com/becvert/cordova-plugin-zeroconf/issues"
4040
},
41-
"homepage": "https://github.com/becvert/cordova-plugin-zeroconf"
41+
"homepage": "https://github.com/becvert/cordova-plugin-zeroconf",
42+
"types": "./types/index.d.ts"
4243
}

types/index.d.ts

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// Type definitions for Apache Cordova Zeroconf (mDNS) plugin
2+
// Project: https://github.com/becvert/cordova-plugin-zeroconf
3+
4+
declare namespace ZeroConfPlugin {
5+
interface TxtRecord {
6+
[key: string]: string
7+
}
8+
9+
/* service : {
10+
'domain' : 'local.',
11+
'type' : '_http._tcp.',
12+
'name': 'Becvert\'s iPad',
13+
'port' : 80,
14+
'hostname' : 'ipad-of-becvert.local',
15+
'ipv4Addresses' : [ '192.168.1.125' ],
16+
'ipv6Addresses' : [ '2001:0:5ef5:79fb:10cb:1dbf:3f57:feb0' ],
17+
'txtRecord' : {
18+
'foo' : 'bar'
19+
} */
20+
interface Service {
21+
domain: string;
22+
type: string;
23+
name: string;
24+
port: number;
25+
hostname: string;
26+
ipv4Addresses: Array<string>;
27+
ipv6Addresses: Array<string>;
28+
txtRecord: TxtRecord;
29+
}
30+
31+
interface Result {
32+
/** added, resolved, registered */
33+
action: string;
34+
service: Service;
35+
}
36+
37+
interface ZeroConf {
38+
/** This plugin allows you to browse and publish ZeroConf/Bonjour/mDNS services from applications developed using PhoneGap/Cordova 3.0 or newer and Ionic's Capacitor. */
39+
40+
/** any, ipv6 or ipv4 */
41+
registerAddressFamily: string;
42+
/** any, ipv6 or ipv4 */
43+
watchAddressFamily: string;
44+
45+
/**
46+
* Returns this device's hostname.
47+
* @param successCallback The callback that is called when the plugin returns the hostname.
48+
* @param errorCallback A callback that is called when errors happen.
49+
*/
50+
getHostname(
51+
successCallback: (hostname: string) => void,
52+
errorCallback?: (error: string) => void): void;
53+
54+
/**
55+
* Publishes a new service.
56+
* @param type
57+
* @param domain
58+
* @param name
59+
* @param port
60+
* @param txtRecord
61+
* @param successCallback The callback that is called when the plugin completes successully.
62+
* @param errorCallback A callback that is called when errors happen.
63+
*/
64+
register(
65+
type: string,
66+
domain: string,
67+
name: string,
68+
port: number,
69+
txtRecord: TxtRecord,
70+
successCallback: (result: Result) => void,
71+
errorCallback?: (error: string) => void): void;
72+
73+
/**
74+
* Unregisters a service.
75+
* @param type
76+
* @param domain
77+
* @param name
78+
* @param successCallback The callback that is called when the plugin completes successully.
79+
* @param errorCallback A callback that is called when errors happen.
80+
*/
81+
unregister(
82+
type: string,
83+
domain: string,
84+
name: string,
85+
successCallback: () => void,
86+
errorCallback?: (error: string) => void): void;
87+
88+
/**
89+
* Unregisters all published services.
90+
* @param successCallback The callback that is called when the plugin completes successully.
91+
* @param errorCallback A callback that is called when errors happen.
92+
*/
93+
stop(
94+
successCallback: () => void,
95+
errorCallback?: (error: string) => void): void;
96+
97+
/**
98+
* Starts watching for services of the specified type.
99+
* @param type
100+
* @param domain
101+
* @param successCallback The callback that is called when the plugin completes successully. Also called whenever a new service is discovered or resolved.
102+
* @param errorCallback A callback that is called when errors happen.
103+
*/
104+
watch(
105+
type: string,
106+
domain: string,
107+
successCallback: (result: Result) => void,
108+
errorCallback?: (error: string) => void): void;
109+
110+
/**
111+
* Stops watching for services of the specified type.
112+
* @param type
113+
* @param domain
114+
* @param successCallback The callback that is called when the plugin completes successully. Also called whenever a new service is discovered or resolved.
115+
* @param errorCallback A callback that is called when errors happen.
116+
*/
117+
unwatch(
118+
type: string,
119+
domain: string,
120+
successCallback: () => void,
121+
errorCallback?: (error: string) => void): void;
122+
123+
124+
/**
125+
* Closes the service browser and stops watching.
126+
* @param successCallback The callback that is called when the plugin completes successully.
127+
* @param errorCallback A callback that is called when errors happen.
128+
*/
129+
close(
130+
successCallback: () => void,
131+
errorCallback?: (error: string) => void): void;
132+
133+
/**
134+
* Re-initializes the entire plugin, which resets the browsers and services. Use this if the WiFi network has changed while the app is running.
135+
* @param successCallback The callback that is called when the plugin completes successully.
136+
* @param errorCallback A callback that is called when errors happen.
137+
*/
138+
reInit(
139+
successCallback: () => void,
140+
errorCallback?: (error: string) => void): void;
141+
}
142+
}

0 commit comments

Comments
 (0)