• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 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 } 2302998 - It is not allowed to access this domain.
442     * @throws { BusinessError } 2302999 - Websocket other unknown error.
443     * @syscap SystemCapability.Communication.NetStack
444     * @crossplatform
445     * @atomicservice
446     * @since 12
447     */
448    connect(url: string, callback: AsyncCallback<boolean>): void;
449
450    /**
451     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
452     * @permission ohos.permission.INTERNET
453     * @param { string } url URL for establishing a WebSocket connection.
454     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
455     * @param { AsyncCallback<boolean> } callback - the callback of connect.
456     * @throws { BusinessError } 401 - Parameter error.
457     * @throws { BusinessError } 201 - Permission denied.
458     * @syscap SystemCapability.Communication.NetStack
459     * @since 6
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 { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
466     * @param { AsyncCallback<boolean> } callback - the callback of connect.
467     * @throws { BusinessError } 401 - Parameter error.
468     * @throws { BusinessError } 201 - Permission denied.
469     * @throws { BusinessError } 2302999 - Websocket other unknown error.
470     * @syscap SystemCapability.Communication.NetStack
471     * @crossplatform
472     * @since 10
473     */
474    /**
475     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
476     * @permission ohos.permission.INTERNET
477     * @param { string } url URL for establishing a WebSocket connection.
478     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
479     * @param { AsyncCallback<boolean> } callback - the callback of connect.
480     * @throws { BusinessError } 401 - Parameter error.
481     * @throws { BusinessError } 201 - Permission denied.
482     * @throws { BusinessError } 2302999 - Websocket other unknown error.
483     * @syscap SystemCapability.Communication.NetStack
484     * @crossplatform
485     * @atomicservice
486     * @since 11
487     */
488    /**
489     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
490     * @permission ohos.permission.INTERNET
491     * @param { string } url URL for establishing a WebSocket connection.
492     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
493     * @param { AsyncCallback<boolean> } callback - the callback of connect.
494     * @throws { BusinessError } 401 - Parameter error.
495     * @throws { BusinessError } 201 - Permission denied.
496     * @throws { BusinessError } 2302001 - Websocket url error.
497     * @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
498     * @throws { BusinessError } 2302003 - Websocket connection already exists.
499     * @throws { BusinessError } 2302998 - It is not allowed to access this domain.
500     * @throws { BusinessError } 2302999 - Websocket other unknown error.
501     * @syscap SystemCapability.Communication.NetStack
502     * @crossplatform
503     * @atomicservice
504     * @since 12
505     */
506    connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback<boolean>): void;
507
508    /**
509     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
510     * @permission ohos.permission.INTERNET
511     * @param { string } url URL for establishing a WebSocket connection.
512     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
513     * @returns { Promise<boolean> } The promise returned by the function.
514     * @throws { BusinessError } 401 - Parameter error.
515     * @throws { BusinessError } 201 - Permission denied.
516     * @syscap SystemCapability.Communication.NetStack
517     * @since 6
518     */
519    /**
520     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
521     * @permission ohos.permission.INTERNET
522     * @param { string } url URL for establishing a WebSocket connection.
523     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
524     * @returns { Promise<boolean> } The promise returned by the function.
525     * @throws { BusinessError } 401 - Parameter error.
526     * @throws { BusinessError } 201 - Permission denied.
527     * @throws { BusinessError } 2302999 - Websocket other unknown error.
528     * @syscap SystemCapability.Communication.NetStack
529     * @crossplatform
530     * @since 10
531     */
532    /**
533     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
534     * @permission ohos.permission.INTERNET
535     * @param { string } url URL for establishing a WebSocket connection.
536     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
537     * @returns { Promise<boolean> } The promise returned by the function.
538     * @throws { BusinessError } 401 - Parameter error.
539     * @throws { BusinessError } 201 - Permission denied.
540     * @throws { BusinessError } 2302999 - Websocket other unknown error.
541     * @syscap SystemCapability.Communication.NetStack
542     * @crossplatform
543     * @atomicservice
544     * @since 11
545     */
546    /**
547     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
548     * @permission ohos.permission.INTERNET
549     * @param { string } url URL for establishing a WebSocket connection.
550     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
551     * @returns { Promise<boolean> } The promise returned by the function.
552     * @throws { BusinessError } 401 - Parameter error.
553     * @throws { BusinessError } 201 - Permission denied.
554     * @throws { BusinessError } 2302001 - Websocket url error.
555     * @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
556     * @throws { BusinessError } 2302003 - Websocket connection already exists.
557     * @throws { BusinessError } 2302998 - It is not allowed to access this domain.
558     * @throws { BusinessError } 2302999 - Websocket other unknown error.
559     * @syscap SystemCapability.Communication.NetStack
560     * @crossplatform
561     * @atomicservice
562     * @since 12
563     */
564    connect(url: string, options?: WebSocketRequestOptions): Promise<boolean>;
565
566    /**
567     * Sends data through a WebSocket connection.
568     * @permission ohos.permission.INTERNET
569     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
570     * @param { AsyncCallback<boolean> } callback - the callback of send.
571     * @throws { BusinessError } 401 - Parameter error.
572     * @throws { BusinessError } 201 - Permission denied.
573     * @syscap SystemCapability.Communication.NetStack
574     * @since 6
575     */
576    /**
577     * Sends data through a WebSocket connection.
578     * @permission ohos.permission.INTERNET
579     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
580     * @param { AsyncCallback<boolean> } callback - the callback of send.
581     * @throws { BusinessError } 401 - Parameter error.
582     * @throws { BusinessError } 201 - Permission denied.
583     * @syscap SystemCapability.Communication.NetStack
584     * @crossplatform
585     * @since 10
586     */
587    /**
588     * Sends data through a WebSocket connection.
589     * @permission ohos.permission.INTERNET
590     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
591     * @param { AsyncCallback<boolean> } callback - the callback of send.
592     * @throws { BusinessError } 401 - Parameter error.
593     * @throws { BusinessError } 201 - Permission denied.
594     * @syscap SystemCapability.Communication.NetStack
595     * @crossplatform
596     * @atomicservice
597     * @since 11
598     */
599    send(data: string | ArrayBuffer, callback: AsyncCallback<boolean>): void;
600
601    /**
602     * Sends data through a WebSocket connection.
603     * @permission ohos.permission.INTERNET
604     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
605     * @returns { Promise<boolean> } The promise returned by the function.
606     * @throws { BusinessError } 401 - Parameter error.
607     * @throws { BusinessError } 201 - Permission denied.
608     * @syscap SystemCapability.Communication.NetStack
609     * @since 6
610     */
611    /**
612     * Sends data through a WebSocket connection.
613     * @permission ohos.permission.INTERNET
614     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
615     * @returns { Promise<boolean> } The promise returned by the function.
616     * @throws { BusinessError } 401 - Parameter error.
617     * @throws { BusinessError } 201 - Permission denied.
618     * @syscap SystemCapability.Communication.NetStack
619     * @crossplatform
620     * @since 10
621     */
622    /**
623     * Sends data through a WebSocket connection.
624     * @permission ohos.permission.INTERNET
625     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
626     * @returns { Promise<boolean> } The promise returned by the function.
627     * @throws { BusinessError } 401 - Parameter error.
628     * @throws { BusinessError } 201 - Permission denied.
629     * @syscap SystemCapability.Communication.NetStack
630     * @crossplatform
631     * @atomicservice
632     * @since 11
633     */
634    send(data: string | ArrayBuffer): Promise<boolean>;
635
636    /**
637     * Closes a WebSocket connection.
638     * @permission ohos.permission.INTERNET
639     * @param { AsyncCallback<boolean> } callback - the callback of close.
640     * @throws { BusinessError } 401 - Parameter error.
641     * @throws { BusinessError } 201 - Permission denied.
642     * @syscap SystemCapability.Communication.NetStack
643     * @since 6
644     */
645    /**
646     * Closes a WebSocket connection.
647     * @permission ohos.permission.INTERNET
648     * @param { AsyncCallback<boolean> } callback - the callback of close.
649     * @throws { BusinessError } 401 - Parameter error.
650     * @throws { BusinessError } 201 - Permission denied.
651     * @syscap SystemCapability.Communication.NetStack
652     * @crossplatform
653     * @since 10
654     */
655    /**
656     * Closes a WebSocket connection.
657     * @permission ohos.permission.INTERNET
658     * @param { AsyncCallback<boolean> } callback - the callback of close.
659     * @throws { BusinessError } 401 - Parameter error.
660     * @throws { BusinessError } 201 - Permission denied.
661     * @syscap SystemCapability.Communication.NetStack
662     * @crossplatform
663     * @atomicservice
664     * @since 11
665     */
666    close(callback: AsyncCallback<boolean>): void;
667
668    /**
669     * Closes a WebSocket connection.
670     * @permission ohos.permission.INTERNET
671     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
672     * @param { AsyncCallback<boolean> } callback - the callback of close.
673     * @throws { BusinessError } 401 - Parameter error.
674     * @throws { BusinessError } 201 - Permission denied.
675     * @syscap SystemCapability.Communication.NetStack
676     * @since 6
677     */
678    /**
679     * Closes a WebSocket connection.
680     * @permission ohos.permission.INTERNET
681     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
682     * @param { AsyncCallback<boolean> } callback - the callback of close.
683     * @throws { BusinessError } 401 - Parameter error.
684     * @throws { BusinessError } 201 - Permission denied.
685     * @syscap SystemCapability.Communication.NetStack
686     * @crossplatform
687     * @since 10
688     */
689    /**
690     * Closes a WebSocket connection.
691     * @permission ohos.permission.INTERNET
692     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
693     * @param { AsyncCallback<boolean> } callback - the callback of close.
694     * @throws { BusinessError } 401 - Parameter error.
695     * @throws { BusinessError } 201 - Permission denied.
696     * @syscap SystemCapability.Communication.NetStack
697     * @crossplatform
698     * @atomicservice
699     * @since 11
700     */
701    close(options: WebSocketCloseOptions, callback: AsyncCallback<boolean>): void;
702
703    /**
704     * Closes a WebSocket connection.
705     * @permission ohos.permission.INTERNET
706     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
707     * @returns { Promise<boolean> } The promise returned by the function.
708     * @throws { BusinessError } 401 - Parameter error.
709     * @throws { BusinessError } 201 - Permission denied.
710     * @syscap SystemCapability.Communication.NetStack
711     * @since 6
712     */
713    /**
714     * Closes a WebSocket connection.
715     * @permission ohos.permission.INTERNET
716     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
717     * @returns { Promise<boolean> } The promise returned by the function.
718     * @throws { BusinessError } 401 - Parameter error.
719     * @throws { BusinessError } 201 - Permission denied.
720     * @syscap SystemCapability.Communication.NetStack
721     * @crossplatform
722     * @since 10
723     */
724    /**
725     * Closes a WebSocket connection.
726     * @permission ohos.permission.INTERNET
727     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
728     * @returns { Promise<boolean> } The promise returned by the function.
729     * @throws { BusinessError } 401 - Parameter error.
730     * @throws { BusinessError } 201 - Permission denied.
731     * @syscap SystemCapability.Communication.NetStack
732     * @crossplatform
733     * @atomicservice
734     * @since 11
735     */
736    close(options?: WebSocketCloseOptions): Promise<boolean>;
737
738    /**
739     * Enables listening for the open events of a WebSocket connection.
740     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
741     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
742     * @syscap SystemCapability.Communication.NetStack
743     * @since 6
744     */
745    /**
746     * Enables listening for the open events of a WebSocket connection.
747     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
748     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
749     * @syscap SystemCapability.Communication.NetStack
750     * @crossplatform
751     * @since 10
752     */
753    /**
754     * Enables listening for the open events of a WebSocket connection.
755     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
756     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
757     * @syscap SystemCapability.Communication.NetStack
758     * @crossplatform
759     * @atomicservice
760     * @since 11
761     */
762    on(type: 'open', callback: AsyncCallback<Object>): void;
763
764    /**
765     * Cancels listening for the open events of a WebSocket connection.
766     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
767     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
768     * @syscap SystemCapability.Communication.NetStack
769     * @since 6
770     */
771    /**
772     * Cancels listening for the open events of a WebSocket connection.
773     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
774     * @param { AsyncCallback<Object> } callback the callback used to return the result.
775     * @syscap SystemCapability.Communication.NetStack
776     * @crossplatform
777     * @since 10
778     */
779    /**
780     * Cancels listening for the open events of a WebSocket connection.
781     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
782     * @param { AsyncCallback<Object> } callback the callback used to return the result.
783     * @syscap SystemCapability.Communication.NetStack
784     * @crossplatform
785     * @atomicservice
786     * @since 11
787     */
788    off(type: 'open', callback?: AsyncCallback<Object>): void;
789
790    /**
791     * Enables listening for the message events of a WebSocket connection.
792     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
793     * @param { 'message' } type - event indicating that a message has been received from the server.
794     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
795     * @syscap SystemCapability.Communication.NetStack
796     * @since 6
797     */
798    /**
799     * Enables listening for the message events of a WebSocket connection.
800     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
801     * @param { 'message' } type - event indicating that a message has been received from the server.
802     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
803     * @syscap SystemCapability.Communication.NetStack
804     * @crossplatform
805     * @since 10
806     */
807    /**
808     * Enables listening for the message events of a WebSocket connection.
809     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
810     * @param { 'message' } type - event indicating that a message has been received from the server.
811     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
812     * @syscap SystemCapability.Communication.NetStack
813     * @crossplatform
814     * @atomicservice
815     * @since 11
816     */
817    on(type: 'message', callback: AsyncCallback<string | ArrayBuffer>): void;
818
819    /**
820     * Cancels listening for the message events of a WebSocket connection.
821     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
822     * @param { 'message' } type - event indicating that a message has been received from the server.
823     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
824     * @syscap SystemCapability.Communication.NetStack
825     * @since 6
826     */
827    /**
828     * Cancels listening for the message events of a WebSocket connection.
829     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
830     * @param { 'message' } type - event indicating that a message has been received from the server.
831     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
832     * @syscap SystemCapability.Communication.NetStack
833     * @crossplatform
834     * @since 10
835     */
836    /**
837     * Cancels listening for the message events of a WebSocket connection.
838     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
839     * @param { 'message' } type - event indicating that a message has been received from the server.
840     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
841     * @syscap SystemCapability.Communication.NetStack
842     * @crossplatform
843     * @atomicservice
844     * @since 11
845     */
846    off(type: 'message', callback?: AsyncCallback<string | ArrayBuffer>): void;
847
848    /**
849     * Enables listening for the close events of a WebSocket connection.
850     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
851     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
852     * <br>close indicates the close error code and reason indicates the error code description.
853     * @syscap SystemCapability.Communication.NetStack
854     * @since 6
855     */
856    /**
857     * Enables listening for the close events of a WebSocket connection.
858     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
859     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
860     * <br>close indicates the close error code and reason indicates the error code description.
861     * @syscap SystemCapability.Communication.NetStack
862     * @crossplatform
863     * @since 10
864     */
865    /**
866     * Enables listening for the close events of a WebSocket connection.
867     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
868     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
869     * <br>close indicates the close error code and reason indicates the error code description.
870     * @syscap SystemCapability.Communication.NetStack
871     * @crossplatform
872     * @atomicservice
873     * @since 11
874     */
875    on(type: 'close', callback: AsyncCallback<CloseResult>): void;
876
877    /**
878     * Cancels listening for the close events of a WebSocket connection.
879     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
880     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
881     * <br>close indicates the close error code and reason indicates the error code description.
882     * @syscap SystemCapability.Communication.NetStack
883     * @since 6
884     */
885    /**
886     * Cancels listening for the close events of a WebSocket connection.
887     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
888     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
889     * <br>close indicates the close error code and reason indicates the error code description.
890     * @syscap SystemCapability.Communication.NetStack
891     * @crossplatform
892     * @since 10
893     */
894    /**
895     * Cancels listening for the close events of a WebSocket connection.
896     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
897     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
898     * <br>close indicates the close error code and reason indicates the error code description.
899     * @syscap SystemCapability.Communication.NetStack
900     * @crossplatform
901     * @atomicservice
902     * @since 11
903     */
904    off(type: 'close', callback?: AsyncCallback<CloseResult>): void;
905
906    /**
907     * Enables listening for the error events of a WebSocket connection.
908     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
909     * @param { ErrorCallback } callback - the callback used to return the result.
910     * @syscap SystemCapability.Communication.NetStack
911     * @since 6
912     */
913    /**
914     * Enables listening for the error events of a WebSocket connection.
915     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
916     * @param { ErrorCallback } callback - the callback used to return the result.
917     * @syscap SystemCapability.Communication.NetStack
918     * @crossplatform
919     * @since 10
920     */
921    /**
922     * Enables listening for the error events of a WebSocket connection.
923     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
924     * @param { ErrorCallback } callback - the callback used to return the result.
925     * @syscap SystemCapability.Communication.NetStack
926     * @crossplatform
927     * @atomicservice
928     * @since 11
929     */
930    on(type: 'error', callback: ErrorCallback): void;
931
932    /**
933     * Cancels listening for the error events of a WebSocket connection.
934     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
935     * @param { ErrorCallback } callback - the callback used to return the result.
936     * @syscap SystemCapability.Communication.NetStack
937     * @since 6
938     */
939    /**
940     * Cancels listening for the error events of a WebSocket connection.
941     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
942     * @param { ErrorCallback } callback - the callback used to return the result.
943     * @syscap SystemCapability.Communication.NetStack
944     * @crossplatform
945     * @since 10
946     */
947    /**
948     * Cancels listening for the error events of a WebSocket connection.
949     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
950     * @param { ErrorCallback } callback - the callback used to return the result.
951     * @syscap SystemCapability.Communication.NetStack
952     * @crossplatform
953     * @atomicservice
954     * @since 11
955     */
956    off(type: 'error', callback?: ErrorCallback): void;
957
958    /**
959     * Enables listening for receiving data ends events of a WebSocket connection.
960     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
961     * @param { Callback<void> } callback - the callback used to return the result.
962     * @syscap SystemCapability.Communication.NetStack
963     * @since 11
964     */
965    /**
966     * Enables listening for receiving data ends events of a WebSocket connection.
967     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
968     * @param { Callback<void> } callback - the callback used to return the result.
969     * @syscap SystemCapability.Communication.NetStack
970     * @crossplatform
971     * @since 12
972     */
973    on(type: 'dataEnd', callback: Callback<void>): void;
974
975    /**
976     * Cancels listening for receiving data ends events of a WebSocket connection.
977     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
978     * @param { Callback<void> } [ callback ] - the callback used to return the result.
979     * @syscap SystemCapability.Communication.NetStack
980     * @since 11
981     */
982    /**
983     * Cancels listening for receiving data ends events of a WebSocket connection.
984     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
985     * @param { Callback<void> } [ callback ] - the callback used to return the result.
986     * @syscap SystemCapability.Communication.NetStack
987     * @crossplatform
988     * @since 12
989     */
990    off(type: 'dataEnd', callback?: Callback<void>): void;
991
992    /**
993     * Registers an observer for HTTP Response Header events.
994     * @param { 'headerReceive'} type - Indicates Event name.
995     * @param { Callback<ResponseHeaders> } callback - the callback used to return the result.
996     * @syscap SystemCapability.Communication.NetStack
997     * @since 12
998     */
999    on(type: 'headerReceive', callback: Callback<ResponseHeaders>): void;
1000
1001    /**
1002     * Unregisters the observer for HTTP Response Header events.
1003     * @param { 'headerReceive' } type - Indicates Event name.
1004     * @param { Callback<ResponseHeaders> } [callback] - the callback used to return the result.
1005     * @syscap SystemCapability.Communication.NetStack
1006     * @since 12
1007     */
1008    off(type: 'headerReceive', callback?: Callback<ResponseHeaders>): void;
1009  }
1010}
1011
1012export default webSocket;