• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 values 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 * @Syscap SysCap.ACE.UIEngine
32 */
33export default class Network {
34  /**
35   * Obtains the network type.
36   * @param options
37   */
38  static getType(options?: {
39    /**
40     * Called when the network type is obtained.
41     * @since 3
42     */
43    success?: (data: NetworkResponse) => void;
44
45    /**
46     * Called when the network type fails to be obtained.
47     * @since 3
48     */
49    fail?: (data: any, code: number) => void;
50
51    /**
52     * Called when the execution is completed.
53     * @since 3
54     */
55    complete?: () => void;
56  }): void;
57
58  /**
59   * Listens to the network connection state. If this method is called multiple times, the last call takes effect.
60   * @param options
61   */
62  static subscribe(options?: {
63    /**
64     * Called when the network connection state changes.
65     * @since 3
66     */
67    success?: (data: NetworkResponse) => void;
68
69    /**
70     * Called when the listening fails.
71     * @since 3
72     */
73    fail?: (data: any, code: number) => void;
74  }): void;
75
76  /**
77   * Cancels listening to the network connection state.
78   * @param options
79   */
80  static unsubscribe(): void;
81}
82