161847f8eSopenharmony_ci/* 261847f8eSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 361847f8eSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 461847f8eSopenharmony_ci * you may not use this file except in compliance with the License. 561847f8eSopenharmony_ci * You may obtain a copy of the License at 661847f8eSopenharmony_ci * 761847f8eSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 861847f8eSopenharmony_ci * 961847f8eSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1061847f8eSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1161847f8eSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1261847f8eSopenharmony_ci * See the License for the specific language governing permissions and 1361847f8eSopenharmony_ci * limitations under the License. 1461847f8eSopenharmony_ci */ 1561847f8eSopenharmony_ci 1661847f8eSopenharmony_ci/** 1761847f8eSopenharmony_ci * @file 1861847f8eSopenharmony_ci * @kit NetworkKit 1961847f8eSopenharmony_ci */ 2061847f8eSopenharmony_ci 2161847f8eSopenharmony_ciimport { AsyncCallback, Callback } from "./@ohos.base"; 2261847f8eSopenharmony_ciimport connection from "./@ohos.net.connection"; 2361847f8eSopenharmony_ciimport Context from "./application/Context"; 2461847f8eSopenharmony_ci 2561847f8eSopenharmony_ci/** 2661847f8eSopenharmony_ci * Provides interfaces to discover DNS based services on a local network over Multicast DNS. 2761847f8eSopenharmony_ci * @namespace mdns 2861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 2961847f8eSopenharmony_ci * @since 10 3061847f8eSopenharmony_ci */ 3161847f8eSopenharmony_ci/** 3261847f8eSopenharmony_ci * Provides interfaces to discover DNS based services on a local network over Multicast DNS. 3361847f8eSopenharmony_ci * @namespace mdns 3461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 3561847f8eSopenharmony_ci * @atomicservice 3661847f8eSopenharmony_ci * @since 11 3761847f8eSopenharmony_ci */ 3861847f8eSopenharmony_cideclare namespace mdns { 3961847f8eSopenharmony_ci /** 4061847f8eSopenharmony_ci * Get a network address. 4161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 4261847f8eSopenharmony_ci * @since 10 4361847f8eSopenharmony_ci */ 4461847f8eSopenharmony_ci /** 4561847f8eSopenharmony_ci * Get a network address. 4661847f8eSopenharmony_ci * @typedef { connection.NetAddress } 4761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core 4861847f8eSopenharmony_ci * @atomicservice 4961847f8eSopenharmony_ci * @since 12 5061847f8eSopenharmony_ci */ 5161847f8eSopenharmony_ci type NetAddress = connection.NetAddress; 5261847f8eSopenharmony_ci 5361847f8eSopenharmony_ci /** 5461847f8eSopenharmony_ci * Adds an mDNS service. 5561847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 5661847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 5761847f8eSopenharmony_ci * @param { AsyncCallback<LocalServiceInfo> } callback - the callback of addLocalService. 5861847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 5961847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 6061847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 6161847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 6261847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 6361847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 6461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 6561847f8eSopenharmony_ci * @since 10 6661847f8eSopenharmony_ci */ 6761847f8eSopenharmony_ci /** 6861847f8eSopenharmony_ci * Adds an mDNS service. 6961847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 7061847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 7161847f8eSopenharmony_ci * @param { AsyncCallback<LocalServiceInfo> } callback - the callback of addLocalService. 7261847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 7361847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 7461847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 7561847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 7661847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 7761847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 7861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 7961847f8eSopenharmony_ci * @atomicservice 8061847f8eSopenharmony_ci * @since 11 8161847f8eSopenharmony_ci */ 8261847f8eSopenharmony_ci function addLocalService(context: Context, serviceInfo: LocalServiceInfo, 8361847f8eSopenharmony_ci callback: AsyncCallback<LocalServiceInfo>): void; 8461847f8eSopenharmony_ci 8561847f8eSopenharmony_ci /** 8661847f8eSopenharmony_ci * Adds an mDNS service. 8761847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 8861847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 8961847f8eSopenharmony_ci * @returns { Promise<LocalServiceInfo> } The promise returned by the function. 9061847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 9161847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 9261847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 9361847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 9461847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 9561847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 9661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 9761847f8eSopenharmony_ci * @since 10 9861847f8eSopenharmony_ci */ 9961847f8eSopenharmony_ci /** 10061847f8eSopenharmony_ci * Adds an mDNS service. 10161847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 10261847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 10361847f8eSopenharmony_ci * @returns { Promise<LocalServiceInfo> } The promise returned by the function. 10461847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 10561847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 10661847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 10761847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 10861847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 10961847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 11061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 11161847f8eSopenharmony_ci * @atomicservice 11261847f8eSopenharmony_ci * @since 11 11361847f8eSopenharmony_ci */ 11461847f8eSopenharmony_ci function addLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise<LocalServiceInfo>; 11561847f8eSopenharmony_ci 11661847f8eSopenharmony_ci /** 11761847f8eSopenharmony_ci * Removes an mDNS service. 11861847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 11961847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 12061847f8eSopenharmony_ci * @param { AsyncCallback<LocalServiceInfo> } callback - the callback of removeLocalService. 12161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 12261847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 12361847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 12461847f8eSopenharmony_ci * @throws { BusinessError } 2204002 - Callback not found. 12561847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 12661847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 12761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 12861847f8eSopenharmony_ci * @since 10 12961847f8eSopenharmony_ci */ 13061847f8eSopenharmony_ci /** 13161847f8eSopenharmony_ci * Removes an mDNS service. 13261847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 13361847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 13461847f8eSopenharmony_ci * @param { AsyncCallback<LocalServiceInfo> } callback - the callback of removeLocalService. 13561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 13661847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 13761847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 13861847f8eSopenharmony_ci * @throws { BusinessError } 2204002 - Callback not found. 13961847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 14061847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 14161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 14261847f8eSopenharmony_ci * @atomicservice 14361847f8eSopenharmony_ci * @since 11 14461847f8eSopenharmony_ci */ 14561847f8eSopenharmony_ci function removeLocalService(context: Context, serviceInfo: LocalServiceInfo, 14661847f8eSopenharmony_ci callback: AsyncCallback<LocalServiceInfo>): void; 14761847f8eSopenharmony_ci 14861847f8eSopenharmony_ci /** 14961847f8eSopenharmony_ci * Removes an mDNS service. 15061847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 15161847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 15261847f8eSopenharmony_ci * @returns { Promise<LocalServiceInfo> } The promise returned by the function. 15361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 15461847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 15561847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 15661847f8eSopenharmony_ci * @throws { BusinessError } 2204002 - Callback not found. 15761847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 15861847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 15961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 16061847f8eSopenharmony_ci * @since 10 16161847f8eSopenharmony_ci */ 16261847f8eSopenharmony_ci /** 16361847f8eSopenharmony_ci * Removes an mDNS service. 16461847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 16561847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 16661847f8eSopenharmony_ci * @returns { Promise<LocalServiceInfo> } The promise returned by the function. 16761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 16861847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 16961847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 17061847f8eSopenharmony_ci * @throws { BusinessError } 2204002 - Callback not found. 17161847f8eSopenharmony_ci * @throws { BusinessError } 2204008 - Failed to delete the service instance. 17261847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 17361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 17461847f8eSopenharmony_ci * @atomicservice 17561847f8eSopenharmony_ci * @since 11 17661847f8eSopenharmony_ci */ 17761847f8eSopenharmony_ci function removeLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise<LocalServiceInfo>; 17861847f8eSopenharmony_ci 17961847f8eSopenharmony_ci /** 18061847f8eSopenharmony_ci * Create an mDNS based discovery service with context and serviceType. 18161847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 18261847f8eSopenharmony_ci * @param { string } serviceType - The service type being discovered. 18361847f8eSopenharmony_ci * @returns { DiscoveryService } the DiscoveryService of the createDiscoveryService. 18461847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 18561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 18661847f8eSopenharmony_ci * @since 10 18761847f8eSopenharmony_ci */ 18861847f8eSopenharmony_ci /** 18961847f8eSopenharmony_ci * Create an mDNS based discovery service with context and serviceType. 19061847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 19161847f8eSopenharmony_ci * @param { string } serviceType - The service type being discovered. 19261847f8eSopenharmony_ci * @returns { DiscoveryService } the DiscoveryService of the createDiscoveryService. 19361847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 19461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 19561847f8eSopenharmony_ci * @atomicservice 19661847f8eSopenharmony_ci * @since 11 19761847f8eSopenharmony_ci */ 19861847f8eSopenharmony_ci function createDiscoveryService(context: Context, serviceType: string): DiscoveryService; 19961847f8eSopenharmony_ci 20061847f8eSopenharmony_ci /** 20161847f8eSopenharmony_ci * Resolves an mDNS service. 20261847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 20361847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 20461847f8eSopenharmony_ci * @param { AsyncCallback<LocalServiceInfo> } callback - the callback of resolveLocalService. 20561847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 20661847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 20761847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 20861847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 20961847f8eSopenharmony_ci * @throws { BusinessError } 2204006 - Request timeout. 21061847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 21161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 21261847f8eSopenharmony_ci * @since 10 21361847f8eSopenharmony_ci */ 21461847f8eSopenharmony_ci /** 21561847f8eSopenharmony_ci * Resolves an mDNS service. 21661847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 21761847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 21861847f8eSopenharmony_ci * @param { AsyncCallback<LocalServiceInfo> } callback - the callback of resolveLocalService. 21961847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 22061847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 22161847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 22261847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 22361847f8eSopenharmony_ci * @throws { BusinessError } 2204006 - Request timeout. 22461847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 22561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 22661847f8eSopenharmony_ci * @atomicservice 22761847f8eSopenharmony_ci * @since 11 22861847f8eSopenharmony_ci */ 22961847f8eSopenharmony_ci function resolveLocalService(context: Context, serviceInfo: LocalServiceInfo, 23061847f8eSopenharmony_ci callback: AsyncCallback<LocalServiceInfo>): void; 23161847f8eSopenharmony_ci 23261847f8eSopenharmony_ci /** 23361847f8eSopenharmony_ci * Resolves an mDNS service. 23461847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 23561847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 23661847f8eSopenharmony_ci * @returns { Promise<LocalServiceInfo> } The promise returned by the function. 23761847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 23861847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 23961847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 24061847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 24161847f8eSopenharmony_ci * @throws { BusinessError } 2204006 - Request timeout. 24261847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 24361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 24461847f8eSopenharmony_ci * @since 10 24561847f8eSopenharmony_ci */ 24661847f8eSopenharmony_ci /** 24761847f8eSopenharmony_ci * Resolves an mDNS service. 24861847f8eSopenharmony_ci * @param { Context } context - Indicates the context of application or capability. 24961847f8eSopenharmony_ci * @param { LocalServiceInfo } serviceInfo - Information about the mDNS service. {@link LocalServiceInfo} 25061847f8eSopenharmony_ci * @returns { Promise<LocalServiceInfo> } The promise returned by the function. 25161847f8eSopenharmony_ci * @throws { BusinessError } 401 - Parameter error. 25261847f8eSopenharmony_ci * @throws { BusinessError } 2100002 - Failed to connect to the service. 25361847f8eSopenharmony_ci * @throws { BusinessError } 2100003 - System internal error. 25461847f8eSopenharmony_ci * @throws { BusinessError } 2204003 - Callback duplicated. 25561847f8eSopenharmony_ci * @throws { BusinessError } 2204006 - Request timeout. 25661847f8eSopenharmony_ci * @throws { BusinessError } 2204010 - Failed to send the message. 25761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 25861847f8eSopenharmony_ci * @atomicservice 25961847f8eSopenharmony_ci * @since 11 26061847f8eSopenharmony_ci */ 26161847f8eSopenharmony_ci function resolveLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise<LocalServiceInfo>; 26261847f8eSopenharmony_ci 26361847f8eSopenharmony_ci /** 26461847f8eSopenharmony_ci * Defines a DiscoveryService object for discovering mDNS services of the specified type. 26561847f8eSopenharmony_ci * @interface DiscoveryService 26661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 26761847f8eSopenharmony_ci * @since 10 26861847f8eSopenharmony_ci */ 26961847f8eSopenharmony_ci /** 27061847f8eSopenharmony_ci * Defines a DiscoveryService object for discovering mDNS services of the specified type. 27161847f8eSopenharmony_ci * @interface DiscoveryService 27261847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 27361847f8eSopenharmony_ci * @atomicservice 27461847f8eSopenharmony_ci * @since 11 27561847f8eSopenharmony_ci */ 27661847f8eSopenharmony_ci export interface DiscoveryService { 27761847f8eSopenharmony_ci /** 27861847f8eSopenharmony_ci * Enables listening for discoveryStart events of mDNS services. 27961847f8eSopenharmony_ci * @param { 'discoveryStart' } type - Indicates Event name. 28061847f8eSopenharmony_ci * @param { Callback<{ serviceInfo: LocalServiceInfo, errorCode?: MdnsError }> } callback - the callback used to return the result. 28161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 28261847f8eSopenharmony_ci * @since 10 28361847f8eSopenharmony_ci */ 28461847f8eSopenharmony_ci /** 28561847f8eSopenharmony_ci * Enables listening for discoveryStart events of mDNS services. 28661847f8eSopenharmony_ci * @param { 'discoveryStart' } type - Indicates Event name. 28761847f8eSopenharmony_ci * @param { Callback<DiscoveryEventInfo> } callback - the callback used to return the result. 28861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 28961847f8eSopenharmony_ci * @atomicservice 29061847f8eSopenharmony_ci * @since 11 29161847f8eSopenharmony_ci */ 29261847f8eSopenharmony_ci on(type: 'discoveryStart', callback: Callback<DiscoveryEventInfo>): void; 29361847f8eSopenharmony_ci 29461847f8eSopenharmony_ci /** 29561847f8eSopenharmony_ci * Cancels listening for discoveryStart events of mDNS services. 29661847f8eSopenharmony_ci * @param { 'discoveryStart' } type - Indicates Event name. 29761847f8eSopenharmony_ci * @param { Callback<{ serviceInfo: LocalServiceInfo, errorCode?: MdnsError }> } callback - the callback used to return the result. 29861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 29961847f8eSopenharmony_ci * @since 10 30061847f8eSopenharmony_ci */ 30161847f8eSopenharmony_ci /** 30261847f8eSopenharmony_ci * Cancels listening for discoveryStart events of mDNS services. 30361847f8eSopenharmony_ci * @param { 'discoveryStart' } type - Indicates Event name. 30461847f8eSopenharmony_ci * @param { Callback<DiscoveryEventInfo> } callback - the callback used to return the result. 30561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 30661847f8eSopenharmony_ci * @atomicservice 30761847f8eSopenharmony_ci * @since 11 30861847f8eSopenharmony_ci */ 30961847f8eSopenharmony_ci off(type: 'discoveryStart', callback?: Callback<DiscoveryEventInfo>): void; 31061847f8eSopenharmony_ci 31161847f8eSopenharmony_ci /** 31261847f8eSopenharmony_ci * Enables listening for discoveryStop events of mDNS services. 31361847f8eSopenharmony_ci * @param { 'discoveryStop' } type - Indicates Event name. 31461847f8eSopenharmony_ci * @param { Callback<{ serviceInfo: LocalServiceInfo, errorCode?: MdnsError }> } callback - the callback used to return the result. 31561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 31661847f8eSopenharmony_ci * @since 10 31761847f8eSopenharmony_ci */ 31861847f8eSopenharmony_ci /** 31961847f8eSopenharmony_ci * Enables listening for discoveryStop events of mDNS services. 32061847f8eSopenharmony_ci * @param { 'discoveryStop' } type - Indicates Event name. 32161847f8eSopenharmony_ci * @param { Callback<DiscoveryEventInfo> } callback - the callback used to return the result. 32261847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 32361847f8eSopenharmony_ci * @atomicservice 32461847f8eSopenharmony_ci * @since 11 32561847f8eSopenharmony_ci */ 32661847f8eSopenharmony_ci on(type: 'discoveryStop', callback: Callback<DiscoveryEventInfo>): void; 32761847f8eSopenharmony_ci 32861847f8eSopenharmony_ci /** 32961847f8eSopenharmony_ci * Cancels listening for discoveryStop events of mDNS services. 33061847f8eSopenharmony_ci * @param { 'discoveryStop' } type - Indicates Event name. 33161847f8eSopenharmony_ci * @param { Callback<{ serviceInfo: LocalServiceInfo, errorCode?: MdnsError }> } callback - the callback used to return the result. 33261847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 33361847f8eSopenharmony_ci * @since 10 33461847f8eSopenharmony_ci */ 33561847f8eSopenharmony_ci /** 33661847f8eSopenharmony_ci * Cancels listening for discoveryStop events of mDNS services. 33761847f8eSopenharmony_ci * @param { 'discoveryStop' } type - Indicates Event name. 33861847f8eSopenharmony_ci * @param { Callback<DiscoveryEventInfo> } callback - the callback used to return the result. 33961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 34061847f8eSopenharmony_ci * @atomicservice 34161847f8eSopenharmony_ci * @since 11 34261847f8eSopenharmony_ci */ 34361847f8eSopenharmony_ci off(type: 'discoveryStop', callback?: Callback<DiscoveryEventInfo>): void; 34461847f8eSopenharmony_ci 34561847f8eSopenharmony_ci /** 34661847f8eSopenharmony_ci * Enables listening for serviceFound events of mDNS services. 34761847f8eSopenharmony_ci * @param { 'serviceFound' } type - Indicates Event name. 34861847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 34961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 35061847f8eSopenharmony_ci * @since 10 35161847f8eSopenharmony_ci */ 35261847f8eSopenharmony_ci /** 35361847f8eSopenharmony_ci * Enables listening for serviceFound events of mDNS services. 35461847f8eSopenharmony_ci * @param { 'serviceFound' } type - Indicates Event name. 35561847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 35661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 35761847f8eSopenharmony_ci * @atomicservice 35861847f8eSopenharmony_ci * @since 11 35961847f8eSopenharmony_ci */ 36061847f8eSopenharmony_ci on(type: 'serviceFound', callback: Callback<LocalServiceInfo>): void; 36161847f8eSopenharmony_ci 36261847f8eSopenharmony_ci /** 36361847f8eSopenharmony_ci * Cancels listening for serviceFound events of mDNS services. 36461847f8eSopenharmony_ci * @param { 'serviceFound' } type - Indicates Event name. 36561847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 36661847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 36761847f8eSopenharmony_ci * @since 10 36861847f8eSopenharmony_ci */ 36961847f8eSopenharmony_ci /** 37061847f8eSopenharmony_ci * Cancels listening for serviceFound events of mDNS services. 37161847f8eSopenharmony_ci * @param { 'serviceFound' } type - Indicates Event name. 37261847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 37361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 37461847f8eSopenharmony_ci * @atomicservice 37561847f8eSopenharmony_ci * @since 11 37661847f8eSopenharmony_ci */ 37761847f8eSopenharmony_ci off(type: 'serviceFound', callback?: Callback<LocalServiceInfo>): void; 37861847f8eSopenharmony_ci 37961847f8eSopenharmony_ci /** 38061847f8eSopenharmony_ci * Enables listening for serviceLost events of mDNS services. 38161847f8eSopenharmony_ci * @param { 'serviceLost' } type - Indicates Event name. 38261847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 38361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 38461847f8eSopenharmony_ci * @since 10 38561847f8eSopenharmony_ci */ 38661847f8eSopenharmony_ci /** 38761847f8eSopenharmony_ci * Enables listening for serviceLost events of mDNS services. 38861847f8eSopenharmony_ci * @param { 'serviceLost' } type - Indicates Event name. 38961847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 39061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 39161847f8eSopenharmony_ci * @atomicservice 39261847f8eSopenharmony_ci * @since 11 39361847f8eSopenharmony_ci */ 39461847f8eSopenharmony_ci on(type: 'serviceLost', callback: Callback<LocalServiceInfo>): void; 39561847f8eSopenharmony_ci 39661847f8eSopenharmony_ci /** 39761847f8eSopenharmony_ci * Cancels listening for serviceLost events of mDNS services. 39861847f8eSopenharmony_ci * @param { 'serviceLost' } type - Indicates Event name. 39961847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 40061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 40161847f8eSopenharmony_ci * @since 10 40261847f8eSopenharmony_ci */ 40361847f8eSopenharmony_ci /** 40461847f8eSopenharmony_ci * Cancels listening for serviceLost events of mDNS services. 40561847f8eSopenharmony_ci * @param { 'serviceLost' } type - Indicates Event name. 40661847f8eSopenharmony_ci * @param { Callback<LocalServiceInfo> } callback - the callback used to return the result. 40761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 40861847f8eSopenharmony_ci * @atomicservice 40961847f8eSopenharmony_ci * @since 11 41061847f8eSopenharmony_ci */ 41161847f8eSopenharmony_ci off(type: 'serviceLost', callback?: Callback<LocalServiceInfo>): void; 41261847f8eSopenharmony_ci 41361847f8eSopenharmony_ci /** 41461847f8eSopenharmony_ci * Starts searching for mDNS services on the LAN. 41561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 41661847f8eSopenharmony_ci * @since 10 41761847f8eSopenharmony_ci */ 41861847f8eSopenharmony_ci /** 41961847f8eSopenharmony_ci * Starts searching for mDNS services on the LAN. 42061847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 42161847f8eSopenharmony_ci * @atomicservice 42261847f8eSopenharmony_ci * @since 11 42361847f8eSopenharmony_ci */ 42461847f8eSopenharmony_ci startSearchingMDNS(): void; 42561847f8eSopenharmony_ci 42661847f8eSopenharmony_ci /** 42761847f8eSopenharmony_ci * Stops searching for mDNS services on the LAN. 42861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 42961847f8eSopenharmony_ci * @since 10 43061847f8eSopenharmony_ci */ 43161847f8eSopenharmony_ci /** 43261847f8eSopenharmony_ci * Stops searching for mDNS services on the LAN. 43361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 43461847f8eSopenharmony_ci * @atomicservice 43561847f8eSopenharmony_ci * @since 11 43661847f8eSopenharmony_ci */ 43761847f8eSopenharmony_ci stopSearchingMDNS(): void; 43861847f8eSopenharmony_ci } 43961847f8eSopenharmony_ci 44061847f8eSopenharmony_ci /** 44161847f8eSopenharmony_ci * Defines the mDNS service information. 44261847f8eSopenharmony_ci * @interface LocalServiceInfo 44361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 44461847f8eSopenharmony_ci * @since 10 44561847f8eSopenharmony_ci */ 44661847f8eSopenharmony_ci /** 44761847f8eSopenharmony_ci * Defines the mDNS service information. 44861847f8eSopenharmony_ci * @interface LocalServiceInfo 44961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 45061847f8eSopenharmony_ci * @atomicservice 45161847f8eSopenharmony_ci * @since 11 45261847f8eSopenharmony_ci */ 45361847f8eSopenharmony_ci export interface LocalServiceInfo { 45461847f8eSopenharmony_ci /** 45561847f8eSopenharmony_ci * Service type. Use an underscore (_) as the prefix, for example, _http._tcp. 45661847f8eSopenharmony_ci * @type {string} 45761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 45861847f8eSopenharmony_ci * @since 10 45961847f8eSopenharmony_ci */ 46061847f8eSopenharmony_ci /** 46161847f8eSopenharmony_ci * Service type. Use an underscore (_) as the prefix, for example, _http._tcp. 46261847f8eSopenharmony_ci * @type {string} 46361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 46461847f8eSopenharmony_ci * @atomicservice 46561847f8eSopenharmony_ci * @since 11 46661847f8eSopenharmony_ci */ 46761847f8eSopenharmony_ci serviceType: string; 46861847f8eSopenharmony_ci /** 46961847f8eSopenharmony_ci * Service name. 47061847f8eSopenharmony_ci * @type {string} 47161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 47261847f8eSopenharmony_ci * @since 10 47361847f8eSopenharmony_ci */ 47461847f8eSopenharmony_ci /** 47561847f8eSopenharmony_ci * Service name. 47661847f8eSopenharmony_ci * @type {string} 47761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 47861847f8eSopenharmony_ci * @atomicservice 47961847f8eSopenharmony_ci * @since 11 48061847f8eSopenharmony_ci */ 48161847f8eSopenharmony_ci serviceName: string; 48261847f8eSopenharmony_ci /** 48361847f8eSopenharmony_ci * Port number. 48461847f8eSopenharmony_ci * @type {?number} 48561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 48661847f8eSopenharmony_ci * @since 10 48761847f8eSopenharmony_ci */ 48861847f8eSopenharmony_ci /** 48961847f8eSopenharmony_ci * Port number. 49061847f8eSopenharmony_ci * @type {?number} 49161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 49261847f8eSopenharmony_ci * @atomicservice 49361847f8eSopenharmony_ci * @since 11 49461847f8eSopenharmony_ci */ 49561847f8eSopenharmony_ci port?: number; 49661847f8eSopenharmony_ci /** 49761847f8eSopenharmony_ci * IP address of the host. 49861847f8eSopenharmony_ci * @type {?NetAddress} 49961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 50061847f8eSopenharmony_ci * @since 10 50161847f8eSopenharmony_ci */ 50261847f8eSopenharmony_ci /** 50361847f8eSopenharmony_ci * IP address of the host. 50461847f8eSopenharmony_ci * @type {?NetAddress} 50561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 50661847f8eSopenharmony_ci * @atomicservice 50761847f8eSopenharmony_ci * @since 11 50861847f8eSopenharmony_ci */ 50961847f8eSopenharmony_ci host?: NetAddress; 51061847f8eSopenharmony_ci /** 51161847f8eSopenharmony_ci * DNS-SD TXT record pairs. 51261847f8eSopenharmony_ci * @type {?Array<ServiceAttribute>} 51361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 51461847f8eSopenharmony_ci * @since 10 51561847f8eSopenharmony_ci */ 51661847f8eSopenharmony_ci /** 51761847f8eSopenharmony_ci * DNS-SD TXT record pairs. 51861847f8eSopenharmony_ci * @type {?Array<ServiceAttribute>} 51961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 52061847f8eSopenharmony_ci * @atomicservice 52161847f8eSopenharmony_ci * @since 11 52261847f8eSopenharmony_ci */ 52361847f8eSopenharmony_ci serviceAttribute?: Array<ServiceAttribute>; 52461847f8eSopenharmony_ci } 52561847f8eSopenharmony_ci 52661847f8eSopenharmony_ci /** 52761847f8eSopenharmony_ci * Defines the mDNS service attribute information. 52861847f8eSopenharmony_ci * @interface ServiceAttribute 52961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 53061847f8eSopenharmony_ci * @since 10 53161847f8eSopenharmony_ci */ 53261847f8eSopenharmony_ci /** 53361847f8eSopenharmony_ci * Defines the mDNS service attribute information. 53461847f8eSopenharmony_ci * @interface ServiceAttribute 53561847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 53661847f8eSopenharmony_ci * @atomicservice 53761847f8eSopenharmony_ci * @since 11 53861847f8eSopenharmony_ci */ 53961847f8eSopenharmony_ci export interface ServiceAttribute { 54061847f8eSopenharmony_ci /** 54161847f8eSopenharmony_ci * TXT record key. 54261847f8eSopenharmony_ci * @type {string} 54361847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 54461847f8eSopenharmony_ci * @since 10 54561847f8eSopenharmony_ci */ 54661847f8eSopenharmony_ci /** 54761847f8eSopenharmony_ci * TXT record key. 54861847f8eSopenharmony_ci * @type {string} 54961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 55061847f8eSopenharmony_ci * @atomicservice 55161847f8eSopenharmony_ci * @since 11 55261847f8eSopenharmony_ci */ 55361847f8eSopenharmony_ci key: string; 55461847f8eSopenharmony_ci 55561847f8eSopenharmony_ci /** 55661847f8eSopenharmony_ci * TXT record value. 55761847f8eSopenharmony_ci * @type {Array<number>} 55861847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 55961847f8eSopenharmony_ci * @since 10 56061847f8eSopenharmony_ci */ 56161847f8eSopenharmony_ci /** 56261847f8eSopenharmony_ci * TXT record value. 56361847f8eSopenharmony_ci * @type {Array<number>} 56461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 56561847f8eSopenharmony_ci * @atomicservice 56661847f8eSopenharmony_ci * @since 11 56761847f8eSopenharmony_ci */ 56861847f8eSopenharmony_ci value: Array<number>; 56961847f8eSopenharmony_ci } 57061847f8eSopenharmony_ci 57161847f8eSopenharmony_ci /** 57261847f8eSopenharmony_ci * Defines the discovery events information of mDNS services. 57361847f8eSopenharmony_ci * @interface DiscoveryEventInfo 57461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 57561847f8eSopenharmony_ci * @atomicservice 57661847f8eSopenharmony_ci * @since 11 57761847f8eSopenharmony_ci */ 57861847f8eSopenharmony_ci export interface DiscoveryEventInfo { 57961847f8eSopenharmony_ci /** 58061847f8eSopenharmony_ci * Information about the mDNS service. 58161847f8eSopenharmony_ci * @type {LocalServiceInfo} 58261847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 58361847f8eSopenharmony_ci * @atomicservice 58461847f8eSopenharmony_ci * @since 11 58561847f8eSopenharmony_ci */ 58661847f8eSopenharmony_ci serviceInfo: LocalServiceInfo; 58761847f8eSopenharmony_ci 58861847f8eSopenharmony_ci /** 58961847f8eSopenharmony_ci * The mDNS error information. 59061847f8eSopenharmony_ci * @type {?MdnsError} 59161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 59261847f8eSopenharmony_ci * @atomicservice 59361847f8eSopenharmony_ci * @since 11 59461847f8eSopenharmony_ci */ 59561847f8eSopenharmony_ci errorCode?: MdnsError; 59661847f8eSopenharmony_ci } 59761847f8eSopenharmony_ci 59861847f8eSopenharmony_ci /** 59961847f8eSopenharmony_ci * Defines the mDNS error information. 60061847f8eSopenharmony_ci * @enum {number} 60161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 60261847f8eSopenharmony_ci * @since 10 60361847f8eSopenharmony_ci */ 60461847f8eSopenharmony_ci /** 60561847f8eSopenharmony_ci * Defines the mDNS error information. 60661847f8eSopenharmony_ci * @enum {number} 60761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 60861847f8eSopenharmony_ci * @atomicservice 60961847f8eSopenharmony_ci * @since 11 61061847f8eSopenharmony_ci */ 61161847f8eSopenharmony_ci export enum MdnsError { 61261847f8eSopenharmony_ci /** 61361847f8eSopenharmony_ci * Indicates that the operation failed due to internal error. 61461847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 61561847f8eSopenharmony_ci * @since 10 61661847f8eSopenharmony_ci */ 61761847f8eSopenharmony_ci /** 61861847f8eSopenharmony_ci * Indicates that the operation failed due to internal error. 61961847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 62061847f8eSopenharmony_ci * @atomicservice 62161847f8eSopenharmony_ci * @since 11 62261847f8eSopenharmony_ci */ 62361847f8eSopenharmony_ci INTERNAL_ERROR = 0, 62461847f8eSopenharmony_ci 62561847f8eSopenharmony_ci /** 62661847f8eSopenharmony_ci * Indicates that the operation failed because it is already active. 62761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 62861847f8eSopenharmony_ci * @since 10 62961847f8eSopenharmony_ci */ 63061847f8eSopenharmony_ci /** 63161847f8eSopenharmony_ci * Indicates that the operation failed because it is already active. 63261847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 63361847f8eSopenharmony_ci * @atomicservice 63461847f8eSopenharmony_ci * @since 11 63561847f8eSopenharmony_ci */ 63661847f8eSopenharmony_ci ALREADY_ACTIVE = 1, 63761847f8eSopenharmony_ci 63861847f8eSopenharmony_ci /** 63961847f8eSopenharmony_ci * <p>Indicates that the operation failed because the maximum outstanding 64061847f8eSopenharmony_ci * requests from the applications have reached.</p> 64161847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 64261847f8eSopenharmony_ci * @since 10 64361847f8eSopenharmony_ci */ 64461847f8eSopenharmony_ci /** 64561847f8eSopenharmony_ci * <p>Indicates that the operation failed because the maximum outstanding 64661847f8eSopenharmony_ci * requests from the applications have reached.</p> 64761847f8eSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.MDNS 64861847f8eSopenharmony_ci * @atomicservice 64961847f8eSopenharmony_ci * @since 11 65061847f8eSopenharmony_ci */ 65161847f8eSopenharmony_ci MAX_LIMIT = 2 65261847f8eSopenharmony_ci } 65361847f8eSopenharmony_ci} 65461847f8eSopenharmony_ci 65561847f8eSopenharmony_ci/** 65661847f8eSopenharmony_ci * @since 10 65761847f8eSopenharmony_ci */ 65861847f8eSopenharmony_ciexport default mdns; 659