1/* 2 * Copyright (c) 2024-2025 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 * @file 18 * @kit DistributedServiceKit 19 */ 20 21import { Callback } from './@ohos.base'; 22import image from './@ohos.multimedia.image'; 23import Context from './application/Context'; 24import colorSpaceManager from './@ohos.graphics.colorSpaceManager'; 25 26/** 27 * Providers interfaces to create a {@link abilityConnectionManager} instances. 28 * 29 * @namespace abilityConnectionManager 30 * @syscap SystemCapability.DistributedSched.AppCollaboration 31 * @since 18 32 */ 33declare namespace abilityConnectionManager { 34 35 /** 36 * Collaborative application information. 37 * @interface PeerInfo 38 * @syscap SystemCapability.DistributedSched.AppCollaboration 39 * @since 18 40 */ 41 interface PeerInfo { 42 /** 43 * Device identifier. The actual value is udid-hash confused with appid and salt value based on sha256. 44 * This id remains unchanged after application installation. If the application is uninstalled and reinstalled, 45 * the obtained ID will change. 46 * @type { string } 47 * @syscap SystemCapability.DistributedSched.AppCollaboration 48 * @since 18 49 */ 50 deviceId: string; 51 52 /** 53 * bundle name. 54 * @type { string } 55 * @syscap SystemCapability.DistributedSched.AppCollaboration 56 * @since 18 57 */ 58 bundleName: string; 59 60 /** 61 * module name. 62 * @type { string } 63 * @syscap SystemCapability.DistributedSched.AppCollaboration 64 * @since 18 65 */ 66 moduleName: string; 67 68 /** 69 * ability name. 70 * @type { string } 71 * @syscap SystemCapability.DistributedSched.AppCollaboration 72 * @since 18 73 */ 74 abilityName: string; 75 76 /** 77 * Service name. 78 * @type { ?string } 79 * @syscap SystemCapability.DistributedSched.AppCollaboration 80 * @since 18 81 */ 82 serviceName?: string; 83 } 84 85 /** 86 * Connection options for ability connection sessions. 87 * @interface ConnectOptions 88 * @syscap SystemCapability.DistributedSched.AppCollaboration 89 * @since 18 90 */ 91 interface ConnectOptions { 92 /** 93 * Send Data Configuration Options. WiFi needs to be turned on. 94 * @type { ?boolean } 95 * @syscap SystemCapability.DistributedSched.AppCollaboration 96 * @since 18 97 */ 98 needSendData?: boolean; 99 100 /** 101 * Send Stream Data Configuration Options. WiFi needs to be turned on. 102 * @type { ?boolean } 103 * @syscap SystemCapability.DistributedSched.AppCollaboration 104 * @systemapi 105 * @since 18 106 */ 107 needSendStream?: boolean; 108 109 /** 110 * Receive Stream Data Configuration Options. WiFi needs to be turned on. 111 * @type { ?boolean } 112 * @syscap SystemCapability.DistributedSched.AppCollaboration 113 * @systemapi 114 * @since 18 115 */ 116 needReceiveStream?: boolean; 117 118 /** 119 * Startup option. 120 * @type { ?StartOptionParams } 121 * @syscap SystemCapability.DistributedSched.AppCollaboration 122 * @since 18 123 */ 124 startOptions?: StartOptionParams; 125 126 /** 127 * Additional information about the ability connection request. 128 * @type { ?Record<string, string> } 129 * @syscap SystemCapability.DistributedSched.AppCollaboration 130 * @since 18 131 */ 132 parameters?: Record<string, string>; 133 } 134 135 /** 136 * Connection result. 137 * @interface ConnectResult 138 * @syscap SystemCapability.DistributedSched.AppCollaboration 139 * @since 18 140 */ 141 interface ConnectResult { 142 /** 143 * Connection is accepted or rejected. 144 * @type { boolean } 145 * @syscap SystemCapability.DistributedSched.AppCollaboration 146 * @since 18 147 */ 148 isConnected: boolean; 149 150 /** 151 * Connection failure error code. 152 * @type { ?ConnectErrorCode } 153 * @syscap SystemCapability.DistributedSched.AppCollaboration 154 * @since 18 155 */ 156 errorCode?: ConnectErrorCode; 157 158 /** 159 * Indicates the reason for reject. 160 * @type { ?string } 161 * @syscap SystemCapability.DistributedSched.AppCollaboration 162 * @since 18 163 */ 164 reason?: string; 165 } 166 167 /** 168 * Connection failure error code. 169 * @enum { number } 170 * @syscap SystemCapability.DistributedSched.AppCollaboration 171 * @since 18 172 */ 173 export enum ConnectErrorCode { 174 /** 175 * A connected session exists between the two application. 176 * @syscap SystemCapability.DistributedSched.AppCollaboration 177 * @since 18 178 */ 179 CONNECTED_SESSION_EXISTS = 0, 180 181 /** 182 * The peer application rejects the collaboration request. 183 * @syscap SystemCapability.DistributedSched.AppCollaboration 184 * @since 18 185 */ 186 PEER_APP_REJECTED = 1, 187 188 /** 189 * Connection failed due to the device's WiFi being off. 190 * @syscap SystemCapability.DistributedSched.AppCollaboration 191 * @since 18 192 */ 193 LOCAL_WIFI_NOT_OPEN = 2, 194 195 /** 196 * Connection failed due to the peer's WiFi being off. 197 * @syscap SystemCapability.DistributedSched.AppCollaboration 198 * @since 18 199 */ 200 PEER_WIFI_NOT_OPEN = 3, 201 202 /** 203 * Connection failed due to the peer ability has not implemented the onCollaborate method. 204 * @syscap SystemCapability.DistributedSched.AppCollaboration 205 * @since 18 206 */ 207 PEER_ABILITY_NO_ONCOLLABORATE = 4, 208 209 /** 210 * The connection failed due to an internal system error. 211 * @syscap SystemCapability.DistributedSched.AppCollaboration 212 * @since 18 213 */ 214 SYSTEM_INTERNAL_ERROR = 5, 215 } 216 217 /** 218 * The constant for params of the start option. 219 * 220 * @enum { number } 221 * @syscap SystemCapability.DistributedSched.AppCollaboration 222 * @since 18 223 */ 224 export enum StartOptionParams { 225 /** 226 * Launching the peer application to the foreground. 227 * @syscap SystemCapability.DistributedSched.AppCollaboration 228 * @since 18 229 */ 230 START_IN_FOREGROUND = 0, 231 232 /** 233 * Launching the peer application to the background. 234 * @syscap SystemCapability.DistributedSched.AppCollaboration 235 * @systemapi 236 * @since 18 237 */ 238 START_IN_BACKGROUND = 1, 239 } 240 241 /** 242 * Connection event callback information. 243 * @interface EventCallbackInfo 244 * @syscap SystemCapability.DistributedSched.AppCollaboration 245 * @since 18 246 */ 247 interface EventCallbackInfo { 248 /** 249 * Ability connection Session id. 250 * @type { number } 251 * @syscap SystemCapability.DistributedSched.AppCollaboration 252 * @since 18 253 */ 254 sessionId: number; 255 256 /** 257 * Indicates the reason of ability disconnection. 258 * @type { ?DisconnectReason } 259 * @syscap SystemCapability.DistributedSched.AppCollaboration 260 * @since 18 261 */ 262 reason?: DisconnectReason; 263 264 /** 265 * Received message data. 266 * @type { ?string } 267 * @syscap SystemCapability.DistributedSched.AppCollaboration 268 * @since 18 269 */ 270 msg?: string; 271 272 /** 273 * Received data. 274 * @type { ?ArrayBuffer } 275 * @syscap SystemCapability.DistributedSched.AppCollaboration 276 * @since 18 277 */ 278 data?: ArrayBuffer; 279 280 /** 281 * Received image. 282 * @type { ?image.PixelMap } 283 * @syscap SystemCapability.DistributedSched.AppCollaboration 284 * @systemapi 285 * @since 18 286 */ 287 image?: image.PixelMap; 288 } 289 290 /** 291 * Collaborate event information. 292 * @interface CollaborateEventInfo 293 * @syscap SystemCapability.DistributedSched.AppCollaboration 294 * @since 18 295 */ 296 interface CollaborateEventInfo { 297 /** 298 * Indicates the type of collaborate event. 299 * @type { CollaborateEventType } 300 * @syscap SystemCapability.DistributedSched.AppCollaboration 301 * @since 18 302 */ 303 eventType: CollaborateEventType; 304 305 /** 306 * Indicates the collaborate message of collaborate event. 307 * @type { ?string } 308 * @syscap SystemCapability.DistributedSched.AppCollaboration 309 * @since 18 310 */ 311 eventMsg?: string; 312 } 313 314 /** 315 * CollaborateEventType. 316 * @enum { number } 317 * @syscap SystemCapability.DistributedSched.AppCollaboration 318 * @since 18 319 */ 320 enum CollaborateEventType { 321 /** 322 * Indicates send task failure. 323 * @syscap SystemCapability.DistributedSched.AppCollaboration 324 * @since 18 325 */ 326 SEND_FAILURE = 0, 327 328 /** 329 * Indicates color space conversion failure. 330 * @syscap SystemCapability.DistributedSched.AppCollaboration 331 * @since 18 332 */ 333 COLOR_SPACE_CONVERSION_FAILURE = 1, 334 } 335 336 /** 337 * DisconnectReason. 338 * @enum { number } 339 * @syscap SystemCapability.DistributedSched.AppCollaboration 340 * @since 18 341 */ 342 enum DisconnectReason { 343 /** 344 * Indicates that the reason is the peer application actively closes the collaboration. 345 * @syscap SystemCapability.DistributedSched.AppCollaboration 346 * @since 18 347 */ 348 PEER_APP_CLOSE_COLLABORATION = 0, 349 350 /** 351 * Indicates that the reason is the peer application exit. 352 * @syscap SystemCapability.DistributedSched.AppCollaboration 353 * @since 18 354 */ 355 PEER_APP_EXIT = 1, 356 357 /** 358 * Indicates that the reason is a network disconnection. 359 * @syscap SystemCapability.DistributedSched.AppCollaboration 360 * @since 18 361 */ 362 NETWORK_DISCONNECTED = 2, 363 } 364 365 /** 366 * Registers connect event. 367 * 368 * @param { 'connect' } type - Registration Type, 'connect'. 369 * @param { number } sessionId - Ability connection Session id. 370 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('connect') command. 371 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 372 * @syscap SystemCapability.DistributedSched.AppCollaboration 373 * @since 18 374 */ 375 function on(type: 'connect', sessionId: number, 376 callback: Callback<EventCallbackInfo>): void; 377 378 /** 379 * Unregisters connect event. 380 * 381 * @param { 'connect' } type - Registration Type, 'connect'. 382 * @param { number } sessionId - Ability connection Session id. 383 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('connect') command. 384 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 385 * @syscap SystemCapability.DistributedSched.AppCollaboration 386 * @since 18 387 */ 388 function off(type: 'connect', sessionId: number, 389 callback?: Callback<EventCallbackInfo>): void; 390 391 /** 392 * Registers disconnect event. 393 * 394 * @param { 'disconnect' } type - Registration Type, 'disconnect'. 395 * @param { number } sessionId - Ability connection Session id. 396 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('disconnect') command. 397 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 398 * @syscap SystemCapability.DistributedSched.AppCollaboration 399 * @since 18 400 */ 401 function on(type: 'disconnect', sessionId: number, 402 callback: Callback<EventCallbackInfo>): void; 403 404 /** 405 * Unregisters disconnect event. 406 * 407 * @param { 'disconnect' } type - Registration Type, 'connect'. 408 * @param { number } sessionId - Ability connection Session id. 409 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('disconnect') command. 410 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 411 * @syscap SystemCapability.DistributedSched.AppCollaboration 412 * @since 18 413 */ 414 function off(type: 'disconnect', sessionId: number, 415 callback?: Callback<EventCallbackInfo>): void; 416 417 /** 418 * Registers receiveMessage event. 419 * 420 * @param { 'receiveMessage' } type - Registration Type, 'receiveMessage'. 421 * @param { number } sessionId - Ability connection Session id. 422 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('receiveMessage') command. 423 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 424 * @syscap SystemCapability.DistributedSched.AppCollaboration 425 * @since 18 426 */ 427 function on(type: 'receiveMessage', sessionId: number, 428 callback: Callback<EventCallbackInfo>): void; 429 430 /** 431 * Unregisters receiveMessage event. 432 * 433 * @param { 'receiveMessage' } type - Registration Type, 'receiveMessage'. 434 * @param { number } sessionId - Ability connection Session id. 435 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('receiveMessage') command. 436 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 437 * @syscap SystemCapability.DistributedSched.AppCollaboration 438 * @since 18 439 */ 440 function off(type: 'receiveMessage', sessionId: number, 441 callback?: Callback<EventCallbackInfo>): void; 442 443 /** 444 * Registers receiveData event. 445 * 446 * @param { 'receiveData' } type - Registration Type, 'receiveData'. 447 * @param { number } sessionId - Ability connection Session id. 448 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('receiveData') command. 449 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 450 * @syscap SystemCapability.DistributedSched.AppCollaboration 451 * @since 18 452 */ 453 function on(type: 'receiveData', sessionId: number, 454 callback: Callback<EventCallbackInfo>): void; 455 456 /** 457 * Unregisters receiveData event. 458 * 459 * @param { 'receiveData' } type - Registration Type, 'receiveData'. 460 * @param { number } sessionId - Ability connection Session id. 461 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('receiveData') command. 462 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 463 * @syscap SystemCapability.DistributedSched.AppCollaboration 464 * @since 18 465 */ 466 function off(type: 'receiveData', sessionId: number, 467 callback?: Callback<EventCallbackInfo>): void; 468 469 /** 470 * Registers receiveImage event. 471 * 472 * @param { 'receiveImage' } type - Registration Type, 'receiveImage'. 473 * @param { number } sessionId - Ability connection Session id. 474 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('receiveImage') command. 475 * @throws { BusinessError } 202 - Not system App. 476 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 477 * @syscap SystemCapability.DistributedSched.AppCollaboration 478 * @systemapi 479 * @since 18 480 */ 481 function on(type: 'receiveImage', sessionId: number, 482 callback: Callback<EventCallbackInfo>): void; 483 484 /** 485 * Unregisters receiveImage event. 486 * 487 * @param { 'receiveImage' } type - Registration Type, 'receiveImage'. 488 * @param { number } sessionId - Ability connection Session id. 489 * @param { Callback<EventCallbackInfo> } callback - Used to handle ('receiveImage') command. 490 * @throws { BusinessError } 202 - Not system App. 491 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 492 * @syscap SystemCapability.DistributedSched.AppCollaboration 493 * @systemapi 494 * @since 18 495 */ 496 function off(type: 'receiveImage', sessionId: number, 497 callback?: Callback<EventCallbackInfo>): void; 498 499 /** 500 * Registers collaborateEvent event. 501 * 502 * @param { 'collaborateEvent' } type - Registration Type, 'collaborateEvent'. 503 * @param { number } sessionId - Ability connection Session id. 504 * @param { Callback<CollaborateEventInfo> } callback - Called when an error event comes. 505 * @throws { BusinessError } 202 - Not system App. 506 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 507 * @syscap SystemCapability.DistributedSched.AppCollaboration 508 * @systemapi 509 * @since 18 510 */ 511 function on(type: 'collaborateEvent', sessionId: number, 512 callback: Callback<CollaborateEventInfo>): void; 513 514 /** 515 * Unregisters collaborateEvent event. 516 * 517 * @param { 'collaborateEvent' } type - Registration Type, 'collaborateEvent'. 518 * @param { number } sessionId - Ability connection Session id. 519 * @param { Callback<CollaborateEventInfo> } callback - Called when an error event comes. 520 * @throws { BusinessError } 202 - Not system App. 521 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 522 * @syscap SystemCapability.DistributedSched.AppCollaboration 523 * @systemapi 524 * @since 18 525 */ 526 function off(type: 'collaborateEvent', sessionId: number, 527 callback?: Callback<CollaborateEventInfo>): void; 528 529 /** 530 * Create the Ability connection Session. 531 * 532 * @permission ohos.permission.INTERNET and ohos.permission.GET_NETWORK_INFO and ohos.permission.SET_NETWORK_INFO and ohos.permission.DISTRIBUTED_DATASYNC 533 * @param { string } serviceName - Service name, which must be consistent at both ends. 534 * @param { Context } context - The context of an ability. 535 * @param { PeerInfo } peerInfo - Collaborative application information at the sink end. 536 * @param { ConnectOptions } connectOptions - Connection options for Ability connection sessions. 537 * @returns { number} Returns the Ability connection Session id. 538 * @throws { BusinessError } 201 - Permission denied. 539 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 540 * @syscap SystemCapability.DistributedSched.AppCollaboration 541 * @since 18 542 */ 543 function createAbilityConnectionSession(serviceName: string, context: Context, peerInfo: PeerInfo, 544 connectOptions: ConnectOptions): number; 545 546 /** 547 * Destroy the ability connection session 548 * 549 * @param { number } sessionId - Ability connection Session id. 550 * @syscap SystemCapability.DistributedSched.AppCollaboration 551 * @since 18 552 */ 553 function destroyAbilityConnectionSession(sessionId: number): void; 554 555 /** 556 * Get the application information in the ability connection session 557 * 558 * @param { number } sessionId - Ability connection Session id. 559 * @returns { PeerInfo | undefined } Returns the collaborative application information at the sink end. 560 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 561 * @syscap SystemCapability.DistributedSched.AppCollaboration 562 * @since 18 563 */ 564 function getPeerInfoById(sessionId: number): PeerInfo | undefined; 565 566 /** 567 * Initiate an ability session connection. 568 * 569 * @param { number } sessionId - Ability connection Session id. 570 * @returns { Promise<ConnectResult> } The promise returned by the function. 571 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 572 * @syscap SystemCapability.DistributedSched.AppCollaboration 573 * @since 18 574 */ 575 function connect(sessionId: number): Promise<ConnectResult>; 576 577 /** 578 * Disconnect a Ability connection Session. 579 * 580 * @param { number } sessionId - Ability connection Session id. 581 * @syscap SystemCapability.DistributedSched.AppCollaboration 582 * @since 18 583 */ 584 function disconnect(sessionId: number): void; 585 586 /** 587 * Accept connection request and prepare the connection environment. 588 * 589 * @param { number } sessionId - Ability connection Session id. 590 * @param { string } token - Token for collaborative service management 591 * @returns { Promise<void> } The promise returned by the function. 592 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 593 * @syscap SystemCapability.DistributedSched.AppCollaboration 594 * @since 18 595 */ 596 function acceptConnect(sessionId: number, token: string): Promise<void>; 597 598 /** 599 * Notify the peer end of the reason why the connection is rejected. 600 * 601 * @param { string } token - Token for collaborative service management. 602 * @param { string } reason - Reason for connection rejection. 603 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 604 * @syscap SystemCapability.DistributedSched.AppCollaboration 605 * @since 18 606 */ 607 function reject(token: string, reason: string): void; 608 609 /** 610 * Send message data. 611 * 612 * @param { number } sessionId - Ability connection Session id. 613 * @param { string } msg - Message data to be sent. 614 * @returns { Promise<void> } The promise returned by the function. 615 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 616 * @syscap SystemCapability.DistributedSched.AppCollaboration 617 * @since 18 618 */ 619 function sendMessage(sessionId: number, msg: string): Promise<void>; 620 621 /** 622 * Send data. 623 * 624 * @param { number } sessionId - Ability connection Session id. 625 * @param { ArrayBuffer } data - Data to be sent. 626 * @returns { Promise<void> } The promise returned by the function. 627 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 628 * @syscap SystemCapability.DistributedSched.AppCollaboration 629 * @since 18 630 */ 631 function sendData(sessionId: number, data: ArrayBuffer): Promise<void>; 632 633 /** 634 * Send image data. 635 * 636 * @param { number } sessionId - Ability connection Session id. 637 * @param { image.PixelMap } image - image data to be sent. 638 * @param { number } [quality] - image compression quality, range 0~100, default 30. 639 * @returns { Promise<void> } The promise returned by the function. 640 * @throws { BusinessError } 202 - Not system App. 641 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 642 * @syscap SystemCapability.DistributedSched.AppCollaboration 643 * @systemapi 644 * @since 18 645 */ 646 function sendImage(sessionId: number, image: image.PixelMap, quality?: number): Promise<void>; 647 648 /** 649 * Creating a Stream. 650 * 651 * @param { number } sessionId - Ability connection Session id. 652 * @param { StreamParam } param - Transport Stream Parameters 653 * @returns {Promise<number>} The promise returned by the function, contain the ID of a transport stream. 654 * @throws { BusinessError } 202 - Not system App. 655 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 656 * @throws { BusinessError } 32300001 - Only one stream can be created for the current session. 657 * @throws { BusinessError } 32300003 - Bitrate not supported. 658 * @throws { BusinessError } 32300004 - Color space not supported. 659 * @syscap SystemCapability.DistributedSched.AppCollaboration 660 * @systemapi 661 * @since 18 662 */ 663 function createStream(sessionId: number, param: StreamParam): Promise<number>; 664 665 /** 666 * Sets the transmission surface. 667 * 668 * @param { number } streamId - Indicates the ID of a transport stream. 669 * @param { string } surfaceId - Surface ID. 670 * @param { SurfaceParam } param - Surface Parameters 671 * @throws { BusinessError } 202 - Not system App. 672 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 673 * @syscap SystemCapability.DistributedSched.AppCollaboration 674 * @systemapi 675 * @since 18 676 */ 677 function setSurfaceId(streamId: number, surfaceId: string, param: SurfaceParam): void; 678 /** 679 * Obtains the transmission surface. 680 * 681 * @param { number } streamId - Indicates the ID of a transport stream. 682 * @param { SurfaceParam } param - Surface Parameters 683 * @returns {string} Returns the ID of a surface. 684 * @throws { BusinessError } 202 - Not system App. 685 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 686 * @syscap SystemCapability.DistributedSched.AppCollaboration 687 * @systemapi 688 * @since 18 689 */ 690 function getSurfaceId(streamId: number, param: SurfaceParam): string; 691 692 /** 693 * Update surface parameters. 694 * 695 * @param { number } streamId - Stream ID. 696 * @param { SurfaceParam } param - Surface Parameters 697 * @throws { BusinessError } 202 - Not system App. 698 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 699 * @syscap SystemCapability.DistributedSched.AppCollaboration 700 * @systemapi 701 * @since 18 702 */ 703 function updateSurfaceParam(streamId: number, param: SurfaceParam): void; 704 705 /** 706 * Destroy the Stream. 707 * 708 * @param { number } streamId - Indicates the ID of a transport stream. 709 * @throws { BusinessError } 202 - Not system App. 710 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 711 * @syscap SystemCapability.DistributedSched.AppCollaboration 712 * @systemapi 713 * @since 18 714 */ 715 function destroyStream(streamId: number): void; 716 717 /** 718 * Start Streaming 719 * 720 * @param { number } streamId - Indicates the ID of a transport stream. 721 * @throws { BusinessError } 202 - Not system App. 722 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 723 * @throws { BusinessError } 32300002 - The stream at the receive end is not started. 724 * @syscap SystemCapability.DistributedSched.AppCollaboration 725 * @systemapi 726 * @since 18 727 */ 728 function startStream(streamId: number): void; 729 730 /** 731 * Stop Streaming 732 * 733 * @param { number } streamId - Indicates the ID of a transport stream. 734 * @throws { BusinessError } 202 - Not system App. 735 * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 736 * @syscap SystemCapability.DistributedSched.AppCollaboration 737 * @systemapi 738 * @since 18 739 */ 740 function stopStream(streamId: number): void; 741 742 /** 743 * Streaming configuration parameters. 744 * @interface StreamParam 745 * @syscap SystemCapability.DistributedSched.AppCollaboration 746 * @systemapi 747 * @since 18 748 */ 749 interface StreamParam { 750 /** 751 * Stream name, the receive end must be consistent with the transmit end. 752 * @type { string } 753 * @syscap SystemCapability.DistributedSched.AppCollaboration 754 * @systemapi 755 * @since 18 756 */ 757 name: string; 758 759 /** 760 * Stream transmission role, which can be a receive stream or a transmit stream. 761 * @type { StreamRole } 762 * @syscap SystemCapability.DistributedSched.AppCollaboration 763 * @systemapi 764 * @since 18 765 */ 766 role: StreamRole; 767 768 /** 769 * This value indicates video bitrate, default 80(kbps). Only valid on the sender side. 770 * @type { ?number } 771 * @syscap SystemCapability.DistributedSched.AppCollaboration 772 * @systemapi 773 * @since 18 774 */ 775 bitrate?: number; 776 777 /** 778 * The target color space for conversion. Currently, only BT709_LIMIT is supported. 779 * If the video format on the sender side is HDR and needs to be converted to SDR during transmission, this parameter should be set. 780 * @type { ?colorSpaceManager.ColorSpace } 781 * @syscap SystemCapability.DistributedSched.AppCollaboration 782 * @systemapi 783 * @since 18 784 */ 785 colorSpaceConversionTarget?: colorSpaceManager.ColorSpace; 786 } 787 788 /** 789 * Surface configuration parameters. 790 * @interface SurfaceParam 791 * @syscap SystemCapability.DistributedSched.AppCollaboration 792 * @systemapi 793 * @since 18 794 */ 795 interface SurfaceParam { 796 /** 797 * Encoding width. Must be set before stream starts and cannot update once set. 798 * @type { number } 799 * @syscap SystemCapability.DistributedSched.AppCollaboration 800 * @systemapi 801 * @since 18 802 */ 803 width: number; 804 805 /** 806 * Encoding length. Must be set before stream starts and cannot update once set. 807 * @type { number } 808 * @syscap SystemCapability.DistributedSched.AppCollaboration 809 * @systemapi 810 * @since 18 811 */ 812 height: number; 813 814 /** 815 * Video PixelFormat, this option must be configured on the sender. 816 * Must be set before stream starts and cannot update once set. 817 * @type { ?VideoPixelFormat } 818 * @syscap SystemCapability.DistributedSched.AppCollaboration 819 * @systemapi 820 * @since 18 821 */ 822 format?: VideoPixelFormat; 823 824 /** 825 * This value identifies the rotation angle of the video. 826 * the range of rotation angle should be {0, 90, 180, 270}, default is 0 827 * @type { ?number } 828 * @syscap SystemCapability.DistributedSched.AppCollaboration 829 * @systemapi 830 * @since 18 831 */ 832 rotation?: number; 833 834 /** 835 * This value indicates whether the video is reversed. 836 * @type { ?FlipOptions } 837 * @syscap SystemCapability.DistributedSched.AppCollaboration 838 * @systemapi 839 * @since 18 840 */ 841 flip?: FlipOptions; 842 } 843 844 /** 845 * Flip option. 846 * @enum { number } 847 * @syscap SystemCapability.DistributedSched.AppCollaboration 848 * @systemapi 849 * @since 18 850 */ 851 export enum FlipOptions { 852 /** 853 * Horizontal Flip 854 * @syscap SystemCapability.DistributedSched.AppCollaboration 855 * @systemapi 856 * @since 18 857 */ 858 HORIZONTAL = 0, 859 860 /** 861 * Vertical Flip 862 * @syscap SystemCapability.DistributedSched.AppCollaboration 863 * @systemapi 864 * @since 18 865 */ 866 VERTICAL = 1, 867 } 868 869 /** 870 * Stream transmission role. 871 * @enum { number } 872 * @syscap SystemCapability.DistributedSched.AppCollaboration 873 * @systemapi 874 * @since 18 875 */ 876 export enum StreamRole { 877 /** 878 * This status indicates the stream is a send stream. 879 * @syscap SystemCapability.DistributedSched.AppCollaboration 880 * @systemapi 881 * @since 18 882 */ 883 SOURCE = 0, 884 885 /** 886 * This status indicates the stream is a receive stream. 887 * @syscap SystemCapability.DistributedSched.AppCollaboration 888 * @systemapi 889 * @since 18 890 */ 891 SINK = 1, 892 } 893 894 /** 895 * Video pixelFormat Configuration Options. 896 * @enum { number } 897 * @syscap SystemCapability.DistributedSched.AppCollaboration 898 * @systemapi 899 * @since 18 900 */ 901 export enum VideoPixelFormat { 902 /** 903 * Unknown. 904 * @syscap SystemCapability.DistributedSched.AppCollaboration 905 * @systemapi 906 * @since 18 907 */ 908 UNKNOWN = -1, 909 910 /** 911 * NV12. yuv 420 semiplanar. 912 * @syscap SystemCapability.DistributedSched.AppCollaboration 913 * @systemapi 914 * @since 18 915 */ 916 NV12 = 0, 917 918 /** 919 * NV21. yvu 420 semiplanar. 920 * @syscap SystemCapability.DistributedSched.AppCollaboration 921 * @systemapi 922 * @since 18 923 */ 924 NV21 = 1, 925 } 926 927 /** 928 * The keys for ability onCollaborate parameters. 929 * @enum { string } 930 * @syscap SystemCapability.DistributedSched.AppCollaboration 931 * @since 18 932 */ 933 export enum CollaborationKeys { 934 /** 935 * The key of peerinfo 936 * @syscap SystemCapability.DistributedSched.AppCollaboration 937 * @since 18 938 */ 939 PEER_INFO = 'ohos.collaboration.key.peerInfo', 940 941 /** 942 * The key of connect options 943 * @syscap SystemCapability.DistributedSched.AppCollaboration 944 * @since 18 945 */ 946 CONNECT_OPTIONS = 'ohos.collaboration.key.connectOptions', 947 948 /** 949 * The key of collaboration type 950 * @syscap SystemCapability.DistributedSched.AppCollaboration 951 * @since 18 952 */ 953 COLLABORATE_TYPE = 'ohos.collaboration.key.abilityCollaborateType', 954 } 955 956 /** 957 * Ability collaboration values. 958 * @enum { string } 959 * @syscap SystemCapability.DistributedSched.AppCollaboration 960 * @since 18 961 */ 962 export enum CollaborationValues { 963 /** 964 * Default collaboration type 965 * @syscap SystemCapability.DistributedSched.AppCollaboration 966 * @since 18 967 */ 968 ABILITY_COLLABORATION_TYPE_DEFAULT = 'ohos.collaboration.value.abilityCollab', 969 970 /** 971 * Collaboration type of connect proxy 972 * @syscap SystemCapability.DistributedSched.AppCollaboration 973 * @since 18 974 */ 975 ABILITY_COLLABORATION_TYPE_CONNECT_PROXY = 'ohos.collaboration.value.connectProxy', 976 } 977} 978export default abilityConnectionManager;