title: Taro.startLocalServiceDiscovery(option)

sidebar_label: startLocalServiceDiscovery

Starts searching for the mDNS service in the LAN. The search results will be returned via the wx.onLocalService* event.

Note

  1. wx.startLocalServiceDiscovery is a performance-consuming behavior that automatically stops after 30 seconds and executes the callback function registered with wx.onLocalServiceDiscoveryStop.

  2. After calling wx.startLocalServiceDiscovery, you cannot call this API again until the search behavior stops. The operations to stop this search behavior include calling wx.stopLocalServiceDiscovery and stopping the search automatically after 30 seconds.

Reference

Type

  1. (option: Option) => void

Parameters

Option

Property Type Required Description
complete (res: CallbackResult) => void No The callback function used when the API call completed (always executed whether the call succeeds or fails)
fail (res: CallbackResult) => void No The callback function for a failed API call
success (res: CallbackResult) => void No The callback function for a successful API call

FailCallbackResult

Property Type Description
errMsg string Error message

Valid values:
- ‘invalid param’: serviceType is empty;
- ‘scan task already exist’: Calls startLocalServiceDiscovery again when the current search initiated by startLocalServiceDiscovery is not stopped;

API Support

API WeChat Mini-Program H5 React Native
Taro.startLocalServiceDiscovery ✔️