tencent cloud

Feedback

Last updated: 2024-03-05 14:57:45

    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: Object res parameter, function listener, the listening function for the event of mDNS service resolution failure.
    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 listening function passed into onLocalServiceLost. If this parameter is not provided, all listening functions will be removed.
    Sample Code:
    const listener = function (res) { console.log(res) }
    
    wx.onLocalServiceLost(listener)
    wx.offLocalServiceLost(listener) // The same function object 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: Object res parameter, function listener, the listening function for the event of mDNS service departure.
    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, the listening function passed in by onLocalServiceFound. If this parameter is not passed, all listening functions will be 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: Object res parameter, function listener, the listening function for the event of mDNS service discovery.
    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, the listening function passed into onLocalServiceDiscoveryStop. If this parameter is not provided, all listening functions will be 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 listening function for the event of mDNS service stop discovery.
    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