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 16/** 17 * @devices tv, phone, tablet, wearable 18 */ 19export interface Result { 20 /** 21 * Result code. 22 * @devices tv, phone, tablet, wearable 23 */ 24 code: number; 25 26 /** 27 * Returned data. 28 * @devices tv, phone, tablet, wearable 29 */ 30 data: object; 31} 32 33/** 34 * @devices liteWearable 35 */ 36export interface SubscribeMessageResponse { 37 /** 38 * Peer device ID. 39 * @devices liteWearable 40 */ 41 deviceId: string; 42 43 /** 44 * Name of the bundle where the peer ability locates. The name is case sensitive. 45 * @devices liteWearable 46 */ 47 bundleName: string; 48 49 /** 50 * Peer ability name, which is case sensitive. 51 * @devices liteWearable 52 */ 53 abilityName: string; 54 55 /** 56 * Messages received from the device. 57 * @devices liteWearable 58 */ 59 message: string; 60} 61 62/** 63 * @devices tv, phone, tablet, wearable 64 */ 65export interface CallAbilityParam { 66 /** 67 * Name of the bundle where the ability locates. The name is case sensitive and must be the same as that on the AA side. 68 * @devices tv, phone, tablet, wearable 69 */ 70 bundleName: string; 71 /** 72 * Ability name, which is case sensitive and must be the same as that on the AA side. 73 * @devices tv, phone, tablet, wearable 74 */ 75 abilityName: string; 76 /** 77 * Ability operation code, which defines the service function of an AA and must be consistent with the AA side. 78 * @devices tv, phone, tablet, wearable 79 */ 80 messageCode: number; 81 /** 82 * Ability type. Different types of abilities have different implementation on the AA side. 83 * 0: Ability, which has an independent lifecycle. The FA starts and requests an AA through an RPC. Such type of abilities are used to provide basic services for multiple FAs to call or are used when the abilities should run in the background. 84 * 1: Internal ability, which shares the same process with the FA and communicates with it by calling internal functions. Such type of abilities are used in scenarios that require low response latency and cannot be called by other FAs. 85 * @devices tv, phone, tablet, wearable 86 */ 87 abilityType: number; 88 /** 89 * Data sent to the ability. The data to carry differs depending on the service to be processed and its field name must be consistent with the AA side. 90 * @devices tv, phone, tablet, wearable 91 */ 92 data?: object; 93 /** 94 * Whether the request is synchronous or asynchronous. The synchronous mode is used by default. Currently, the asynchronous mode is available only for internal abilities. 95 * 0: Synchronous mode (default value) 96 * 1: Asynchronous mode 97 * @devices tv, phone, tablet, wearable 98 */ 99 syncOption?: number; 100} 101 102/** 103 * @devices tv, phone, tablet, wearable 104 */ 105export interface SubscribeAbilityEventParam { 106 /** 107 * Name of the bundle where the ability locates. The name is case sensitive and must be the same as that on the AA side. 108 * @devices tv, phone, tablet, wearable 109 */ 110 bundleName: string; 111 /** 112 * Ability name, which is case sensitive and must be the same as that on the AA side. 113 * @devices tv, phone, tablet, wearable 114 */ 115 abilityName: string; 116 /** 117 * Ability operation code, which defines the service function of an AA and must be consistent with the AA side. 118 * @devices tv, phone, tablet, wearable 119 */ 120 messageCode: number; 121 /** 122 * Ability type. Different types of abilities have different implementation on the AA side. 123 * 0: Ability, which has an independent lifecycle. The FA starts and requests an AA through an RPC. Such type of abilities are used to provide basic services for multiple FAs to call or are used when the abilities should run in the background. 124 * 1: Internal ability, which shares the same process with the FA and communicates with it by calling internal functions. Such type of abilities are used in scenarios that require low response latency and cannot be called by other FAs. 125 * @devices tv, phone, tablet, wearable 126 */ 127 abilityType: number; 128 /** 129 * Whether the request is synchronous or asynchronous. The synchronous mode is used by default. Currently, the asynchronous mode is available only for internal abilities. 130 * 0: Synchronous mode (default value) 131 * 1: Asynchronous mode 132 * @devices tv, phone, tablet, wearable 133 */ 134 syncOption?: number; 135} 136 137/** 138 * @devices liteWearable 139 */ 140export interface SendMessageOptions { 141 /** 142 * Destination device ID. 143 * @devices liteWearable 144 */ 145 deviceId: string; 146 147 /** 148 * Name of the destination bundle where the ability locates. The name is case sensitive. 149 * @devices liteWearable 150 */ 151 bundleName: string; 152 153 /** 154 * Destination ability name, which is case sensitive. 155 * @devices liteWearable 156 */ 157 abilityName: string; 158 159 /** 160 * Messages sent to the destination device. 161 * A maximum of 1 KB of data can be transmitted at a time. 162 * If more than 1 KB of data needs to be transmitted, split the messages into multiple parts to transmit. 163 * @devices liteWearable 164 */ 165 message?: string; 166 167 /** 168 * Called when the messages are sent successfully. 169 * @devices liteWearable 170 */ 171 success?: () => void; 172 173 /** 174 * Called when the messages fail to be sent. 175 * @devices liteWearable 176 */ 177 fail?: (data: string, code: number) => void; 178 179 /** 180 * Called when the execution is completed. 181 * @devices liteWearable 182 */ 183 complete?: () => void; 184} 185 186/** 187 * @devices liteWearable 188 */ 189export interface SubscribeMessageOptions { 190 /** 191 * Called when the messages are sent successfully. 192 * @devices liteWearable 193 */ 194 success?: (data: SubscribeMessageResponse) => void; 195 196 /** 197 * Called when the messages fail to be sent. 198 * @devices liteWearable 199 */ 200 fail?: (data: string, code: number) => void; 201} 202 203/** 204 * @devices tv, phone, tablet, wearable 205 */ 206export interface RequestParams { 207 /** 208 * The name of the bundle to start. It should be used with abilityname and case sensitive. 209 * @devices tv, phone, tablet, wearable 210 */ 211 bundleName?: string; 212 /** 213 * Ability name, which is case sensitive. 214 * @devices tv, phone, tablet, wearable 215 */ 216 abilityName?: string; 217 /** 218 * The list of entities to which the FA to be called. If it is not filled in, all entity lists will be found by default. It should be used with action. 219 * @devices tv, phone, tablet, wearable 220 */ 221 entities?: Array<string>; 222 /** 223 * Without specifying the bundle name and ability name, you can start the application according to other properties with action. 224 * @devices tv, phone, tablet, wearable 225 */ 226 action?: string; 227 /** 228 * If more than one FA meets the conditions, the user can select the device from the popup. 229 * 0: Default. Select the FA to start from the local and remote devices. 230 * 1: start FA from the local device. 231 * @devices tv, phone, tablet, wearable 232 */ 233 deviceType?: number; 234 /** 235 * Data sent to the ability which need to be serializable. 236 * @devices tv, phone, tablet, wearable 237 */ 238 data?: object; 239 /** 240 * Configuration switch when start FA. 241 * @devices tv, phone, tablet, wearable 242 */ 243 flag?: number; 244 /** 245 * Specify the url of the page which the FA to be called. Use home page directly by default. 246 * @devices tv, phone, tablet, wearable 247 */ 248 url?: string; 249} 250 251/** 252 * @devices tv, phone, tablet, wearable 253 */ 254export interface FinishWithResultParams { 255 /** 256 * Result code. 257 * @devices tv, phone, tablet, wearable 258 */ 259 code: number; 260 261 /** 262 * Returned data. 263 * @devices tv, phone, tablet, wearable 264 */ 265 result: object; 266} 267 268/** 269 * @devices tv, phone, tablet, wearable, liteWearable 270 */ 271export declare class FeatureAbility { 272 /** 273 * Start a FA without callback result. 274 * @param request Indicates the request param. 275 * @returns A Promise object is returned, which contains the result of whether to call Ability's interface successfully. 276 * @devices tv, phone, tablet, wearable 277 */ 278 static startAbility(request: RequestParams): Promise<Result>; 279 280 /** 281 * Start a FA with callback result. 282 * @param request Indicates the request param. 283 * @returns A Promise object is returned, which contains the result of the data FA returned. 284 * @devices tv, phone, tablet, wearable 285 */ 286 static startAbilityForResult(request: RequestParams): Promise<Result>; 287 288 /** 289 * FA call the interface to destory itself and set the result as parameters. 290 * @param request Indicates the request param. 291 * @returns A Promise object is returned, which contains the result whether to callback successfully. 292 * @devices tv, phone, tablet, wearable 293 */ 294 static finishWithResult(param: FinishWithResultParams): Promise<Result>; 295 296 /** 297 * Calls an AA. 298 * @param param Indicates the request param. 299 * @returns A Promise object is returned, which contains the result data returned by the AA. The result is a JSON string. 300 * @devices tv, phone, tablet, wearable 301 */ 302 static callAbility(param: CallAbilityParam): Promise<Result>; 303 304 /** 305 * Start FA migration. 306 * @returns A Promise object is returned, which contains the result data returned by the AA. The result is a JSON string. 307 * @devices tv, phone, tablet, wearable 308 */ 309 static continueAbility(): Promise<Result>; 310 311 /** 312 * Subscribes to events of an AA. 313 * @param param Indicates the request param. 314 * @param func Indicates the event reporting callback. 315 * @returns A Promise object is returned, which contains the result data returned by the AA. The result is a JSON string. 316 * @devices tv, phone, tablet, wearable 317 */ 318 static subscribeAbilityEvent( 319 param: SubscribeAbilityEventParam, 320 func: Function 321 ): Promise<Result>; 322 323 /** 324 * Unsubscribes from events of an AA. 325 * @param param Indicates the request param. 326 * @returns A Promise object is returned, which contains the result data returned by the AA. The result is a JSON string. 327 * @devices tv, phone, tablet, wearable 328 */ 329 static unsubscribeAbilityEvent( 330 param: SubscribeAbilityEventParam 331 ): Promise<Result>; 332 333 /** 334 * Sends messages to the destination device. 335 * @param options Options. 336 * @devices liteWearable 337 */ 338 static sendMsg(options: SendMessageOptions): void; 339 340 /** 341 * Listens for messages sent from other devices. 342 * @param options Options. 343 * @devices liteWearable 344 */ 345 static subscribeMsg(options: SubscribeMessageOptions): void; 346 347 /** 348 * Cancels the listening for messages sent from other devices. 349 * @devices liteWearable 350 */ 351 static unsubscribeMsg(): void; 352} 353