capacitor-mdns-discovery
v0.0.4
Published
mDNS device discovery for IoT Devices
Readme
capacitor-mdns-discovery
mDNS device discovery for IoT Devices
Install
npm install capacitor-mdns-discovery
npx cap synciOS
For iOS, make sure you enable local network and Bonjour service discovery in your app’s Info.plist:
<key>NSLocalNetworkUsageDescription</key>
<string>Discover devices on the local network.</string>
<key>NSBonjourServices</key>
<array>
<string>_http._tcp.</string>
<!-- Add any additional service types you intend to discover -->
</array>Android
No additional configuration is required beyond the standard Capacitor Android setup. Ensure your app includes network permissions (such as INTERNET) which are enabled by default in most Capacitor templates.
Build
npm install
npm run lint
npm run buildTo fully verify the plugin and regenerate the API docs section below, run:
npm run verifyPublishing
This package is a standard Capacitor plugin and can be published to npm like any other npm package:
npm version patch # or minor / major
git push --follow-tags
npm publish --access publicAlternatively, once you have configured an NPM_TOKEN secret in your GitHub repository, you can create a GitHub Release and let the Publish to npm workflow handle building and publishing for you.
API
startDiscovery(...)stopDiscovery(...)addListener('deviceFound', ...)addListener('deviceLost', ...)addListener('discoveryError', ...)removeAllListeners()- Interfaces
- Type Aliases
startDiscovery(...)
startDiscovery(options?: StartDiscoveryOptions | undefined) => Promise<void>| Param | Type |
| ------------- | ----------------------------------------------------------------------- |
| options | StartDiscoveryOptions |
stopDiscovery(...)
stopDiscovery(options?: StopDiscoveryOptions | undefined) => Promise<void>| Param | Type |
| ------------- | --------------------------------------------------------------------- |
| options | StopDiscoveryOptions |
addListener('deviceFound', ...)
addListener(eventName: 'deviceFound', listenerFunc: (device: MdnsDevice) => void) => Promise<{ remove: () => void; }>| Param | Type |
| ------------------ | ---------------------------------------------------------------------- |
| eventName | 'deviceFound' |
| listenerFunc | (device: MdnsDevice) => void |
Returns: Promise<{ remove: () => void; }>
addListener('deviceLost', ...)
addListener(eventName: 'deviceLost', listenerFunc: (device: Pick<MdnsDevice, 'name' | 'serviceType'>) => void) => Promise<{ remove: () => void; }>| Param | Type |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------- |
| eventName | 'deviceLost' |
| listenerFunc | (device: Pick<MdnsDevice, 'name' | 'serviceType'>) => void |
Returns: Promise<{ remove: () => void; }>
addListener('discoveryError', ...)
addListener(eventName: 'discoveryError', listenerFunc: (error: { message: string; code: number; }) => void) => Promise<{ remove: () => void; }>| Param | Type |
| ------------------ | ------------------------------------------------------------------- |
| eventName | 'discoveryError' |
| listenerFunc | (error: { message: string; code: number; }) => void |
Returns: Promise<{ remove: () => void; }>
removeAllListeners()
removeAllListeners() => Promise<void>Interfaces
StartDiscoveryOptions
| Prop | Type |
| ----------------- | ------------------- |
| serviceType | string |
StopDiscoveryOptions
| Prop | Type |
| ----------------- | ------------------- |
| serviceType | string |
MdnsDevice
| Prop | Type |
| ----------------- | --------------------------------------------------------------- |
| name | string |
| host | string |
| port | number |
| serviceType | string |
| txtRecords | Record<string, string> |
Type Aliases
Record
Construct a type with a set of properties K of type T
{ [P in K]: T; }
Pick
From T, pick a set of properties whose keys are in the union K
{ [P in K]: T[P]; }
