• 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     * 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  /**
177   * HTTP proxy configuration.
178   * system: means that use system proxy configuration.
179   * no-proxy: means do not use proxy.
180   * object of @type {connection.HttpProxy} means providing custom proxy settings
181   * @typedef { 'system' | 'no-proxy' | HttpProxy }
182   * @syscap SystemCapability.Communication.NetStack
183   * @since 12
184   */
185  export type ProxyConfiguration = 'system' | 'no-proxy' | HttpProxy;
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   * @since 11
194   */
195  /**
196   * The clientCert field of the client certificate, which includes three attributes:
197   * client certificate (certPath) and only support PEM format, certificate private key (keyPath),
198   * and passphrase (keyPassword).
199   * @interface ClientCert
200   * @syscap SystemCapability.Communication.NetStack
201   * @crossplatform
202   * @since 12
203   */
204  export interface ClientCert {
205    /**
206     * The path to the client certificate file.
207     * @type {string}
208     * @syscap SystemCapability.Communication.NetStack
209     * @since 11
210     */
211    /**
212     * The path to the client certificate file.
213     * @type {string}
214     * @syscap SystemCapability.Communication.NetStack
215     * @crossplatform
216     * @since 12
217     */
218    certPath: string;
219
220    /**
221     * The path of the client certificate private key file.
222     * @type {string}
223     * @syscap SystemCapability.Communication.NetStack
224     * @since 11
225     */
226    /**
227     * The path of the client certificate private key file.
228     * @type {string}
229     * @syscap SystemCapability.Communication.NetStack
230     * @crossplatform
231     * @since 12
232     */
233    keyPath: string;
234
235    /**
236     * Client certificate password.
237     * @type {?string}
238     * @syscap SystemCapability.Communication.NetStack
239     * @since 11
240     */
241    /**
242     * Client certificate password.
243     * @type {?string}
244     * @syscap SystemCapability.Communication.NetStack
245     * @crossplatform
246     * @since 12
247     */
248    keyPassword?: string;
249  }
250
251  /**
252   * Defines the optional parameters carried in the request for closing a WebSocket connection.
253   * @interface WebSocketCloseOptions
254   * @syscap SystemCapability.Communication.NetStack
255   * @since 6
256   */
257  /**
258   * Defines the optional parameters carried in the request for closing a WebSocket connection.
259   * @interface WebSocketCloseOptions
260   * @syscap SystemCapability.Communication.NetStack
261   * @crossplatform
262   * @since 10
263   */
264  /**
265   * Defines the optional parameters carried in the request for closing a WebSocket connection.
266   * @interface WebSocketCloseOptions
267   * @syscap SystemCapability.Communication.NetStack
268   * @crossplatform
269   * @atomicservice
270   * @since 11
271   */
272  export interface WebSocketCloseOptions {
273    /**
274     * Error code.
275     * @type {?number}
276     * @syscap SystemCapability.Communication.NetStack
277     * @since 6
278     */
279    /**
280     * Error code.
281     * @type {?number}
282     * @syscap SystemCapability.Communication.NetStack
283     * @crossplatform
284     * @since 10
285     */
286    /**
287     * Error code.
288     * @type {?number}
289     * @syscap SystemCapability.Communication.NetStack
290     * @crossplatform
291     * @atomicservice
292     * @since 11
293     */
294    code?: number;
295    /**
296     * Error cause.
297     * @type {?string}
298     * @syscap SystemCapability.Communication.NetStack
299     * @since 6
300     */
301    /**
302     * Error cause.
303     * @type {?string}
304     * @syscap SystemCapability.Communication.NetStack
305     * @crossplatform
306     * @since 10
307     */
308    /**
309     * Error cause.
310     * @type {?string}
311     * @syscap SystemCapability.Communication.NetStack
312     * @crossplatform
313     * @atomicservice
314     * @since 11
315     */
316    reason?: string;
317  }
318
319  /**
320   * The result for closing a WebSocket connection.
321   * @interface CloseResult
322   * @syscap SystemCapability.Communication.NetStack
323   * @crossplatform
324   * @since 10
325   */
326  /**
327   * The result for closing a WebSocket connection.
328   * @interface CloseResult
329   * @syscap SystemCapability.Communication.NetStack
330   * @crossplatform
331   * @atomicservice
332   * @since 11
333   */
334  export interface CloseResult {
335    /**
336     * Error code.
337     * @type {number}
338     * @syscap SystemCapability.Communication.NetStack
339     * @crossplatform
340     * @since 10
341     */
342    /**
343     * Error code.
344     * @type {number}
345     * @syscap SystemCapability.Communication.NetStack
346     * @crossplatform
347     * @atomicservice
348     * @since 11
349     */
350    code: number;
351    /**
352     * Error cause.
353     * @type {string}
354     * @syscap SystemCapability.Communication.NetStack
355     * @crossplatform
356     * @since 10
357     */
358    /**
359     * Error cause.
360     * @type {string}
361     * @syscap SystemCapability.Communication.NetStack
362     * @crossplatform
363     * @atomicservice
364     * @since 11
365     */
366    reason: string;
367  }
368
369  /**
370   * HTTP response headers.
371   * @typedef { object }
372   * @syscap SystemCapability.Communication.NetStack
373   * @since 12
374   */
375  export type ResponseHeaders = {
376    [k: string]: string | string[] | undefined;
377  }
378
379  /**
380   * <p>Defines a WebSocket object. Before invoking WebSocket APIs,
381   * you need to call webSocket.createWebSocket to create a WebSocket object.</p>
382   * @interface WebSocket
383   * @syscap SystemCapability.Communication.NetStack
384   * @since 6
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   * @since 10
393   */
394  /**
395   * <p>Defines a WebSocket object. Before invoking WebSocket APIs,
396   * you need to call webSocket.createWebSocket to create a WebSocket object.</p>
397   * @interface WebSocket
398   * @syscap SystemCapability.Communication.NetStack
399   * @crossplatform
400   * @atomicservice
401   * @since 11
402   */
403  export interface WebSocket {
404    /**
405     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
406     * @permission ohos.permission.INTERNET
407     * @param { string } url - URL for establishing a WebSocket connection.
408     * @param { AsyncCallback<boolean> } callback - the callback of connect.
409     * @throws { BusinessError } 401 - Parameter error.
410     * @throws { BusinessError } 201 - Permission denied.
411     * @syscap SystemCapability.Communication.NetStack
412     * @since 6
413     */
414    /**
415     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
416     * @permission ohos.permission.INTERNET
417     * @param { string } url URL for establishing a WebSocket connection.
418     * @param { AsyncCallback<boolean> } callback - the callback of connect.
419     * @throws { BusinessError } 401 - Parameter error.
420     * @throws { BusinessError } 201 - Permission denied.
421     * @throws { BusinessError } 2302999 - Internal error.
422     * @syscap SystemCapability.Communication.NetStack
423     * @crossplatform
424     * @since 10
425     */
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     * @throws { BusinessError } 2302999 - Internal error.
434     * @syscap SystemCapability.Communication.NetStack
435     * @crossplatform
436     * @atomicservice
437     * @since 11
438     */
439    /**
440     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
441     * @permission ohos.permission.INTERNET
442     * @param { string } url URL for establishing a WebSocket connection.
443     * @param { AsyncCallback<boolean> } callback - the callback of connect.
444     * @throws { BusinessError } 401 - Parameter error.
445     * @throws { BusinessError } 201 - Permission denied.
446     * @throws { BusinessError } 2302001 - Websocket url error.
447     * @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
448     * @throws { BusinessError } 2302003 - Websocket connection already exists.
449     * @throws { BusinessError } 2302998 - It is not allowed to access this domain.
450     * @throws { BusinessError } 2302999 - Internal error.
451     * @syscap SystemCapability.Communication.NetStack
452     * @crossplatform
453     * @atomicservice
454     * @since 12
455     */
456    connect(url: string, callback: AsyncCallback<boolean>): void;
457
458    /**
459     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
460     * @permission ohos.permission.INTERNET
461     * @param { string } url URL for establishing a WebSocket connection.
462     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
463     * @param { AsyncCallback<boolean> } callback - the callback of connect.
464     * @throws { BusinessError } 401 - Parameter error.
465     * @throws { BusinessError } 201 - Permission denied.
466     * @syscap SystemCapability.Communication.NetStack
467     * @since 6
468     */
469    /**
470     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
471     * @permission ohos.permission.INTERNET
472     * @param { string } url URL for establishing a WebSocket connection.
473     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
474     * @param { AsyncCallback<boolean> } callback - the callback of connect.
475     * @throws { BusinessError } 401 - Parameter error.
476     * @throws { BusinessError } 201 - Permission denied.
477     * @throws { BusinessError } 2302999 - Internal error.
478     * @syscap SystemCapability.Communication.NetStack
479     * @crossplatform
480     * @since 10
481     */
482    /**
483     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
484     * @permission ohos.permission.INTERNET
485     * @param { string } url URL for establishing a WebSocket connection.
486     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
487     * @param { AsyncCallback<boolean> } callback - the callback of connect.
488     * @throws { BusinessError } 401 - Parameter error.
489     * @throws { BusinessError } 201 - Permission denied.
490     * @throws { BusinessError } 2302999 - Internal error.
491     * @syscap SystemCapability.Communication.NetStack
492     * @crossplatform
493     * @atomicservice
494     * @since 11
495     */
496    /**
497     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
498     * @permission ohos.permission.INTERNET
499     * @param { string } url URL for establishing a WebSocket connection.
500     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
501     * @param { AsyncCallback<boolean> } callback - the callback of connect.
502     * @throws { BusinessError } 401 - Parameter error.
503     * @throws { BusinessError } 201 - Permission denied.
504     * @throws { BusinessError } 2302001 - Websocket url error.
505     * @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
506     * @throws { BusinessError } 2302003 - Websocket connection already exists.
507     * @throws { BusinessError } 2302998 - It is not allowed to access this domain.
508     * @throws { BusinessError } 2302999 - Internal error.
509     * @syscap SystemCapability.Communication.NetStack
510     * @crossplatform
511     * @atomicservice
512     * @since 12
513     */
514    connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback<boolean>): void;
515
516    /**
517     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
518     * @permission ohos.permission.INTERNET
519     * @param { string } url URL for establishing a WebSocket connection.
520     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
521     * @returns { Promise<boolean> } The promise returned by the function.
522     * @throws { BusinessError } 401 - Parameter error.
523     * @throws { BusinessError } 201 - Permission denied.
524     * @syscap SystemCapability.Communication.NetStack
525     * @since 6
526     */
527    /**
528     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
529     * @permission ohos.permission.INTERNET
530     * @param { string } url URL for establishing a WebSocket connection.
531     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
532     * @returns { Promise<boolean> } The promise returned by the function.
533     * @throws { BusinessError } 401 - Parameter error.
534     * @throws { BusinessError } 201 - Permission denied.
535     * @throws { BusinessError } 2302999 - Internal error.
536     * @syscap SystemCapability.Communication.NetStack
537     * @crossplatform
538     * @since 10
539     */
540    /**
541     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
542     * @permission ohos.permission.INTERNET
543     * @param { string } url URL for establishing a WebSocket connection.
544     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
545     * @returns { Promise<boolean> } The promise returned by the function.
546     * @throws { BusinessError } 401 - Parameter error.
547     * @throws { BusinessError } 201 - Permission denied.
548     * @throws { BusinessError } 2302999 - Internal error.
549     * @syscap SystemCapability.Communication.NetStack
550     * @crossplatform
551     * @atomicservice
552     * @since 11
553     */
554    /**
555     * Initiates a WebSocket request to establish a WebSocket connection to a given URL.
556     * @permission ohos.permission.INTERNET
557     * @param { string } url URL for establishing a WebSocket connection.
558     * @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
559     * @returns { Promise<boolean> } The promise returned by the function.
560     * @throws { BusinessError } 401 - Parameter error.
561     * @throws { BusinessError } 201 - Permission denied.
562     * @throws { BusinessError } 2302001 - Websocket url error.
563     * @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
564     * @throws { BusinessError } 2302003 - Websocket connection already exists.
565     * @throws { BusinessError } 2302998 - It is not allowed to access this domain.
566     * @throws { BusinessError } 2302999 - Internal error.
567     * @syscap SystemCapability.Communication.NetStack
568     * @crossplatform
569     * @atomicservice
570     * @since 12
571     */
572    connect(url: string, options?: WebSocketRequestOptions): Promise<boolean>;
573
574    /**
575     * Sends data through a WebSocket connection.
576     * @permission ohos.permission.INTERNET
577     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
578     * @param { AsyncCallback<boolean> } callback - the callback of send.
579     * @throws { BusinessError } 401 - Parameter error.
580     * @throws { BusinessError } 201 - Permission denied.
581     * @syscap SystemCapability.Communication.NetStack
582     * @since 6
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     * @since 10
594     */
595    /**
596     * Sends data through a WebSocket connection.
597     * @permission ohos.permission.INTERNET
598     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
599     * @param { AsyncCallback<boolean> } callback - the callback of send.
600     * @throws { BusinessError } 401 - Parameter error.
601     * @throws { BusinessError } 201 - Permission denied.
602     * @syscap SystemCapability.Communication.NetStack
603     * @crossplatform
604     * @atomicservice
605     * @since 11
606     */
607    send(data: string | ArrayBuffer, callback: AsyncCallback<boolean>): void;
608
609    /**
610     * Sends data through a WebSocket connection.
611     * @permission ohos.permission.INTERNET
612     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
613     * @returns { Promise<boolean> } The promise returned by the function.
614     * @throws { BusinessError } 401 - Parameter error.
615     * @throws { BusinessError } 201 - Permission denied.
616     * @syscap SystemCapability.Communication.NetStack
617     * @since 6
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     * @since 10
629     */
630    /**
631     * Sends data through a WebSocket connection.
632     * @permission ohos.permission.INTERNET
633     * @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
634     * @returns { Promise<boolean> } The promise returned by the function.
635     * @throws { BusinessError } 401 - Parameter error.
636     * @throws { BusinessError } 201 - Permission denied.
637     * @syscap SystemCapability.Communication.NetStack
638     * @crossplatform
639     * @atomicservice
640     * @since 11
641     */
642    send(data: string | ArrayBuffer): Promise<boolean>;
643
644    /**
645     * Closes a WebSocket connection.
646     * @permission ohos.permission.INTERNET
647     * @param { AsyncCallback<boolean> } callback - the callback of close.
648     * @throws { BusinessError } 401 - Parameter error.
649     * @throws { BusinessError } 201 - Permission denied.
650     * @syscap SystemCapability.Communication.NetStack
651     * @since 6
652     */
653    /**
654     * Closes a WebSocket connection.
655     * @permission ohos.permission.INTERNET
656     * @param { AsyncCallback<boolean> } callback - the callback of close.
657     * @throws { BusinessError } 401 - Parameter error.
658     * @throws { BusinessError } 201 - Permission denied.
659     * @syscap SystemCapability.Communication.NetStack
660     * @crossplatform
661     * @since 10
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     * @crossplatform
671     * @atomicservice
672     * @since 11
673     */
674    close(callback: AsyncCallback<boolean>): void;
675
676    /**
677     * Closes a WebSocket connection.
678     * @permission ohos.permission.INTERNET
679     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
680     * @param { AsyncCallback<boolean> } callback - the callback of close.
681     * @throws { BusinessError } 401 - Parameter error.
682     * @throws { BusinessError } 201 - Permission denied.
683     * @syscap SystemCapability.Communication.NetStack
684     * @since 6
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     * @since 10
696     */
697    /**
698     * Closes a WebSocket connection.
699     * @permission ohos.permission.INTERNET
700     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
701     * @param { AsyncCallback<boolean> } callback - the callback of close.
702     * @throws { BusinessError } 401 - Parameter error.
703     * @throws { BusinessError } 201 - Permission denied.
704     * @syscap SystemCapability.Communication.NetStack
705     * @crossplatform
706     * @atomicservice
707     * @since 11
708     */
709    close(options: WebSocketCloseOptions, callback: AsyncCallback<boolean>): void;
710
711    /**
712     * Closes a WebSocket connection.
713     * @permission ohos.permission.INTERNET
714     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
715     * @returns { Promise<boolean> } The promise returned by the function.
716     * @throws { BusinessError } 401 - Parameter error.
717     * @throws { BusinessError } 201 - Permission denied.
718     * @syscap SystemCapability.Communication.NetStack
719     * @since 6
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     * @since 10
731     */
732    /**
733     * Closes a WebSocket connection.
734     * @permission ohos.permission.INTERNET
735     * @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
736     * @returns { Promise<boolean> } The promise returned by the function.
737     * @throws { BusinessError } 401 - Parameter error.
738     * @throws { BusinessError } 201 - Permission denied.
739     * @syscap SystemCapability.Communication.NetStack
740     * @crossplatform
741     * @atomicservice
742     * @since 11
743     */
744    close(options?: WebSocketCloseOptions): Promise<boolean>;
745
746    /**
747     * Enables listening for the open events of a WebSocket connection.
748     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
749     * @param { AsyncCallback<Object> } callback - the callback used to return the result.
750     * @syscap SystemCapability.Communication.NetStack
751     * @since 6
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     * @since 10
760     */
761    /**
762     * Enables 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     * @crossplatform
767     * @atomicservice
768     * @since 11
769     */
770    on(type: 'open', callback: AsyncCallback<Object>): void;
771
772    /**
773     * Cancels 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     * @since 6
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     * @since 10
786     */
787    /**
788     * Cancels listening for the open events of a WebSocket connection.
789     * @param { 'open' } type - event indicating that a WebSocket connection has been opened.
790     * @param { AsyncCallback<Object> } callback the callback used to return the result.
791     * @syscap SystemCapability.Communication.NetStack
792     * @crossplatform
793     * @atomicservice
794     * @since 11
795     */
796    off(type: 'open', callback?: AsyncCallback<Object>): void;
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     * @since 6
805     */
806    /**
807     * Enables listening for the message events of a WebSocket connection.
808     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
809     * @param { 'message' } type - event indicating that a message has been received from the server.
810     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
811     * @syscap SystemCapability.Communication.NetStack
812     * @crossplatform
813     * @since 10
814     */
815    /**
816     * Enables listening for the message events of a WebSocket connection.
817     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
818     * @param { 'message' } type - event indicating that a message has been received from the server.
819     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
820     * @syscap SystemCapability.Communication.NetStack
821     * @crossplatform
822     * @atomicservice
823     * @since 11
824     */
825    on(type: 'message', callback: AsyncCallback<string | ArrayBuffer>): void;
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     * @since 6
834     */
835    /**
836     * Cancels listening for the message events of a WebSocket connection.
837     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
838     * @param { 'message' } type - event indicating that a message has been received from the server.
839     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
840     * @syscap SystemCapability.Communication.NetStack
841     * @crossplatform
842     * @since 10
843     */
844    /**
845     * Cancels listening for the message events of a WebSocket connection.
846     * data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
847     * @param { 'message' } type - event indicating that a message has been received from the server.
848     * @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
849     * @syscap SystemCapability.Communication.NetStack
850     * @crossplatform
851     * @atomicservice
852     * @since 11
853     */
854    off(type: 'message', callback?: AsyncCallback<string | ArrayBuffer>): void;
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     * @since 6
863     */
864    /**
865     * Enables listening for the close events of a WebSocket connection.
866     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
867     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
868     * <br>close indicates the close error code and reason indicates the error code description.
869     * @syscap SystemCapability.Communication.NetStack
870     * @crossplatform
871     * @since 10
872     */
873    /**
874     * Enables listening for the close events of a WebSocket connection.
875     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
876     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
877     * <br>close indicates the close error code and reason indicates the error code description.
878     * @syscap SystemCapability.Communication.NetStack
879     * @crossplatform
880     * @atomicservice
881     * @since 11
882     */
883    on(type: 'close', callback: AsyncCallback<CloseResult>): void;
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     * @since 6
892     */
893    /**
894     * Cancels listening for the close events of a WebSocket connection.
895     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
896     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
897     * <br>close indicates the close error code and reason indicates the error code description.
898     * @syscap SystemCapability.Communication.NetStack
899     * @crossplatform
900     * @since 10
901     */
902    /**
903     * Cancels listening for the close events of a WebSocket connection.
904     * @param { 'close' } type - event indicating that a WebSocket connection has been closed.
905     * @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
906     * <br>close indicates the close error code and reason indicates the error code description.
907     * @syscap SystemCapability.Communication.NetStack
908     * @crossplatform
909     * @atomicservice
910     * @since 11
911     */
912    off(type: 'close', callback?: AsyncCallback<CloseResult>): void;
913
914    /**
915     * Enables listening for the error events of a WebSocket connection.
916     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
917     * @param { ErrorCallback } callback - the callback used to return the result.
918     * @syscap SystemCapability.Communication.NetStack
919     * @since 6
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     * @since 10
928     */
929    /**
930     * Enables 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     * @crossplatform
935     * @atomicservice
936     * @since 11
937     */
938    on(type: 'error', callback: ErrorCallback): void;
939
940    /**
941     * Cancels 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     * @since 6
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     * @since 10
954     */
955    /**
956     * Cancels listening for the error events of a WebSocket connection.
957     * @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
958     * @param { ErrorCallback } callback - the callback used to return the result.
959     * @syscap SystemCapability.Communication.NetStack
960     * @crossplatform
961     * @atomicservice
962     * @since 11
963     */
964    off(type: 'error', callback?: ErrorCallback): void;
965
966    /**
967     * Enables listening for receiving data ends events of a WebSocket connection.
968     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
969     * @param { Callback<void> } callback - the callback used to return the result.
970     * @syscap SystemCapability.Communication.NetStack
971     * @since 11
972     */
973    /**
974     * Enables listening for receiving data ends events of a WebSocket connection.
975     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
976     * @param { Callback<void> } callback - the callback used to return the result.
977     * @syscap SystemCapability.Communication.NetStack
978     * @crossplatform
979     * @since 12
980     */
981    on(type: 'dataEnd', callback: Callback<void>): void;
982
983    /**
984     * Cancels listening for receiving data ends events of a WebSocket connection.
985     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
986     * @param { Callback<void> } [ callback ] - the callback used to return the result.
987     * @syscap SystemCapability.Communication.NetStack
988     * @since 11
989     */
990    /**
991     * Cancels listening for receiving data ends events of a WebSocket connection.
992     * @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
993     * @param { Callback<void> } [ callback ] - the callback used to return the result.
994     * @syscap SystemCapability.Communication.NetStack
995     * @crossplatform
996     * @since 12
997     */
998    off(type: 'dataEnd', callback?: Callback<void>): void;
999
1000    /**
1001     * Registers an observer for HTTP Response Header events.
1002     * @param { 'headerReceive'} type - Indicates Event name.
1003     * @param { Callback<ResponseHeaders> } callback - the callback used to return the result.
1004     * @syscap SystemCapability.Communication.NetStack
1005     * @since 12
1006     */
1007    on(type: 'headerReceive', callback: Callback<ResponseHeaders>): void;
1008
1009    /**
1010     * Unregisters the observer for HTTP Response Header events.
1011     * @param { 'headerReceive' } type - Indicates Event name.
1012     * @param { Callback<ResponseHeaders> } [callback] - the callback used to return the result.
1013     * @syscap SystemCapability.Communication.NetStack
1014     * @since 12
1015     */
1016    off(type: 'headerReceive', callback?: Callback<ResponseHeaders>): void;
1017  }
1018
1019  /**
1020   * Creates a web socket Server.
1021   * @returns { WebSocketServer } the WebSocketServer Object.
1022   * @syscap SystemCapability.Communication.NetStack
1023   * @since 19
1024   */
1025  function createWebSocketServer(): WebSocketServer;
1026
1027  /**
1028   * Defines parameters for a WebSocket Server.
1029   * @interface WebSocketServerConfig
1030   * @syscap SystemCapability.Communication.NetStack
1031   * @since 19
1032   */
1033  export interface WebSocketServerConfig {
1034    /**
1035     * Network card that the server listens on.
1036     * The server listens on this specific address. It's 0.0.0.0 by default.
1037     * @type {?string}
1038     * @syscap SystemCapability.Communication.NetStack
1039     * @since 19
1040     */
1041    serverIP?: string;
1042
1043    /**
1044     * Port number that the server listens on.
1045     * @type {number}
1046     * @syscap SystemCapability.Communication.NetStack
1047     * @since 19
1048     */
1049    serverPort: number;
1050
1051    /**
1052     * Server cert.
1053     * @type {?ServerCert}
1054     * @syscap SystemCapability.Communication.NetStack
1055     * @since 19
1056     */
1057    serverCert?: ServerCert;
1058
1059    /**
1060     * Maximum number of concurrent clients. When it's reached, the server will reject new connections.
1061     * @type { number }
1062     * @syscap SystemCapability.Communication.NetStack
1063     * @since 19
1064     */
1065    maxConcurrentClientsNumber: number;
1066
1067    /**
1068     * Self defined protocol.
1069     * @type {?string}
1070     * @syscap SystemCapability.Communication.NetStack
1071     * @since 19
1072     */
1073    protocol?: string;
1074
1075    /**
1076     * Maximum number of one client's connections. When it's reached, the server will reject new connections.
1077     * @type {number}
1078     * @syscap SystemCapability.Communication.NetStack
1079     * @since 19
1080     */
1081    maxConnectionsForOneClient: number;
1082  }
1083
1084  /**
1085   * The serverCert field of the server certificate, which includes two attributes:
1086   * File paths of server certificate (certPath) and certificate private key (keyPath). Only support PEM format.
1087   * @interface ServerCert
1088   * @syscap SystemCapability.Communication.NetStack
1089   * @since 19
1090   */
1091  export interface ServerCert {
1092    /**
1093     * File path for the server cert.
1094     * @type {string}
1095     * @syscap SystemCapability.Communication.NetStack
1096     * @since 19
1097     */
1098    certPath: string;
1099
1100    /**
1101     * The path of the server certificate private key file.
1102     * @type {string}
1103     * @syscap SystemCapability.Communication.NetStack
1104     * @since 19
1105     */
1106    keyPath: string;
1107  }
1108
1109  /**
1110   * Info about the connection from each specific client.
1111   * @interface WebSocketConnection
1112   * @syscap SystemCapability.Communication.NetStack
1113   * @since 19
1114   */
1115  export interface WebSocketConnection {
1116    /**
1117     * IP address of the client.
1118     * @type {string}
1119     * @syscap SystemCapability.Communication.NetStack
1120     * @since 19
1121     */
1122    clientIP: string;
1123
1124    /**
1125     * Port of the client.
1126     * @type {number}
1127     * @syscap SystemCapability.Communication.NetStack
1128     * @since 19
1129     */
1130    clientPort: number;
1131  }
1132
1133  /**
1134   * Info about the message received from a specific client.
1135   * @interface WebSocketMessage
1136   * @syscap SystemCapability.Communication.NetStack
1137   * @since 19
1138   */
1139  export interface WebSocketMessage {
1140    /**
1141     * Contend of the message.
1142     * @type {string | ArrayBuffer}
1143     * @syscap SystemCapability.Communication.NetStack
1144     * @since 19
1145     */
1146    data: string | ArrayBuffer;
1147
1148    /**
1149     * The connection where the message comes from.
1150     * @type {WebSocketConnection}
1151     * @syscap SystemCapability.Communication.NetStack
1152     * @since 19
1153     */
1154    clientConnection: WebSocketConnection;
1155  }
1156
1157  /**
1158   * Callback function when a client connection is closed.
1159   * @typedef { function } ClientConnectionCloseCallback
1160   * @param { WebSocketConnection } clientConnection - the connection which is closed.
1161   * @param { CloseResult } closeReason - the error code and reason why the connection is closed.
1162   * @syscap SystemCapability.Communication.NetStack
1163   * @since 19
1164   */
1165  export type ClientConnectionCloseCallback = (clientConnection: WebSocketConnection, closeReason: CloseResult) => void;
1166
1167  /**
1168   * <p>Defines a WebSocketServer object. Before invoking WebSocketServer APIs,
1169   * you need to call webSocketServer.createWebSocketServer to create a WebSocket Server.</p>
1170   * @interface WebSocketServer
1171   * @syscap SystemCapability.Communication.NetStack
1172   * @since 19
1173   */
1174  export interface WebSocketServer {
1175    /**
1176     * Start the WebSocket Server, and listen to a given port.
1177     * @permission ohos.permission.INTERNET
1178     * @param { WebSocketServerConfig } config - setting for the server, such as ip address and port to listen to.
1179     * @returns { Promise<boolean> } Indicating whether the server starts sucessfully.
1180     * @throws { BusinessError } 201 - Permission denied.
1181     * @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
1182     * @throws { BusinessError } 2302004 - Can't listen on the given NIC.
1183     * @throws { BusinessError } 2302005 - Can't listen on the given Port.
1184     * @throws { BusinessError } 2302999 - Websocket other unknown error.
1185     * @syscap SystemCapability.Communication.NetStack
1186     * @since 19
1187     */
1188    start(config: WebSocketServerConfig): Promise<boolean>;
1189
1190    /**
1191     * List all alive connections.
1192     * @permission ohos.permission.INTERNET
1193     * @returns { WebSocketConnection[] } an array consists connections from all clients.
1194     * @throws { BusinessError } 201 - Permission denied.
1195     * @syscap SystemCapability.Communication.NetStack
1196     * @since 19
1197     */
1198    listAllConnections(): WebSocketConnection[];
1199
1200    /**
1201     * Close a given WebSocket connection.
1202     * @permission ohos.permission.INTERNET
1203     * @param { WebSocketConnection } connection - which on to be closed.
1204     * @param { webSocket.WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
1205     * @returns { Promise<boolean> } Indicating whether the connection is closed sucessfully.
1206     * @throws { BusinessError } 201 - Permission denied.
1207     * @throws { BusinessError } 2302006 - websocket connection does not exist.
1208     * @syscap SystemCapability.Communication.NetStack
1209     * @since 19
1210     */
1211    close(connection: WebSocketConnection, options?: webSocket.WebSocketCloseOptions): Promise<boolean>;
1212
1213    /**
1214     * Send a message using a specific connection.
1215     * @permission ohos.permission.INTERNET
1216     * @param { string | ArrayBuffer } data - What to send. It can be a string or an ArrayBuffer.
1217     * @param { WebSocketConnection } connection - Where to sent.
1218     * @returns { Promise<boolean> } Indicating whether the message is sent sucessfully.
1219     * @throws { BusinessError } 201 - Permission denied.
1220     * @throws { BusinessError } 2302006 - websocket connection does not exist.
1221     * @syscap SystemCapability.Communication.NetStack
1222     * @since 19
1223     */
1224    send(data: string | ArrayBuffer, connection: WebSocketConnection): Promise<boolean>;
1225
1226     /**
1227      * Stop listening.
1228      * @permission ohos.permission.INTERNET
1229      * @returns { Promise<boolean> } The Indicating whether the server stops sucessfully.
1230      * @throws { BusinessError } 201 - Permission denied.
1231      * @syscap SystemCapability.Communication.NetStack
1232      * @since 19
1233      */
1234    stop(): Promise<boolean>;
1235
1236    /**
1237     * Enables listening for the error events of a WebSocket Server.
1238     * @param { 'error' } type - event indicating that the WebSocket Server has encountered an error.
1239     * @param { ErrorCallback } callback - the callback used to return the result.
1240     * @syscap SystemCapability.Communication.NetStack
1241     * @since 19
1242     */
1243    on(type: 'error', callback: ErrorCallback): void;
1244
1245    /**
1246     * Enables listening for events that a client requested to connect the server.
1247     * @param { 'connect' } type - event indicating that a client requested to connect the server.
1248     * @param { Callback<WebSocketConnection> } callback - the callback used to return the result.
1249     * @syscap SystemCapability.Communication.NetStack
1250     * @since 19
1251     */
1252     on(type: 'connect', callback: Callback<WebSocketConnection>): void;
1253
1254     /**
1255      * Enables listening for events that the server received a message.
1256      * @param { 'messageReceive' } type - event indicating that the server received a message.
1257      * @param { Callback<WebSocketMessage> } callback - the callback used to return the result.
1258      * @syscap SystemCapability.Communication.NetStack
1259      * @since 19
1260      */
1261     on(type: 'messageReceive', callback: Callback<WebSocketMessage>): void;
1262
1263     /**
1264      * Enables listening for events that a connection from a given client has been closed.
1265      * @param { 'close' } type - event indicating that a connection from a given client has been closed.
1266      * @param { ClientConnectionCloseCallback } callback - the callback function when a client connection is closed.
1267      * @syscap SystemCapability.Communication.NetStack
1268      * @since 19
1269      */
1270     on(type: 'close', callback: ClientConnectionCloseCallback): void;
1271
1272    /**
1273     * Cancels listening for the error events of a WebSocket Server.
1274     * @param { 'error' } type - event indicating that the WebSocket Server has encountered an error.
1275     * @param { ErrorCallback } callback - the callback used to return the result.
1276     * @syscap SystemCapability.Communication.NetStack
1277     * @since 19
1278     */
1279    off(type: 'error', callback?: ErrorCallback): void;
1280
1281    /**
1282     * Cancels listening for events that a client requested to connect the server.
1283     * @param { 'connect' } type - event indicating that a client requested to connect the server.
1284     * @param { Callback<WebSocketConnection> } callback - the callback used to return the result.
1285     * @syscap SystemCapability.Communication.NetStack
1286     * @since 19
1287     */
1288    off(type: 'connect', callback?: Callback<WebSocketConnection>): void;
1289
1290    /**
1291     * Cancels listening for events that a connection from a given client has been closed.
1292     * @param { 'close' } type - event indicating that a connection from a given client has been closed.
1293     * @param { ClientConnectionCloseCallback } callback - the callback used to return the result.
1294     * @syscap SystemCapability.Communication.NetStack
1295     * @since 19
1296     */
1297    off(type: 'close', callback?: ClientConnectionCloseCallback): void;
1298
1299    /**
1300     * Cancels listening for events that the server received a message.
1301     * @param { 'messageReceive' } type - event indicating that the server received a message.
1302     * @param { Callback<WebSocketMessage> } callback - the callback used to return the result.
1303     * @syscap SystemCapability.Communication.NetStack
1304     * @since 19
1305     */
1306    off(type: 'messageReceive', callback?: Callback<WebSocketMessage>): void;
1307  }
1308}
1309
1310export default webSocket;