@inthepocket/react-native-service-discovery 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,15 +5,120 @@
5
5
  [![npm](https://img.shields.io/npm/v/@inthepocket/react-native-service-discovery)](https://www.npmjs.com/package/@inthepocket/react-native-service-discovery)
6
6
  ![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)
7
7
 
8
+ This library allows you to discover services on your local network using mDNS (DNS-SD, Bonjour, Zeroconf, Avahi, ...). Devices that support service discovery include printers, webcams, HTTPS servers, and other mobile devices. The library uses [NSNetServiceBrowser](https://developer.apple.com/documentation/foundation/nsnetservicebrowser) on iOS and [NsdManager](https://developer.android.com/develop/connectivity/wifi/use-nsd) on Android.
9
+
8
10
  ## Installation
9
11
 
10
12
  ```sh
11
13
  npm install @inthepocket/react-native-service-discovery
12
14
  ```
13
15
 
16
+ Add the services you want to search for in `Info.plist`:
17
+
18
+ ```xml
19
+ <key>NSBonjourServices</key>
20
+ <array>
21
+ <!-- Change to your services -->
22
+ <string>_ssh._tcp</string>
23
+ <string>_http._tcp</string>
24
+ </array>
25
+ ```
26
+
27
+ Add a custom Local Network prompt message in `Info.plist`:
28
+
29
+ ```xml
30
+ <key>NSLocalNetworkUsageDescription</key>
31
+ <string>${PRODUCT_NAME} uses the local network to discover and connect to devices on your Wi-Fi network.</string>
32
+ ```
33
+
14
34
  ## Usage
15
35
 
16
- TODO
36
+ ```ts
37
+ import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
38
+
39
+ const foundListener = ServiceDiscovery.addEventListener('serviceFound', (service) => {
40
+ console.log('Service found:', service);
41
+ });
42
+
43
+ const lostListener = ServiceDiscovery.addEventListener('serviceLost', (service) => {
44
+ console.log('Service lost:', service);
45
+ });
46
+
47
+ // Start searching for _http._tcp. services
48
+ await ServiceDiscovery.startSearch('http');
49
+
50
+ // ...
51
+ await ServiceDiscovery.stopSearch('http');
52
+ foundListener.remove();
53
+ lostListener.remove();
54
+ ```
55
+
56
+ ### startSearch
57
+
58
+ Start searching for services of a specific type. Searching for multiple services can be done in parallel.
59
+
60
+ | Parameter | Type | Description |
61
+ | --------- | ------ | ----------- |
62
+ | type | string | The service type to search for, e.g. 'http'. The device will search for services of type `_serviceType._tcp.`. |
63
+
64
+ #### Returns
65
+
66
+ `Promise<void>` - Resolves when the search has started. Rejects when the search could not be started.
67
+
68
+ ### stopSearch
69
+
70
+ Stop searching for a specific service. This will not stop searching for any other services that are being searched for.
71
+
72
+ | Parameter | Type | Description |
73
+ | --------- | ------ | ----------- |
74
+ | type | string | The service type to stop searching for, e.g. 'http'. |
75
+
76
+ #### Returns
77
+
78
+ `Promise<void>` - Resolves when the search has stopped. Rejects when the search could not be stopped. Does not reject when the search was already stopped or was not started in the first place.
79
+
80
+ ### addEventListener
81
+
82
+ | Parameter | Type | Description |
83
+ | --------- | ------ | ----------- |
84
+ | event | `'serviceFound' \| 'serviceLost'` | Start listening for found or lost services. |
85
+ | listener | `(service: Service) => void` | The listener that will be called when a service is found or lost. |
86
+
87
+ #### Returns
88
+
89
+ An `EmitterSubscription` that can be used to remove the listener, by calling `remove()`.
90
+
91
+ ### Service
92
+
93
+ | Attribute | Type | Description |
94
+ | --------- | ------ | ----------- |
95
+ | name | `string` | Service name. |
96
+ | type | `string` | Service type, e.g. `_http._tcp.`. |
97
+ | domain | `string` | Domain, can be `local.` or any other domain. |
98
+ | hostName | `string` | The domain name of the IP advertising the service. On local networks this is usually the host name. |
99
+ | addresses | `string[]` | The IP addresses of the service. This is an array of IPv4 and IPv6 addresses. |
100
+ | port | `number` | The port number where the service can be reached. |
101
+ | txt | `Record<string, string>` | The TXT record of the service. The TXT record gives additional information about the service. |
102
+
103
+
104
+ ### Listening for multiple service types
105
+
106
+ You can listen for multiple service types with the same listener:
107
+
108
+ ```ts
109
+ import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
110
+
111
+ ServiceDiscovery.addEventListener('serviceFound', (service) => {
112
+ if(service.type === '_http._tcp.') {
113
+ console.log('HTTP service found:', service);
114
+ } else if(service.type === '_ssh._tcp.') {
115
+ console.log('SSH service found:', service);
116
+ }
117
+ });
118
+
119
+ await ServiceDiscovery.startSearch('http');
120
+ await ServiceDiscovery.startSearch('ssh');
121
+ ```
17
122
 
18
123
  ## Contributing
19
124
 
@@ -24,5 +129,7 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
24
129
  MIT
25
130
 
26
131
  ---
132
+ Many thanks to
27
133
 
28
- Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
134
+ - [react-native-dnssd](https://github.com/kopera/react-native-dnssd)
135
+ - [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -18,10 +18,55 @@ const ServiceDiscovery = ServiceDiscoveryModule ? ServiceDiscoveryModule : new P
18
18
  throw new Error(LINKING_ERROR);
19
19
  }
20
20
  });
21
+
22
+ /**
23
+ * A service that is found or lost on the network.
24
+ */
25
+
21
26
  const EventEmitter = new _reactNative.NativeEventEmitter(ServiceDiscovery);
27
+
28
+ /**
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
33
+ *
34
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
35
+ *
36
+ * // Start searching for _http._tcp. services
37
+ * await ServiceDiscovery.startSearch('http');
38
+ * ```
39
+ */
22
40
  const addEventListener = (event, listener) => EventEmitter.addListener(event, listener);
41
+
42
+ /**
43
+ * Start searching for services of a specific type. Searching for
44
+ * multiple services can be done in parallel.
45
+ *
46
+ * @param serviceType The service type to search for, e.g. 'http'. The device
47
+ * will search for services of type `_serviceType._tcp.`.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
52
+ *
53
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
54
+ *
55
+ * // Start searching for _http._tcp. services
56
+ * await ServiceDiscovery.startSearch('http');
57
+ * ```
58
+ */
23
59
  exports.addEventListener = addEventListener;
24
60
  const startSearch = serviceType => ServiceDiscovery.startSearch(serviceType);
61
+
62
+ /**
63
+ * Stop searching for a specific service. This will not stop searching for any
64
+ * other services that are being searched for.
65
+ *
66
+ * @returns A promise that resolves when the search has been stopped, and
67
+ * rejects if the search cannot be stopped. Does not reject if the search has
68
+ * already been stopped.
69
+ */
25
70
  exports.startSearch = startSearch;
26
71
  const stopSearch = serviceType => ServiceDiscovery.stopSearch(serviceType);
27
72
  exports.stopSearch = stopSearch;
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","ServiceDiscoveryModule","NativeModules","ServiceDiscovery","Proxy","get","Error","EventEmitter","NativeEventEmitter","addEventListener","event","listener","addListener","exports","startSearch","serviceType","stopSearch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GAChB,sGAAqG,GACtGC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,sBAAsB,GAAGH,oBAAoB,GAC/CN,OAAO,CAAC,0BAA0B,CAAC,CAACK,OAAO,GAC3CK,0BAAa,CAACC,gBAAgB;AAElC,MAAMA,gBAAgB,GAAGF,sBAAsB,GAC3CA,sBAAsB,GACtB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACb,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAoBL,MAAMc,YAAY,GAAG,IAAIC,+BAAkB,CAACL,gBAAgB,CAAC;AAEtD,MAAMM,gBAAgB,GAAGA,CAC9BC,KAAmB,EACnBC,QAAyB,KACRJ,YAAY,CAACK,WAAW,CAACF,KAAK,EAAEC,QAAQ,CAAC;AAACE,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA;AAEtD,MAAMK,WAAW,GAAIC,WAAmB,IAC7CZ,gBAAgB,CAACW,WAAW,CAACC,WAAW,CAAC;AAACF,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAErC,MAAME,UAAU,GAAID,WAAmB,IAC5CZ,gBAAgB,CAACa,UAAU,CAACD,WAAW,CAAC;AAACF,OAAA,CAAAG,UAAA,GAAAA,UAAA","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","ServiceDiscoveryModule","NativeModules","ServiceDiscovery","Proxy","get","Error","EventEmitter","NativeEventEmitter","addEventListener","event","listener","addListener","exports","startSearch","serviceType","stopSearch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,sGAAsG,GACtGC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,sBAAsB,GAAGH,oBAAoB,GAC/CN,OAAO,CAAC,0BAA0B,CAAC,CAACK,OAAO,GAC3CK,0BAAa,CAACC,gBAAgB;AAElC,MAAMA,gBAAgB,GAAGF,sBAAsB,GAC3CA,sBAAsB,GACtB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACb,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;;AA2CA,MAAMc,YAAY,GAAG,IAAIC,+BAAkB,CAACL,gBAAgB,CAAC;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMM,gBAAgB,GAAGA,CAC9BC,KAAmB,EACnBC,QAAyB,KACRJ,YAAY,CAACK,WAAW,CAACF,KAAK,EAAEC,QAAQ,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAhBAE,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA;AAiBO,MAAMK,WAAW,GAAIC,WAAmB,IAC7CZ,gBAAgB,CAACW,WAAW,CAACC,WAAW,CAAC;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAPAF,OAAA,CAAAC,WAAA,GAAAA,WAAA;AAQO,MAAME,UAAU,GAAID,WAAmB,IAC5CZ,gBAAgB,CAACa,UAAU,CAACD,WAAW,CAAC;AAACF,OAAA,CAAAG,UAAA,GAAAA,UAAA","ignoreList":[]}
@@ -12,8 +12,53 @@ const ServiceDiscovery = ServiceDiscoveryModule ? ServiceDiscoveryModule : new P
12
12
  throw new Error(LINKING_ERROR);
13
13
  }
14
14
  });
15
+
16
+ /**
17
+ * A service that is found or lost on the network.
18
+ */
19
+
15
20
  const EventEmitter = new NativeEventEmitter(ServiceDiscovery);
21
+
22
+ /**
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
27
+ *
28
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
29
+ *
30
+ * // Start searching for _http._tcp. services
31
+ * await ServiceDiscovery.startSearch('http');
32
+ * ```
33
+ */
16
34
  export const addEventListener = (event, listener) => EventEmitter.addListener(event, listener);
35
+
36
+ /**
37
+ * Start searching for services of a specific type. Searching for
38
+ * multiple services can be done in parallel.
39
+ *
40
+ * @param serviceType The service type to search for, e.g. 'http'. The device
41
+ * will search for services of type `_serviceType._tcp.`.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
46
+ *
47
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
48
+ *
49
+ * // Start searching for _http._tcp. services
50
+ * await ServiceDiscovery.startSearch('http');
51
+ * ```
52
+ */
17
53
  export const startSearch = serviceType => ServiceDiscovery.startSearch(serviceType);
54
+
55
+ /**
56
+ * Stop searching for a specific service. This will not stop searching for any
57
+ * other services that are being searched for.
58
+ *
59
+ * @returns A promise that resolves when the search has been stopped, and
60
+ * rejects if the search cannot be stopped. Does not reject if the search has
61
+ * already been stopped.
62
+ */
18
63
  export const stopSearch = serviceType => ServiceDiscovery.stopSearch(serviceType);
19
64
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","ServiceDiscoveryModule","require","ServiceDiscovery","Proxy","get","Error","EventEmitter","addEventListener","event","listener","addListener","startSearch","serviceType","stopSearch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAE1E,MAAMC,aAAa,GAChB,sGAAqG,GACtGD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,sBAAsB,GAAGH,oBAAoB,GAC/CI,OAAO,CAAC,0BAA0B,CAAC,CAACL,OAAO,GAC3CL,aAAa,CAACW,gBAAgB;AAElC,MAAMA,gBAAgB,GAAGF,sBAAsB,GAC3CA,sBAAsB,GACtB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACZ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAoBL,MAAMa,YAAY,GAAG,IAAIhB,kBAAkB,CAACY,gBAAgB,CAAC;AAE7D,OAAO,MAAMK,gBAAgB,GAAGA,CAC9BC,KAAmB,EACnBC,QAAyB,KACRH,YAAY,CAACI,WAAW,CAACF,KAAK,EAAEC,QAAQ,CAAC;AAE5D,OAAO,MAAME,WAAW,GAAIC,WAAmB,IAC7CV,gBAAgB,CAACS,WAAW,CAACC,WAAW,CAAC;AAE3C,OAAO,MAAMC,UAAU,GAAID,WAAmB,IAC5CV,gBAAgB,CAACW,UAAU,CAACD,WAAW,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","Platform","LINKING_ERROR","select","ios","default","isTurboModuleEnabled","global","__turboModuleProxy","ServiceDiscoveryModule","require","ServiceDiscovery","Proxy","get","Error","EventEmitter","addEventListener","event","listener","addListener","startSearch","serviceType","stopSearch"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAE1E,MAAMC,aAAa,GACjB,sGAAsG,GACtGD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;;AAEjC;AACA,MAAMC,oBAAoB,GAAGC,MAAM,CAACC,kBAAkB,IAAI,IAAI;AAE9D,MAAMC,sBAAsB,GAAGH,oBAAoB,GAC/CI,OAAO,CAAC,0BAA0B,CAAC,CAACL,OAAO,GAC3CL,aAAa,CAACW,gBAAgB;AAElC,MAAMA,gBAAgB,GAAGF,sBAAsB,GAC3CA,sBAAsB,GACtB,IAAIG,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACZ,aAAa,CAAC;EAChC;AACF,CACF,CAAC;;AAEL;AACA;AACA;;AA2CA,MAAMa,YAAY,GAAG,IAAIhB,kBAAkB,CAACY,gBAAgB,CAAC;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMK,gBAAgB,GAAGA,CAC9BC,KAAmB,EACnBC,QAAyB,KACRH,YAAY,CAACI,WAAW,CAACF,KAAK,EAAEC,QAAQ,CAAC;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAME,WAAW,GAAIC,WAAmB,IAC7CV,gBAAgB,CAACS,WAAW,CAACC,WAAW,CAAC;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAID,WAAmB,IAC5CV,gBAAgB,CAACW,UAAU,CAACD,WAAW,CAAC","ignoreList":[]}
@@ -1,18 +1,82 @@
1
+ /**
2
+ * A service that is found or lost on the network.
3
+ */
1
4
  export interface Service {
5
+ /**
6
+ * Service name.
7
+ */
2
8
  readonly name: string;
9
+ /**
10
+ * Service type, e.g. `_http._tcp.`.
11
+ */
3
12
  readonly type: string;
13
+ /**
14
+ * Domain, can be `local.` or any other domain.
15
+ */
4
16
  readonly domain: string;
17
+ /**
18
+ * The domain name of the IP advertising the service.
19
+ * On local networks this is usually the host name.
20
+ */
5
21
  readonly hostName: string;
22
+ /**
23
+ * The IP addresses of the service.
24
+ * This is an array of IPv4 and IPv6 addresses.
25
+ */
6
26
  readonly addresses: string[];
27
+ /**
28
+ * The port number where the service can be reached.
29
+ */
7
30
  readonly port: number;
31
+ /**
32
+ * The TXT record of the service. The TXT record gives additional information
33
+ * about the service.
34
+ */
8
35
  readonly txt: Record<string, string>;
9
36
  }
10
- export type ServiceEvent = 'serviceFound' | 'serviceLost' | 'error';
37
+ export type ServiceEvent = 'serviceFound' | 'serviceLost';
11
38
  export type ServiceCallback = (service: Service) => void;
12
39
  export interface Subscription {
13
40
  remove: () => void;
14
41
  }
42
+ /**
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
47
+ *
48
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
49
+ *
50
+ * // Start searching for _http._tcp. services
51
+ * await ServiceDiscovery.startSearch('http');
52
+ * ```
53
+ */
15
54
  export declare const addEventListener: (event: ServiceEvent, listener: ServiceCallback) => Subscription;
55
+ /**
56
+ * Start searching for services of a specific type. Searching for
57
+ * multiple services can be done in parallel.
58
+ *
59
+ * @param serviceType The service type to search for, e.g. 'http'. The device
60
+ * will search for services of type `_serviceType._tcp.`.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
65
+ *
66
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
67
+ *
68
+ * // Start searching for _http._tcp. services
69
+ * await ServiceDiscovery.startSearch('http');
70
+ * ```
71
+ */
16
72
  export declare const startSearch: (serviceType: string) => Promise<void>;
73
+ /**
74
+ * Stop searching for a specific service. This will not stop searching for any
75
+ * other services that are being searched for.
76
+ *
77
+ * @returns A promise that resolves when the search has been stopped, and
78
+ * rejects if the search cannot be stopped. Does not reject if the search has
79
+ * already been stopped.
80
+ */
17
81
  export declare const stopSearch: (serviceType: string) => Promise<void>;
18
82
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AA0BA,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,aAAa,GAAG,OAAO,CAAC;AAEpE,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAID,eAAO,MAAM,gBAAgB,UACpB,YAAY,YACT,eAAe,KACxB,YAAyD,CAAC;AAE7D,eAAO,MAAM,WAAW,gBAAiB,MAAM,KAAG,QAAQ,IAAI,CACnB,CAAC;AAE5C,eAAO,MAAM,UAAU,gBAAiB,MAAM,KAAG,QAAQ,IAAI,CACnB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B;;;OAGG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;IAC7B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,aAAa,CAAC;AAE1D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAID;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAC3B,OAAO,YAAY,EACnB,UAAU,eAAe,KACxB,YAAyD,CAAC;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,KAAG,OAAO,CAAC,IAAI,CACnB,CAAC;AAE5C;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GAAI,aAAa,MAAM,KAAG,OAAO,CAAC,IAAI,CACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inthepocket/react-native-service-discovery",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "mDNS Network Service Discovery in React Native",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -61,13 +61,13 @@
61
61
  "registry": "https://registry.npmjs.org/"
62
62
  },
63
63
  "devDependencies": {
64
- "@commitlint/config-conventional": "^17.0.2",
64
+ "@commitlint/config-conventional": "^19.8.1",
65
65
  "@evilmartians/lefthook": "^1.5.0",
66
66
  "@react-native/eslint-config": "^0.73.1",
67
- "@release-it/conventional-changelog": "^5.0.0",
67
+ "@release-it/conventional-changelog": "^10.0.1",
68
68
  "@types/jest": "^29.5.5",
69
69
  "@types/react": "^18.2.44",
70
- "commitlint": "^17.0.2",
70
+ "commitlint": "^19.8.1",
71
71
  "del-cli": "^5.1.0",
72
72
  "eslint": "^8.51.0",
73
73
  "eslint-config-prettier": "^9.0.0",
@@ -77,7 +77,7 @@
77
77
  "react": "18.2.0",
78
78
  "react-native": "0.74.0",
79
79
  "react-native-builder-bob": "^0.23.2",
80
- "release-it": "^15.0.0",
80
+ "release-it": "^19.0.4",
81
81
  "turbo": "^1.10.7",
82
82
  "typescript": "^5.2.2"
83
83
  },
@@ -117,7 +117,10 @@
117
117
  },
118
118
  "plugins": {
119
119
  "@release-it/conventional-changelog": {
120
- "preset": "angular"
120
+ "preset": {
121
+ "name": "angular"
122
+ },
123
+ "infile": "CHANGELOG.md"
121
124
  }
122
125
  }
123
126
  },
package/src/index.ts CHANGED
@@ -24,17 +24,44 @@ const ServiceDiscovery = ServiceDiscoveryModule
24
24
  }
25
25
  );
26
26
 
27
+ /**
28
+ * A service that is found or lost on the network.
29
+ */
27
30
  export interface Service {
31
+ /**
32
+ * Service name.
33
+ */
28
34
  readonly name: string;
35
+ /**
36
+ * Service type, e.g. `_http._tcp.`.
37
+ */
29
38
  readonly type: string;
39
+ /**
40
+ * Domain, can be `local.` or any other domain.
41
+ */
30
42
  readonly domain: string;
43
+ /**
44
+ * The domain name of the IP advertising the service.
45
+ * On local networks this is usually the host name.
46
+ */
31
47
  readonly hostName: string;
48
+ /**
49
+ * The IP addresses of the service.
50
+ * This is an array of IPv4 and IPv6 addresses.
51
+ */
32
52
  readonly addresses: string[];
53
+ /**
54
+ * The port number where the service can be reached.
55
+ */
33
56
  readonly port: number;
57
+ /**
58
+ * The TXT record of the service. The TXT record gives additional information
59
+ * about the service.
60
+ */
34
61
  readonly txt: Record<string, string>;
35
62
  }
36
63
 
37
- export type ServiceEvent = 'serviceFound' | 'serviceLost' | 'error';
64
+ export type ServiceEvent = 'serviceFound' | 'serviceLost';
38
65
 
39
66
  export type ServiceCallback = (service: Service) => void;
40
67
 
@@ -44,13 +71,50 @@ export interface Subscription {
44
71
 
45
72
  const EventEmitter = new NativeEventEmitter(ServiceDiscovery);
46
73
 
74
+ /**
75
+ *
76
+ * @example
77
+ * ```ts
78
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
79
+ *
80
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
81
+ *
82
+ * // Start searching for _http._tcp. services
83
+ * await ServiceDiscovery.startSearch('http');
84
+ * ```
85
+ */
47
86
  export const addEventListener = (
48
87
  event: ServiceEvent,
49
88
  listener: ServiceCallback
50
89
  ): Subscription => EventEmitter.addListener(event, listener);
51
90
 
91
+ /**
92
+ * Start searching for services of a specific type. Searching for
93
+ * multiple services can be done in parallel.
94
+ *
95
+ * @param serviceType The service type to search for, e.g. 'http'. The device
96
+ * will search for services of type `_serviceType._tcp.`.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import * as ServiceDiscovery from '@inthepocket/react-native-service-discovery';
101
+ *
102
+ * ServiceDiscovery.addEventListener('serviceFound', (service) => console.log('Service found:', service));
103
+ *
104
+ * // Start searching for _http._tcp. services
105
+ * await ServiceDiscovery.startSearch('http');
106
+ * ```
107
+ */
52
108
  export const startSearch = (serviceType: string): Promise<void> =>
53
109
  ServiceDiscovery.startSearch(serviceType);
54
110
 
111
+ /**
112
+ * Stop searching for a specific service. This will not stop searching for any
113
+ * other services that are being searched for.
114
+ *
115
+ * @returns A promise that resolves when the search has been stopped, and
116
+ * rejects if the search cannot be stopped. Does not reject if the search has
117
+ * already been stopped.
118
+ */
55
119
  export const stopSearch = (serviceType: string): Promise<void> =>
56
120
  ServiceDiscovery.stopSearch(serviceType);