1/* 2 * Copyright (c) 2022-2024 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 NetworkKit 19 */ 20 21import type { AsyncCallback, ErrorCallback, Callback } from './@ohos.base'; 22import type connection from './@ohos.net.connection'; 23 24/** 25 * Provides WebSocket APIs. 26 * @namespace webSocket 27 * @syscap SystemCapability.Communication.NetStack 28 * @since 6 29 */ 30/** 31 * Provides WebSocket APIs. 32 * @namespace webSocket 33 * @syscap SystemCapability.Communication.NetStack 34 * @crossplatform 35 * @since 10 36 */ 37/** 38 * Provides WebSocket APIs. 39 * @namespace webSocket 40 * @syscap SystemCapability.Communication.NetStack 41 * @crossplatform 42 * @atomicservice 43 * @since 11 44 */ 45declare namespace webSocket { 46 /** 47 * @typedef { connection.HttpProxy } 48 * @syscap SystemCapability.Communication.NetManager.Core 49 * @since 12 50 */ 51 type HttpProxy = connection.HttpProxy; 52 53 /** 54 * Creates a web socket connection. 55 * @returns { WebSocket } the WebSocket of the createWebSocket. 56 * @syscap SystemCapability.Communication.NetStack 57 * @since 6 58 */ 59 /** 60 * Creates a web socket connection. 61 * @returns { WebSocket } the WebSocket of the createWebSocket. 62 * @syscap SystemCapability.Communication.NetStack 63 * @crossplatform 64 * @since 10 65 */ 66 /** 67 * Creates a web socket connection. 68 * @returns { WebSocket } the WebSocket of the createWebSocket. 69 * @syscap SystemCapability.Communication.NetStack 70 * @crossplatform 71 * @atomicservice 72 * @since 11 73 */ 74 function createWebSocket(): WebSocket; 75 76 /** 77 * Defines the optional parameters carried in the request for establishing a WebSocket connection. 78 * @interface WebSocketRequestOptions 79 * @syscap SystemCapability.Communication.NetStack 80 * @since 6 81 */ 82 /** 83 * Defines the optional parameters carried in the request for establishing a WebSocket connection. 84 * @interface WebSocketRequestOptions 85 * @syscap SystemCapability.Communication.NetStack 86 * @crossplatform 87 * @since 10 88 */ 89 /** 90 * Defines the optional parameters carried in the request for establishing a WebSocket connection. 91 * @interface WebSocketRequestOptions 92 * @syscap SystemCapability.Communication.NetStack 93 * @crossplatform 94 * @atomicservice 95 * @since 11 96 */ 97 export interface WebSocketRequestOptions { 98 /** 99 * HTTP request header. 100 * @type {?Object} 101 * @syscap SystemCapability.Communication.NetStack 102 * @since 6 103 */ 104 /** 105 * HTTP request header. 106 * @type {?Object} 107 * @syscap SystemCapability.Communication.NetStack 108 * @crossplatform 109 * @since 10 110 */ 111 /** 112 * HTTP request header. 113 * @type {?Object} 114 * @syscap SystemCapability.Communication.NetStack 115 * @crossplatform 116 * @atomicservice 117 * @since 11 118 */ 119 header?: Object; 120 121 /** 122 * File path for client cert. 123 * @type {?string} 124 * @syscap SystemCapability.Communication.NetStack 125 * @since 11 126 */ 127 /** 128 * File path for client cert. 129 * @type {?string} 130 * @syscap SystemCapability.Communication.NetStack 131 * @crossplatform 132 * @since 12 133 */ 134 caPath?: string; 135 136 /** 137 * Wheter or not to skip the verification of the server's certification. 138 * @type { ?boolean } 139 * @syscap SystemCapability.Communication.NetStack 140 * @since 20 141 */ 142 skipServerCertVerification?: boolean; 143 144 /** 145 * Client cert. 146 * @type {?ClientCert} 147 * @syscap SystemCapability.Communication.NetStack 148 * @since 11 149 */ 150 /** 151 * Client cert. 152 * @type {?ClientCert} 153 * @syscap SystemCapability.Communication.NetStack 154 * @crossplatform 155 * @since 12 156 */ 157 clientCert?: ClientCert; 158 159 /** 160 * HTTP proxy configuration. Use 'system' if this filed is not set. 161 * @type {?ProxyConfiguration} 162 * @syscap SystemCapability.Communication.NetStack 163 * @since 12 164 */ 165 proxy?: ProxyConfiguration; 166 167 /** 168 * Self defined protocol. 169 * @type {?string} 170 * @syscap SystemCapability.Communication.NetStack 171 * @since 12 172 */ 173 protocol?: string; 174 175 /** 176 * Self defined interval of ping frame. 177 * default: 30. disable: 0. max: 30000. unit: second. 178 * Ping is performed at every pingInterval. 179 * @type {?int} 180 * @syscap SystemCapability.Communication.NetStack 181 * @since 21 182 * @arkts 1.2 183 */ 184 pingInterval?: int; 185 186 /** 187 * Self defined timeout of pong frame. 188 * default: 30. max: 30000. unit: second. The value must be less than or equal to pingInterval. 189 * If no pong is received within the pongTimeout period, the websocket connection will be disconnected. 190 * @type {?int} 191 * @syscap SystemCapability.Communication.NetStack 192 * @since 21 193 * @arkts 1.2 194 */ 195 pongTimeout?: int; 196 } 197 198 /** 199 * HTTP proxy configuration. 200 * system: means that use system proxy configuration. 201 * no-proxy: means do not use proxy. 202 * object of @type {connection.HttpProxy} means providing custom proxy settings 203 * @typedef { 'system' | 'no-proxy' | HttpProxy } 204 * @syscap SystemCapability.Communication.NetStack 205 * @since 12 206 */ 207 export type ProxyConfiguration = 'system' | 'no-proxy' | HttpProxy; 208 209 /** 210 * The clientCert field of the client certificate, which includes three attributes: 211 * client certificate (certPath) and only support PEM format, certificate private key (keyPath), 212 * and passphrase (keyPassword). 213 * @interface ClientCert 214 * @syscap SystemCapability.Communication.NetStack 215 * @since 11 216 */ 217 /** 218 * The clientCert field of the client certificate, which includes three attributes: 219 * client certificate (certPath) and only support PEM format, certificate private key (keyPath), 220 * and passphrase (keyPassword). 221 * @interface ClientCert 222 * @syscap SystemCapability.Communication.NetStack 223 * @crossplatform 224 * @since 12 225 */ 226 export interface ClientCert { 227 /** 228 * The path to the client certificate file. 229 * @type {string} 230 * @syscap SystemCapability.Communication.NetStack 231 * @since 11 232 */ 233 /** 234 * The path to the client certificate file. 235 * @type {string} 236 * @syscap SystemCapability.Communication.NetStack 237 * @crossplatform 238 * @since 12 239 */ 240 certPath: string; 241 242 /** 243 * The path of the client certificate private key file. 244 * @type {string} 245 * @syscap SystemCapability.Communication.NetStack 246 * @since 11 247 */ 248 /** 249 * The path of the client certificate private key file. 250 * @type {string} 251 * @syscap SystemCapability.Communication.NetStack 252 * @crossplatform 253 * @since 12 254 */ 255 keyPath: string; 256 257 /** 258 * Client certificate password. 259 * @type {?string} 260 * @syscap SystemCapability.Communication.NetStack 261 * @since 11 262 */ 263 /** 264 * Client certificate password. 265 * @type {?string} 266 * @syscap SystemCapability.Communication.NetStack 267 * @crossplatform 268 * @since 12 269 */ 270 keyPassword?: string; 271 } 272 273 /** 274 * Defines the optional parameters carried in the request for closing a WebSocket connection. 275 * @interface WebSocketCloseOptions 276 * @syscap SystemCapability.Communication.NetStack 277 * @since 6 278 */ 279 /** 280 * Defines the optional parameters carried in the request for closing a WebSocket connection. 281 * @interface WebSocketCloseOptions 282 * @syscap SystemCapability.Communication.NetStack 283 * @crossplatform 284 * @since 10 285 */ 286 /** 287 * Defines the optional parameters carried in the request for closing a WebSocket connection. 288 * @interface WebSocketCloseOptions 289 * @syscap SystemCapability.Communication.NetStack 290 * @crossplatform 291 * @atomicservice 292 * @since 11 293 */ 294 export interface WebSocketCloseOptions { 295 /** 296 * Error code. 297 * @type {?number} 298 * @syscap SystemCapability.Communication.NetStack 299 * @since 6 300 */ 301 /** 302 * Error code. 303 * @type {?number} 304 * @syscap SystemCapability.Communication.NetStack 305 * @crossplatform 306 * @since 10 307 */ 308 /** 309 * Error code. 310 * @type {?number} 311 * @syscap SystemCapability.Communication.NetStack 312 * @crossplatform 313 * @atomicservice 314 * @since 11 315 */ 316 code?: number; 317 /** 318 * Error cause. 319 * @type {?string} 320 * @syscap SystemCapability.Communication.NetStack 321 * @since 6 322 */ 323 /** 324 * Error cause. 325 * @type {?string} 326 * @syscap SystemCapability.Communication.NetStack 327 * @crossplatform 328 * @since 10 329 */ 330 /** 331 * Error cause. 332 * @type {?string} 333 * @syscap SystemCapability.Communication.NetStack 334 * @crossplatform 335 * @atomicservice 336 * @since 11 337 */ 338 reason?: string; 339 } 340 341 /** 342 * The result for closing a WebSocket connection. 343 * @interface CloseResult 344 * @syscap SystemCapability.Communication.NetStack 345 * @crossplatform 346 * @since 10 347 */ 348 /** 349 * The result for closing a WebSocket connection. 350 * @interface CloseResult 351 * @syscap SystemCapability.Communication.NetStack 352 * @crossplatform 353 * @atomicservice 354 * @since 11 355 */ 356 export interface CloseResult { 357 /** 358 * Error code. 359 * @type {number} 360 * @syscap SystemCapability.Communication.NetStack 361 * @crossplatform 362 * @since 10 363 */ 364 /** 365 * Error code. 366 * @type {number} 367 * @syscap SystemCapability.Communication.NetStack 368 * @crossplatform 369 * @atomicservice 370 * @since 11 371 */ 372 code: number; 373 /** 374 * Error cause. 375 * @type {string} 376 * @syscap SystemCapability.Communication.NetStack 377 * @crossplatform 378 * @since 10 379 */ 380 /** 381 * Error cause. 382 * @type {string} 383 * @syscap SystemCapability.Communication.NetStack 384 * @crossplatform 385 * @atomicservice 386 * @since 11 387 */ 388 reason: string; 389 } 390 391 /** 392 * HTTP response headers. 393 * @typedef { object } 394 * @syscap SystemCapability.Communication.NetStack 395 * @since 12 396 */ 397 export type ResponseHeaders = { 398 [k: string]: string | string[] | undefined; 399 } 400 401 /** 402 * <p>Defines a WebSocket object. Before invoking WebSocket APIs, 403 * you need to call webSocket.createWebSocket to create a WebSocket object.</p> 404 * @interface WebSocket 405 * @syscap SystemCapability.Communication.NetStack 406 * @since 6 407 */ 408 /** 409 * <p>Defines a WebSocket object. Before invoking WebSocket APIs, 410 * you need to call webSocket.createWebSocket to create a WebSocket object.</p> 411 * @interface WebSocket 412 * @syscap SystemCapability.Communication.NetStack 413 * @crossplatform 414 * @since 10 415 */ 416 /** 417 * <p>Defines a WebSocket object. Before invoking WebSocket APIs, 418 * you need to call webSocket.createWebSocket to create a WebSocket object.</p> 419 * @interface WebSocket 420 * @syscap SystemCapability.Communication.NetStack 421 * @crossplatform 422 * @atomicservice 423 * @since 11 424 */ 425 export interface WebSocket { 426 /** 427 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 428 * @permission ohos.permission.INTERNET 429 * @param { string } url - URL for establishing a WebSocket connection. 430 * @param { AsyncCallback<boolean> } callback - the callback of connect. 431 * @throws { BusinessError } 401 - Parameter error. 432 * @throws { BusinessError } 201 - Permission denied. 433 * @syscap SystemCapability.Communication.NetStack 434 * @since 6 435 */ 436 /** 437 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 438 * @permission ohos.permission.INTERNET 439 * @param { string } url URL for establishing a WebSocket connection. 440 * @param { AsyncCallback<boolean> } callback - the callback of connect. 441 * @throws { BusinessError } 401 - Parameter error. 442 * @throws { BusinessError } 201 - Permission denied. 443 * @throws { BusinessError } 2302999 - Websocket other unknown error. 444 * @syscap SystemCapability.Communication.NetStack 445 * @crossplatform 446 * @since 10 447 */ 448 /** 449 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 450 * @permission ohos.permission.INTERNET 451 * @param { string } url URL for establishing a WebSocket connection. 452 * @param { AsyncCallback<boolean> } callback - the callback of connect. 453 * @throws { BusinessError } 401 - Parameter error. 454 * @throws { BusinessError } 201 - Permission denied. 455 * @throws { BusinessError } 2302999 - Websocket other unknown error. 456 * @syscap SystemCapability.Communication.NetStack 457 * @crossplatform 458 * @atomicservice 459 * @since 11 460 */ 461 /** 462 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 463 * @permission ohos.permission.INTERNET 464 * @param { string } url URL for establishing a WebSocket connection. 465 * @param { AsyncCallback<boolean> } callback - the callback of connect. 466 * @throws { BusinessError } 401 - Parameter error. 467 * @throws { BusinessError } 201 - Permission denied. 468 * @throws { BusinessError } 2302001 - Websocket url error. 469 * @throws { BusinessError } 2302002 - Websocket certificate file does not exist. 470 * @throws { BusinessError } 2302003 - Websocket connection already exists. 471 * @throws { BusinessError } 2302999 - Websocket other unknown error. 472 * @syscap SystemCapability.Communication.NetStack 473 * @crossplatform 474 * @atomicservice 475 * @since 12 476 */ 477 connect(url: string, callback: AsyncCallback<boolean>): void; 478 479 /** 480 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 481 * @permission ohos.permission.INTERNET 482 * @param { string } url URL for establishing a WebSocket connection. 483 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 484 * @param { AsyncCallback<boolean> } callback - the callback of connect. 485 * @throws { BusinessError } 401 - Parameter error. 486 * @throws { BusinessError } 201 - Permission denied. 487 * @syscap SystemCapability.Communication.NetStack 488 * @since 6 489 */ 490 /** 491 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 492 * @permission ohos.permission.INTERNET 493 * @param { string } url URL for establishing a WebSocket connection. 494 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 495 * @param { AsyncCallback<boolean> } callback - the callback of connect. 496 * @throws { BusinessError } 401 - Parameter error. 497 * @throws { BusinessError } 201 - Permission denied. 498 * @throws { BusinessError } 2302999 - Websocket other unknown error. 499 * @syscap SystemCapability.Communication.NetStack 500 * @crossplatform 501 * @since 10 502 */ 503 /** 504 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 505 * @permission ohos.permission.INTERNET 506 * @param { string } url URL for establishing a WebSocket connection. 507 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 508 * @param { AsyncCallback<boolean> } callback - the callback of connect. 509 * @throws { BusinessError } 401 - Parameter error. 510 * @throws { BusinessError } 201 - Permission denied. 511 * @throws { BusinessError } 2302999 - Websocket other unknown error. 512 * @syscap SystemCapability.Communication.NetStack 513 * @crossplatform 514 * @atomicservice 515 * @since 11 516 */ 517 /** 518 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 519 * @permission ohos.permission.INTERNET 520 * @param { string } url URL for establishing a WebSocket connection. 521 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 522 * @param { AsyncCallback<boolean> } callback - the callback of connect. 523 * @throws { BusinessError } 401 - Parameter error. 524 * @throws { BusinessError } 201 - Permission denied. 525 * @throws { BusinessError } 2302001 - Websocket url error. 526 * @throws { BusinessError } 2302002 - Websocket certificate file does not exist. 527 * @throws { BusinessError } 2302003 - Websocket connection already exists. 528 * @throws { BusinessError } 2302999 - Websocket other unknown error. 529 * @syscap SystemCapability.Communication.NetStack 530 * @crossplatform 531 * @atomicservice 532 * @since 12 533 */ 534 connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback<boolean>): void; 535 536 /** 537 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 538 * @permission ohos.permission.INTERNET 539 * @param { string } url URL for establishing a WebSocket connection. 540 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 541 * @returns { Promise<boolean> } The promise returned by the function. 542 * @throws { BusinessError } 401 - Parameter error. 543 * @throws { BusinessError } 201 - Permission denied. 544 * @syscap SystemCapability.Communication.NetStack 545 * @since 6 546 */ 547 /** 548 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 549 * @permission ohos.permission.INTERNET 550 * @param { string } url URL for establishing a WebSocket connection. 551 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 552 * @returns { Promise<boolean> } The promise returned by the function. 553 * @throws { BusinessError } 401 - Parameter error. 554 * @throws { BusinessError } 201 - Permission denied. 555 * @throws { BusinessError } 2302999 - Websocket other unknown error. 556 * @syscap SystemCapability.Communication.NetStack 557 * @crossplatform 558 * @since 10 559 */ 560 /** 561 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 562 * @permission ohos.permission.INTERNET 563 * @param { string } url URL for establishing a WebSocket connection. 564 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 565 * @returns { Promise<boolean> } The promise returned by the function. 566 * @throws { BusinessError } 401 - Parameter error. 567 * @throws { BusinessError } 201 - Permission denied. 568 * @throws { BusinessError } 2302999 - Websocket other unknown error. 569 * @syscap SystemCapability.Communication.NetStack 570 * @crossplatform 571 * @atomicservice 572 * @since 11 573 */ 574 /** 575 * Initiates a WebSocket request to establish a WebSocket connection to a given URL. 576 * @permission ohos.permission.INTERNET 577 * @param { string } url URL for establishing a WebSocket connection. 578 * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}. 579 * @returns { Promise<boolean> } The promise returned by the function. 580 * @throws { BusinessError } 401 - Parameter error. 581 * @throws { BusinessError } 201 - Permission denied. 582 * @throws { BusinessError } 2302001 - Websocket url error. 583 * @throws { BusinessError } 2302002 - Websocket certificate file does not exist. 584 * @throws { BusinessError } 2302003 - Websocket connection already exists. 585 * @throws { BusinessError } 2302999 - Websocket other unknown error. 586 * @syscap SystemCapability.Communication.NetStack 587 * @crossplatform 588 * @atomicservice 589 * @since 12 590 */ 591 connect(url: string, options?: WebSocketRequestOptions): Promise<boolean>; 592 593 /** 594 * Sends data through a WebSocket connection. 595 * @permission ohos.permission.INTERNET 596 * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8). 597 * @param { AsyncCallback<boolean> } callback - the callback of send. 598 * @throws { BusinessError } 401 - Parameter error. 599 * @throws { BusinessError } 201 - Permission denied. 600 * @syscap SystemCapability.Communication.NetStack 601 * @since 6 602 */ 603 /** 604 * Sends data through a WebSocket connection. 605 * @permission ohos.permission.INTERNET 606 * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8). 607 * @param { AsyncCallback<boolean> } callback - the callback of send. 608 * @throws { BusinessError } 401 - Parameter error. 609 * @throws { BusinessError } 201 - Permission denied. 610 * @syscap SystemCapability.Communication.NetStack 611 * @crossplatform 612 * @since 10 613 */ 614 /** 615 * Sends data through a WebSocket connection. 616 * @permission ohos.permission.INTERNET 617 * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8). 618 * @param { AsyncCallback<boolean> } callback - the callback of send. 619 * @throws { BusinessError } 401 - Parameter error. 620 * @throws { BusinessError } 201 - Permission denied. 621 * @syscap SystemCapability.Communication.NetStack 622 * @crossplatform 623 * @atomicservice 624 * @since 11 625 */ 626 send(data: string | ArrayBuffer, callback: AsyncCallback<boolean>): void; 627 628 /** 629 * Sends data through a WebSocket connection. 630 * @permission ohos.permission.INTERNET 631 * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8). 632 * @returns { Promise<boolean> } The promise returned by the function. 633 * @throws { BusinessError } 401 - Parameter error. 634 * @throws { BusinessError } 201 - Permission denied. 635 * @syscap SystemCapability.Communication.NetStack 636 * @since 6 637 */ 638 /** 639 * Sends data through a WebSocket connection. 640 * @permission ohos.permission.INTERNET 641 * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8). 642 * @returns { Promise<boolean> } The promise returned by the function. 643 * @throws { BusinessError } 401 - Parameter error. 644 * @throws { BusinessError } 201 - Permission denied. 645 * @syscap SystemCapability.Communication.NetStack 646 * @crossplatform 647 * @since 10 648 */ 649 /** 650 * Sends data through a WebSocket connection. 651 * @permission ohos.permission.INTERNET 652 * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8). 653 * @returns { Promise<boolean> } The promise returned by the function. 654 * @throws { BusinessError } 401 - Parameter error. 655 * @throws { BusinessError } 201 - Permission denied. 656 * @syscap SystemCapability.Communication.NetStack 657 * @crossplatform 658 * @atomicservice 659 * @since 11 660 */ 661 send(data: string | ArrayBuffer): Promise<boolean>; 662 663 /** 664 * Closes a WebSocket connection. 665 * @permission ohos.permission.INTERNET 666 * @param { AsyncCallback<boolean> } callback - the callback of close. 667 * @throws { BusinessError } 401 - Parameter error. 668 * @throws { BusinessError } 201 - Permission denied. 669 * @syscap SystemCapability.Communication.NetStack 670 * @since 6 671 */ 672 /** 673 * Closes a WebSocket connection. 674 * @permission ohos.permission.INTERNET 675 * @param { AsyncCallback<boolean> } callback - the callback of close. 676 * @throws { BusinessError } 401 - Parameter error. 677 * @throws { BusinessError } 201 - Permission denied. 678 * @syscap SystemCapability.Communication.NetStack 679 * @crossplatform 680 * @since 10 681 */ 682 /** 683 * Closes a WebSocket connection. 684 * @permission ohos.permission.INTERNET 685 * @param { AsyncCallback<boolean> } callback - the callback of close. 686 * @throws { BusinessError } 401 - Parameter error. 687 * @throws { BusinessError } 201 - Permission denied. 688 * @syscap SystemCapability.Communication.NetStack 689 * @crossplatform 690 * @atomicservice 691 * @since 11 692 */ 693 close(callback: AsyncCallback<boolean>): void; 694 695 /** 696 * Closes a WebSocket connection. 697 * @permission ohos.permission.INTERNET 698 * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}. 699 * @param { AsyncCallback<boolean> } callback - the callback of close. 700 * @throws { BusinessError } 401 - Parameter error. 701 * @throws { BusinessError } 201 - Permission denied. 702 * @syscap SystemCapability.Communication.NetStack 703 * @since 6 704 */ 705 /** 706 * Closes a WebSocket connection. 707 * @permission ohos.permission.INTERNET 708 * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}. 709 * @param { AsyncCallback<boolean> } callback - the callback of close. 710 * @throws { BusinessError } 401 - Parameter error. 711 * @throws { BusinessError } 201 - Permission denied. 712 * @syscap SystemCapability.Communication.NetStack 713 * @crossplatform 714 * @since 10 715 */ 716 /** 717 * Closes a WebSocket connection. 718 * @permission ohos.permission.INTERNET 719 * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}. 720 * @param { AsyncCallback<boolean> } callback - the callback of close. 721 * @throws { BusinessError } 401 - Parameter error. 722 * @throws { BusinessError } 201 - Permission denied. 723 * @syscap SystemCapability.Communication.NetStack 724 * @crossplatform 725 * @atomicservice 726 * @since 11 727 */ 728 close(options: WebSocketCloseOptions, callback: AsyncCallback<boolean>): void; 729 730 /** 731 * Closes a WebSocket connection. 732 * @permission ohos.permission.INTERNET 733 * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}. 734 * @returns { Promise<boolean> } The promise returned by the function. 735 * @throws { BusinessError } 401 - Parameter error. 736 * @throws { BusinessError } 201 - Permission denied. 737 * @syscap SystemCapability.Communication.NetStack 738 * @since 6 739 */ 740 /** 741 * Closes a WebSocket connection. 742 * @permission ohos.permission.INTERNET 743 * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}. 744 * @returns { Promise<boolean> } The promise returned by the function. 745 * @throws { BusinessError } 401 - Parameter error. 746 * @throws { BusinessError } 201 - Permission denied. 747 * @syscap SystemCapability.Communication.NetStack 748 * @crossplatform 749 * @since 10 750 */ 751 /** 752 * Closes a WebSocket connection. 753 * @permission ohos.permission.INTERNET 754 * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}. 755 * @returns { Promise<boolean> } The promise returned by the function. 756 * @throws { BusinessError } 401 - Parameter error. 757 * @throws { BusinessError } 201 - Permission denied. 758 * @syscap SystemCapability.Communication.NetStack 759 * @crossplatform 760 * @atomicservice 761 * @since 11 762 */ 763 close(options?: WebSocketCloseOptions): Promise<boolean>; 764 765 /** 766 * Enables listening for the open events of a WebSocket connection. 767 * @param { 'open' } type - event indicating that a WebSocket connection has been opened. 768 * @param { AsyncCallback<Object> } callback - the callback used to return the result. 769 * @syscap SystemCapability.Communication.NetStack 770 * @since 6 771 */ 772 /** 773 * Enables listening for the open events of a WebSocket connection. 774 * @param { 'open' } type - event indicating that a WebSocket connection has been opened. 775 * @param { AsyncCallback<Object> } callback - the callback used to return the result. 776 * @syscap SystemCapability.Communication.NetStack 777 * @crossplatform 778 * @since 10 779 */ 780 /** 781 * Enables listening for the open events of a WebSocket connection. 782 * @param { 'open' } type - event indicating that a WebSocket connection has been opened. 783 * @param { AsyncCallback<Object> } callback - the callback used to return the result. 784 * @syscap SystemCapability.Communication.NetStack 785 * @crossplatform 786 * @atomicservice 787 * @since 11 788 */ 789 on(type: 'open', callback: AsyncCallback<Object>): void; 790 791 /** 792 * Cancels listening for the open events of a WebSocket connection. 793 * @param { 'open' } type - event indicating that a WebSocket connection has been opened. 794 * @param { AsyncCallback<Object> } callback - the callback used to return the result. 795 * @syscap SystemCapability.Communication.NetStack 796 * @since 6 797 */ 798 /** 799 * Cancels listening for the open events of a WebSocket connection. 800 * @param { 'open' } type - event indicating that a WebSocket connection has been opened. 801 * @param { AsyncCallback<Object> } callback the callback used to return the result. 802 * @syscap SystemCapability.Communication.NetStack 803 * @crossplatform 804 * @since 10 805 */ 806 /** 807 * Cancels listening for the open events of a WebSocket connection. 808 * @param { 'open' } type - event indicating that a WebSocket connection has been opened. 809 * @param { AsyncCallback<Object> } callback the callback used to return the result. 810 * @syscap SystemCapability.Communication.NetStack 811 * @crossplatform 812 * @atomicservice 813 * @since 11 814 */ 815 off(type: 'open', callback?: AsyncCallback<Object>): void; 816 817 /** 818 * Enables listening for the message events of a WebSocket connection. 819 * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8). 820 * @param { 'message' } type - event indicating that a message has been received from the server. 821 * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result. 822 * @syscap SystemCapability.Communication.NetStack 823 * @since 6 824 */ 825 /** 826 * Enables listening for the message events of a WebSocket connection. 827 * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8). 828 * @param { 'message' } type - event indicating that a message has been received from the server. 829 * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result. 830 * @syscap SystemCapability.Communication.NetStack 831 * @crossplatform 832 * @since 10 833 */ 834 /** 835 * Enables listening for the message events of a WebSocket connection. 836 * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8). 837 * @param { 'message' } type - event indicating that a message has been received from the server. 838 * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result. 839 * @syscap SystemCapability.Communication.NetStack 840 * @crossplatform 841 * @atomicservice 842 * @since 11 843 */ 844 on(type: 'message', callback: AsyncCallback<string | ArrayBuffer>): void; 845 846 /** 847 * Cancels listening for the message events of a WebSocket connection. 848 * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8). 849 * @param { 'message' } type - event indicating that a message has been received from the server. 850 * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result. 851 * @syscap SystemCapability.Communication.NetStack 852 * @since 6 853 */ 854 /** 855 * Cancels listening for the message events of a WebSocket connection. 856 * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8). 857 * @param { 'message' } type - event indicating that a message has been received from the server. 858 * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result. 859 * @syscap SystemCapability.Communication.NetStack 860 * @crossplatform 861 * @since 10 862 */ 863 /** 864 * Cancels listening for the message events of a WebSocket connection. 865 * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8). 866 * @param { 'message' } type - event indicating that a message has been received from the server. 867 * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result. 868 * @syscap SystemCapability.Communication.NetStack 869 * @crossplatform 870 * @atomicservice 871 * @since 11 872 */ 873 off(type: 'message', callback?: AsyncCallback<string | ArrayBuffer>): void; 874 875 /** 876 * Enables listening for the close events of a WebSocket connection. 877 * @param { 'close' } type - event indicating that a WebSocket connection has been closed. 878 * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result. 879 * <br>close indicates the close error code and reason indicates the error code description. 880 * @syscap SystemCapability.Communication.NetStack 881 * @since 6 882 */ 883 /** 884 * Enables listening for the close events of a WebSocket connection. 885 * @param { 'close' } type - event indicating that a WebSocket connection has been closed. 886 * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result. 887 * <br>close indicates the close error code and reason indicates the error code description. 888 * @syscap SystemCapability.Communication.NetStack 889 * @crossplatform 890 * @since 10 891 */ 892 /** 893 * Enables listening for the close events of a WebSocket connection. 894 * @param { 'close' } type - event indicating that a WebSocket connection has been closed. 895 * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result. 896 * <br>close indicates the close error code and reason indicates the error code description. 897 * @syscap SystemCapability.Communication.NetStack 898 * @crossplatform 899 * @atomicservice 900 * @since 11 901 */ 902 on(type: 'close', callback: AsyncCallback<CloseResult>): void; 903 904 /** 905 * Cancels listening for the close events of a WebSocket connection. 906 * @param { 'close' } type - event indicating that a WebSocket connection has been closed. 907 * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result. 908 * <br>close indicates the close error code and reason indicates the error code description. 909 * @syscap SystemCapability.Communication.NetStack 910 * @since 6 911 */ 912 /** 913 * Cancels listening for the close events of a WebSocket connection. 914 * @param { 'close' } type - event indicating that a WebSocket connection has been closed. 915 * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result. 916 * <br>close indicates the close error code and reason indicates the error code description. 917 * @syscap SystemCapability.Communication.NetStack 918 * @crossplatform 919 * @since 10 920 */ 921 /** 922 * Cancels listening for the close events of a WebSocket connection. 923 * @param { 'close' } type - event indicating that a WebSocket connection has been closed. 924 * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result. 925 * <br>close indicates the close error code and reason indicates the error code description. 926 * @syscap SystemCapability.Communication.NetStack 927 * @crossplatform 928 * @atomicservice 929 * @since 11 930 */ 931 off(type: 'close', callback?: AsyncCallback<CloseResult>): void; 932 933 /** 934 * Enables listening for the error events of a WebSocket connection. 935 * @param { 'error' } type - event indicating the WebSocket connection has encountered an error. 936 * @param { ErrorCallback } callback - the callback used to return the result. 937 * @syscap SystemCapability.Communication.NetStack 938 * @since 6 939 */ 940 /** 941 * Enables listening for the error events of a WebSocket connection. 942 * @param { 'error' } type - event indicating the WebSocket connection has encountered an error. 943 * @param { ErrorCallback } callback - the callback used to return the result. 944 * @syscap SystemCapability.Communication.NetStack 945 * @crossplatform 946 * @since 10 947 */ 948 /** 949 * Enables listening for the error events of a WebSocket connection. 950 * @param { 'error' } type - event indicating the WebSocket connection has encountered an error. 951 * @param { ErrorCallback } callback - the callback used to return the result. 952 * @syscap SystemCapability.Communication.NetStack 953 * @crossplatform 954 * @atomicservice 955 * @since 11 956 */ 957 on(type: 'error', callback: ErrorCallback): void; 958 959 /** 960 * Cancels listening for the error events of a WebSocket connection. 961 * @param { 'error' } type - event indicating the WebSocket connection has encountered an error. 962 * @param { ErrorCallback } callback - the callback used to return the result. 963 * @syscap SystemCapability.Communication.NetStack 964 * @since 6 965 */ 966 /** 967 * Cancels listening for the error events of a WebSocket connection. 968 * @param { 'error' } type - event indicating the WebSocket connection has encountered an error. 969 * @param { ErrorCallback } callback - the callback used to return the result. 970 * @syscap SystemCapability.Communication.NetStack 971 * @crossplatform 972 * @since 10 973 */ 974 /** 975 * Cancels listening for the error events of a WebSocket connection. 976 * @param { 'error' } type - event indicating the WebSocket connection has encountered an error. 977 * @param { ErrorCallback } callback - the callback used to return the result. 978 * @syscap SystemCapability.Communication.NetStack 979 * @crossplatform 980 * @atomicservice 981 * @since 11 982 */ 983 off(type: 'error', callback?: ErrorCallback): void; 984 985 /** 986 * Enables listening for receiving data ends events of a WebSocket connection. 987 * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends. 988 * @param { Callback<void> } callback - the callback used to return the result. 989 * @syscap SystemCapability.Communication.NetStack 990 * @since 11 991 */ 992 /** 993 * Enables listening for receiving data ends events of a WebSocket connection. 994 * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends. 995 * @param { Callback<void> } callback - the callback used to return the result. 996 * @syscap SystemCapability.Communication.NetStack 997 * @crossplatform 998 * @since 12 999 */ 1000 on(type: 'dataEnd', callback: Callback<void>): void; 1001 1002 /** 1003 * Cancels listening for receiving data ends events of a WebSocket connection. 1004 * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends. 1005 * @param { Callback<void> } [ callback ] - the callback used to return the result. 1006 * @syscap SystemCapability.Communication.NetStack 1007 * @since 11 1008 */ 1009 /** 1010 * Cancels listening for receiving data ends events of a WebSocket connection. 1011 * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends. 1012 * @param { Callback<void> } [ callback ] - the callback used to return the result. 1013 * @syscap SystemCapability.Communication.NetStack 1014 * @crossplatform 1015 * @since 12 1016 */ 1017 off(type: 'dataEnd', callback?: Callback<void>): void; 1018 1019 /** 1020 * Registers an observer for HTTP Response Header events. 1021 * @param { 'headerReceive'} type - Indicates Event name. 1022 * @param { Callback<ResponseHeaders> } callback - the callback used to return the result. 1023 * @syscap SystemCapability.Communication.NetStack 1024 * @since 12 1025 */ 1026 on(type: 'headerReceive', callback: Callback<ResponseHeaders>): void; 1027 1028 /** 1029 * Unregisters the observer for HTTP Response Header events. 1030 * @param { 'headerReceive' } type - Indicates Event name. 1031 * @param { Callback<ResponseHeaders> } [callback] - the callback used to return the result. 1032 * @syscap SystemCapability.Communication.NetStack 1033 * @since 12 1034 */ 1035 off(type: 'headerReceive', callback?: Callback<ResponseHeaders>): void; 1036 } 1037} 1038 1039export default webSocket;