mDNS
stopLocalServiceDiscovery
TIP
The API usage is as follows: wx.stopLocalServiceDiscovery(Object object)
Functional description: Stops searching for mDNS services.
Parameters and descriptions: Object object。
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) object.fail callback function parameter: Object res。
Properties Type Description errMsg string Error message, its legal value is task not found: stopLocalServiceDiscovery is called when the service is not currently being searched.
startLocalServiceDiscovery
TIP
The API usage is as follows: wx.startLocalServiceDiscovery(Object object)
TIP
- iOS needs to access the TMFMiniAppExtMDNS extension library to use mDNS related interfaces.
- wx.startLocalServiceDiscovery is a performance-consuming behavior. It will automatically stop and execute after 30 seconds. wx.onLocalServiceDiscoveryStop Registered callback function.
- After calling wx.startLocalServiceDiscovery, the next wx.startLocalServiceDiscovery can only be initiated after the current search behavior stops. The operations to stop the current search behavior include calling wx.stopLocalServiceDiscovery and the system automatically stopping the current search after 30 seconds.
Functional description: Start searching for mDNS services in the LAN. The search results will be returned through wx.onLocalService* events.
Parameters and descriptions: Object object。
Properties Type Default value Required Description serviceType string - Yes Type of service to search success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) object.fail callback function parameter: Object res。
Properties Type Description errMsg string Error message, legal value is
invalid param: serviceType is empty
scan task already exist: If the current search initiated by startLocalServiceDiscovery is not stopped, call startLocalServiceDiscovery againSample code:
wx.startLocalServiceDiscovery({
// There is a service of type _http._tcp. in the local area network connected to the current mobile phone.
serviceType: '_http._tcp.',
success: console.log,
fail: console.log
})offLocalServiceResolveFail
TIP
The API usage is as follows: wx.offLocalServiceResolveFail(function listener)
Functional description: Remove the listener function for events where mDNS service resolution fails
Parameters and descriptions: function listener, Listener function passed in by onLocalServiceResolveFail. If this parameter is not passed, all listeners are removed.
Sample code:
const listener = function (res) { console.log(res) }
wx.onLocalServiceResolveFail(listener)
wx.offLocalServiceResolveFail(listener) // Pass the same function object used for listening.onLocalServiceResolveFail
TIP
The API usage is as follows: wx.onLocalServiceResolveFail(function listener)
Functional description: Listen for events where mDNS service resolution fails
Parameters and descriptions: function listener, Listener function for events of mDNS service resolution failure, parameter Object res is as follows.
Properties Type Description serviceType string Type of service serviceName string Name of service
offLocalServiceLost
TIP
The API usage is as follows: wx.offLocalServiceLost(function listener)
Functional description: Remove the listener function for the mDNS service leaving event.
Parameters and descriptions: function listener, onLocalServiceLost The listener function passed in. If this parameter is not passed, all listeners are removed.
Sample code:
const listener = function (res) { console.log(res) }
wx.onLocalServiceLost(listener)
wx.offLocalServiceLost(listener) // Pass the same function object used for listening.onLocalServiceLost
TIP
The API usage is as follows: wx.onLocalServiceLost(function listener)
Functional description: Listen for the mDNS service leaving event.
Parameters and descriptions: function listener, The listener function for the mDNS service leaving event, the parameter Object res is as follows:
Properties Type Description serviceType string Type of service serviceName string Name of service
offLocalServiceFound
TIP
The API usage is as follows: wx.offLocalServiceFound(function listener)
Functional description: Remove the listener function for the mDNS service discovery event.
Parameters and descriptions: function listener, onLocalServiceFound The listener function passed in. If this parameter is not passed, all listeners are removed.
Sample code:
const listener = function (res) { console.log(res) }
wx.onLocalServiceFound(listener)
wx.offLocalServiceFound(listener) // Pass the same function object used for listening.onLocalServiceFound
TIP
The API usage is as follows: wx.onLocalServiceFound(function listener)
Functional description: Listen for the mDNS service discovery event.
Parameters and descriptions: function listener, The listener function for the mDNS service discovery event, the parameter Object res is as follows:
Properties Type Description serviceType string Type of service serviceName string Name of service ip string The ip address of the service port number The port of the service
offLocalServiceDiscoveryStop
TIP
The API usage is as follows: wx.offLocalServiceDiscoveryStop(function listener)
Functional description: Remove the listener function for the mDNS service stop searching event.
Parameters and descriptions: function listener, onLocalServiceDiscoveryStop The listener function passed in. If this parameter is not passed, all listeners are removed.
Sample code:
const listener = function (res) { console.log(res) }
wx.onLocalServiceDiscoveryStop(listener)
wx.offLocalServiceDiscoveryStop(listener) // Pass the same function object used for listening.onLocalServiceDiscoveryStop
TIP
The API usage is as follows: wx.onLocalServiceDiscoveryStop(function listener)
- Functional description: Listen for the mDNS service stop searching event.
- Parameters and descriptions: function listener, The listener function for the mDNS service stop searching event.