1/* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16export interface NetworkResponse { 17 /** 18 * Network type. The value can be 2G, 3G, 4G, WiFi, or none. 19 * @since 3 20 */ 21 type: string; 22 23 /** 24 * Whether the billing is based on the data volume. 25 * @since 3 26 */ 27 metered: boolean; 28} 29 30/** 31 * @devices tv, phone, tablet, wearable 32 */ 33export interface GetNetworkTypeOptions { 34 /** 35 * Called when the network type is obtained. 36 * @devices tv, phone, tablet, wearable 37 * @since 3 38 */ 39 success?: (data: NetworkResponse) => void; 40 41 /** 42 * Called when the network type fails to be obtained. 43 * @devices tv, phone, tablet, wearable 44 * @since 3 45 */ 46 fail?: (data: any, code: number) => void; 47 48 /** 49 * Called when the execution is completed. 50 * @devices tv, phone, tablet, wearable 51 * @since 3 52 */ 53 complete?: () => void; 54} 55 56/** 57 * @devices tv, phone, tablet, wearable 58 */ 59export interface SubscribeNetworkOptions { 60 /** 61 * Called when the network connection state changes. 62 * @devices tv, phone, tablet, wearable 63 * @since 3 64 */ 65 success?: (data: NetworkResponse) => void; 66 67 /** 68 * Called when the listening fails. 69 * @devices tv, phone, tablet, wearable 70 * @since 3 71 */ 72 fail?: (data: any, code: number) => void; 73} 74 75/** 76 * @devices tv, phone, tablet, wearable 77 */ 78export default class Network { 79 /** 80 * Obtains the network type. 81 * @devices tv, phone, tablet, wearable 82 * @param options Options. 83 */ 84 static getType(options?: GetNetworkTypeOptions): void; 85 86 /** 87 * Listens to the network connection state. If this method is called multiple times, the last call takes effect. 88 * @param options Options. 89 * @devices tv, phone, tablet, wearable 90 */ 91 static subscribe(options?: SubscribeNetworkOptions): void; 92 93 /** 94 * Cancels listening to the network connection state. 95 * @devices tv, phone, tablet, wearable 96 */ 97 static unsubscribe(): void; 98} 99