tencent cloud

Feedback

Last updated: 2024-11-21 18:41:53

    stopLocalServiceDiscovery

    The method of utilizing this API is wx.stopLocalServiceDiscovery(Object object).
    Function Description: Cease the exploration of mDNS services.
    Parameters and Description: Object object.
    Attributes
    Types
    Default value
    Required
    Note
    success
    function
    -
    Not required
    Callback function for successful interface invocation
    fail
    function
    -
    Not required
    Callback function for unsuccessful interface invocation
    complete
    function
    -
    Not required
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    object.fail Callback Function Parameters: Object res.
    Attributes
    Types
    Note
    errMsg
    string
    Error message, with the valid value being 'task not found': invoked when stopLocalServiceDiscovery is called while not currently in the search service.

    startLocalServiceDiscovery

    The usage method for this API is wx.startLocalServiceDiscovery(Object object)
    Note:
    For iOS, the integration of the TMFMiniAppExtMDNS extension library is required to use the mDNS related interfaces.
    wx.startLocalServiceDiscovery is a performance-consuming action. It will automatically stop after 30 seconds and execute the callback function registered with wx.onLocalServiceDiscoveryStop.
    After invoking wx.startLocalServiceDiscovery, the next wx.startLocalServiceDiscovery can only be initiated once this search action has ceased. Actions to halt this search include invoking wx.stopLocalServiceDiscovery and the system automatically stopping the search after 30 seconds.
    Function Description: Initiates the search for mDNS services within the local area network. The results of the search will be returned via the wx.onLocalService* event.
    Parameters and Description: Object object.
    Attributes
    Types
    Default value
    Required
    Note
    serviceType
    string
    -
    Supported
    The type of service to be searched for
    success
    function
    -
    Not required
    Callback function for successful interface invocation
    fail
    function
    -
    Not required
    Callback function for unsuccessful interface invocation
    complete
    function
    -
    Not required
    Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
    object.fail callback function parameters: Object res.
    Attributes
    Types
    Note
    errMsg
    string
    Error message, valid values are
    Invalid parameter: serviceType is empty.
    Scan task already exists: startLocalServiceDiscovery is called again while the search initiated by the current startLocalServiceDiscovery has not stopped.
    Example 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

    The usage method for this API is wx.offLocalServiceResolveFail(function listener).
    Function Description: Removes the listener function for the event of mDNS service resolution failure.
    Parameters and Description: function listener, the listening function passed in by onLocalServiceResolveFail. If this parameter is not passed, all listening functions will be removed.
    Sample Code:
    const listener = function (res) { console.log(res) }
    
    wx.onLocalServiceResolveFail(listener)
    wx.offLocalServiceResolveFail(listener) // The same function object as the listener must be passed in.

    onLocalServiceResolveFail

    The usage method for this API is wx.onLocalServiceResolveFail(function listener).
    Function Description: Monitors the event of mDNS service resolution failure.
    Parameters and Description: function listener, the listener function for the event that the mDNS service fails to resolve, with the following arguments Object res:
    Attributes
    Types
    Note
    serviceType
    string
    Service Type
    serviceName
    string
    Service Name

    offLocalServiceLost

    The usage method for this API is wx.offLocalServiceLost(function listener).
    Function Description: Removes the listening function for the event of mDNS service departure.
    Parameters and Description: function listener, the listener passed in by onLocalServiceLost. If you don't pass this parameter, you can remove all the listener functions.
    Sample Code:
    const listener = function (res) { console.log(res) }
    
    wx.onLocalServiceLost(listener)
    wx.offLocalServiceLost(listener) // The same function objct as used during listening must be passed in.

    onLocalServiceLost

    The usage method for this API is wx.onLocalServiceLost(function listener).
    Function Description: Monitors the event of mDNS service departure.
    Parameters and Description: function listener, the listener function for the event that the mDNS service leaves, with the following arguments Object res:
    Attributes
    Types
    Note
    serviceType
    string
    Service Type
    serviceName
    string
    Service Name

    offLocalServiceFound

    The usage method for this API is wx.offLocalServiceFound(function listener).
    Function Description: Removes the listening function for the event of mDNS service discovery.
    Parameters and Description: function listener, onLocalServiceFound The listener function passed in. If this parameter is not passed, all listener functions are removed.
    Sample Code:
    const listener = function (res) { console.log(res) }
    
    wx.onLocalServiceFound(listener)
    wx.offLocalServiceFound(listener) // The same function object as the one used during monitoring needs to be passed in.

    onLocalServiceFound

    The usage method for this API is wx.onLocalServiceFound(function listener).
    Function Description: Monitors the event of mDNS service discovery.
    Parameters and Description: function listener, the listener function for events discovered by the mDNS service, with the following arguments Object res:
    Attributes
    Types
    Note
    serviceType
    string
    Service Type
    serviceName
    string
    Service Name
    ip
    string
    The IP address of the service.
    port
    number
    The port of the service.

    offLocalServiceDiscoveryStop

    The usage method for this API is wx.offLocalServiceDiscoveryStop(function listener).
    Function Description: Removes the listening function for the event of mDNS service stop discovery.
    Parameters and Description: function listener, onLocalServiceDiscoveryStop The listener function passed in. If this parameter is not passed, all listener functions are removed.
    Sample Code:
    const listener = function (res) { console.log(res) }
    
    wx.onLocalServiceDiscoveryStop(listener)
    wx.offLocalServiceDiscoveryStop(listener) // The same function object as the listener must be passed in.

    onLocalServiceDiscoveryStop

    The usage method for this API is wx.onLocalServiceDiscoveryStop(function listener).
    Function Description: Monitors the event of mDNS service stop discovery.
    Parameters and Description: function listener, the listener function for the event that the mDNS service stops searching.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support