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