1 Star 0 Fork 3.9K

Feng Lin/interface_sdk-js

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
@ohos.net.webSocket.d.ts 39.50 KB
一键复制 编辑 原始数据 按行查看 历史
wangmengyao111 提交于 2024-08-08 16:02 +08:00 . TicketNo:DTS2024072514101
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @file
* @kit NetworkKit
*/
import type { AsyncCallback, ErrorCallback, Callback } from './@ohos.base';
import type connection from './@ohos.net.connection';
/**
* Provides WebSocket APIs.
* @namespace webSocket
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Provides WebSocket APIs.
* @namespace webSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Provides WebSocket APIs.
* @namespace webSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
declare namespace webSocket {
/**
* @typedef { connection.HttpProxy }
* @syscap SystemCapability.Communication.NetManager.Core
* @since 12
*/
type HttpProxy = connection.HttpProxy;
/**
* Creates a web socket connection.
* @returns { WebSocket } the WebSocket of the createWebSocket.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Creates a web socket connection.
* @returns { WebSocket } the WebSocket of the createWebSocket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Creates a web socket connection.
* @returns { WebSocket } the WebSocket of the createWebSocket.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
function createWebSocket(): WebSocket;
/**
* Defines the optional parameters carried in the request for establishing a WebSocket connection.
* @interface WebSocketRequestOptions
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Defines the optional parameters carried in the request for establishing a WebSocket connection.
* @interface WebSocketRequestOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Defines the optional parameters carried in the request for establishing a WebSocket connection.
* @interface WebSocketRequestOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
export interface WebSocketRequestOptions {
/**
* HTTP request header.
* @type {?Object}
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* HTTP request header.
* @type {?Object}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* HTTP request header.
* @type {?Object}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
header?: Object;
/**
* File path for client cert.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* File path for client cert.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
caPath?: string;
/**
* Client cert.
* @type {?ClientCert}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Client cert.
* @type {?ClientCert}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
clientCert?: ClientCert;
/**
* HTTP proxy configuration. Use 'system' if this filed is not set.
* @type {?ProxyConfiguration}
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
proxy?: ProxyConfiguration;
/**
* Self defined protocol.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
protocol?: string;
}
/**
* HTTP proxy configuration.
* system: means that use system proxy configuration.
* no-proxy: means do not use proxy.
* object of @type {connection.HttpProxy} means providing custom proxy settings
* @typedef { 'system' | 'no-proxy' | HttpProxy }
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
export type ProxyConfiguration = 'system' | 'no-proxy' | HttpProxy;
/**
* The clientCert field of the client certificate, which includes three attributes:
* client certificate (certPath) and only support PEM format, certificate private key (keyPath),
* and passphrase (keyPassword).
* @interface ClientCert
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* The clientCert field of the client certificate, which includes three attributes:
* client certificate (certPath) and only support PEM format, certificate private key (keyPath),
* and passphrase (keyPassword).
* @interface ClientCert
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
export interface ClientCert {
/**
* The path to the client certificate file.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* The path to the client certificate file.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
certPath: string;
/**
* The path of the client certificate private key file.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* The path of the client certificate private key file.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
keyPath: string;
/**
* Client certificate password.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Client certificate password.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
keyPassword?: string;
}
/**
* Defines the optional parameters carried in the request for closing a WebSocket connection.
* @interface WebSocketCloseOptions
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Defines the optional parameters carried in the request for closing a WebSocket connection.
* @interface WebSocketCloseOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Defines the optional parameters carried in the request for closing a WebSocket connection.
* @interface WebSocketCloseOptions
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
export interface WebSocketCloseOptions {
/**
* Error code.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Error code.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Error code.
* @type {?number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
code?: number;
/**
* Error cause.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Error cause.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Error cause.
* @type {?string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
reason?: string;
}
/**
* The result for closing a WebSocket connection.
* @interface CloseResult
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* The result for closing a WebSocket connection.
* @interface CloseResult
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
export interface CloseResult {
/**
* Error code.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Error code.
* @type {number}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
code: number;
/**
* Error cause.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Error cause.
* @type {string}
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
reason: string;
}
/**
* HTTP response headers.
* @typedef { object }
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
export type ResponseHeaders = {
[k: string]: string | string[] | undefined;
}
/**
* <p>Defines a WebSocket object. Before invoking WebSocket APIs,
* you need to call webSocket.createWebSocket to create a WebSocket object.</p>
* @interface WebSocket
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* <p>Defines a WebSocket object. Before invoking WebSocket APIs,
* you need to call webSocket.createWebSocket to create a WebSocket object.</p>
* @interface WebSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* <p>Defines a WebSocket object. Before invoking WebSocket APIs,
* you need to call webSocket.createWebSocket to create a WebSocket object.</p>
* @interface WebSocket
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
export interface WebSocket {
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url - URL for establishing a WebSocket connection.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302001 - Websocket url error.
* @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
* @throws { BusinessError } 2302003 - Websocket connection already exists.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 12
*/
connect(url: string, callback: AsyncCallback<boolean>): void;
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of connect.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302001 - Websocket url error.
* @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
* @throws { BusinessError } 2302003 - Websocket connection already exists.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 12
*/
connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback<boolean>): void;
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
/**
* Initiates a WebSocket request to establish a WebSocket connection to a given URL.
* @permission ohos.permission.INTERNET
* @param { string } url URL for establishing a WebSocket connection.
* @param { WebSocketRequestOptions } options - Optional parameters {@link WebSocketRequestOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @throws { BusinessError } 2302001 - Websocket url error.
* @throws { BusinessError } 2302002 - Websocket certificate file does not exist.
* @throws { BusinessError } 2302003 - Websocket connection already exists.
* @throws { BusinessError } 2302999 - Websocket other unknown error.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 12
*/
connect(url: string, options?: WebSocketRequestOptions): Promise<boolean>;
/**
* Sends data through a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
* @param { AsyncCallback<boolean> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Sends data through a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
* @param { AsyncCallback<boolean> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Sends data through a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
* @param { AsyncCallback<boolean> } callback - the callback of send.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
send(data: string | ArrayBuffer, callback: AsyncCallback<boolean>): void;
/**
* Sends data through a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Sends data through a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Sends data through a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { string | ArrayBuffer } data - Data to send. It can be a string(API 6) or an ArrayBuffer(API 8).
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
send(data: string | ArrayBuffer): Promise<boolean>;
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<boolean> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<boolean> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { AsyncCallback<boolean> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
close(callback: AsyncCallback<boolean>): void;
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
* @param { AsyncCallback<boolean> } callback - the callback of close.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
close(options: WebSocketCloseOptions, callback: AsyncCallback<boolean>): void;
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Closes a WebSocket connection.
* @permission ohos.permission.INTERNET
* @param { WebSocketCloseOptions } options - Optional parameters {@link WebSocketCloseOptions}.
* @returns { Promise<boolean> } The promise returned by the function.
* @throws { BusinessError } 401 - Parameter error.
* @throws { BusinessError } 201 - Permission denied.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
close(options?: WebSocketCloseOptions): Promise<boolean>;
/**
* Enables listening for the open events of a WebSocket connection.
* @param { 'open' } type - event indicating that a WebSocket connection has been opened.
* @param { AsyncCallback<Object> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Enables listening for the open events of a WebSocket connection.
* @param { 'open' } type - event indicating that a WebSocket connection has been opened.
* @param { AsyncCallback<Object> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Enables listening for the open events of a WebSocket connection.
* @param { 'open' } type - event indicating that a WebSocket connection has been opened.
* @param { AsyncCallback<Object> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
on(type: 'open', callback: AsyncCallback<Object>): void;
/**
* Cancels listening for the open events of a WebSocket connection.
* @param { 'open' } type - event indicating that a WebSocket connection has been opened.
* @param { AsyncCallback<Object> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Cancels listening for the open events of a WebSocket connection.
* @param { 'open' } type - event indicating that a WebSocket connection has been opened.
* @param { AsyncCallback<Object> } callback the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for the open events of a WebSocket connection.
* @param { 'open' } type - event indicating that a WebSocket connection has been opened.
* @param { AsyncCallback<Object> } callback the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
off(type: 'open', callback?: AsyncCallback<Object>): void;
/**
* Enables listening for the message events of a WebSocket connection.
* data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
* @param { 'message' } type - event indicating that a message has been received from the server.
* @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Enables listening for the message events of a WebSocket connection.
* data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
* @param { 'message' } type - event indicating that a message has been received from the server.
* @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Enables listening for the message events of a WebSocket connection.
* data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
* @param { 'message' } type - event indicating that a message has been received from the server.
* @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
on(type: 'message', callback: AsyncCallback<string | ArrayBuffer>): void;
/**
* Cancels listening for the message events of a WebSocket connection.
* data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
* @param { 'message' } type - event indicating that a message has been received from the server.
* @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Cancels listening for the message events of a WebSocket connection.
* data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
* @param { 'message' } type - event indicating that a message has been received from the server.
* @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for the message events of a WebSocket connection.
* data in AsyncCallback can be a string(API 6) or an ArrayBuffer(API 8).
* @param { 'message' } type - event indicating that a message has been received from the server.
* @param { AsyncCallback<string | ArrayBuffer> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
off(type: 'message', callback?: AsyncCallback<string | ArrayBuffer>): void;
/**
* Enables listening for the close events of a WebSocket connection.
* @param { 'close' } type - event indicating that a WebSocket connection has been closed.
* @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
* <br>close indicates the close error code and reason indicates the error code description.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Enables listening for the close events of a WebSocket connection.
* @param { 'close' } type - event indicating that a WebSocket connection has been closed.
* @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
* <br>close indicates the close error code and reason indicates the error code description.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Enables listening for the close events of a WebSocket connection.
* @param { 'close' } type - event indicating that a WebSocket connection has been closed.
* @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
* <br>close indicates the close error code and reason indicates the error code description.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
on(type: 'close', callback: AsyncCallback<CloseResult>): void;
/**
* Cancels listening for the close events of a WebSocket connection.
* @param { 'close' } type - event indicating that a WebSocket connection has been closed.
* @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
* <br>close indicates the close error code and reason indicates the error code description.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Cancels listening for the close events of a WebSocket connection.
* @param { 'close' } type - event indicating that a WebSocket connection has been closed.
* @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
* <br>close indicates the close error code and reason indicates the error code description.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for the close events of a WebSocket connection.
* @param { 'close' } type - event indicating that a WebSocket connection has been closed.
* @param { AsyncCallback<CloseResult> } callback - the callback used to return the result.
* <br>close indicates the close error code and reason indicates the error code description.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
off(type: 'close', callback?: AsyncCallback<CloseResult>): void;
/**
* Enables listening for the error events of a WebSocket connection.
* @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Enables listening for the error events of a WebSocket connection.
* @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Enables listening for the error events of a WebSocket connection.
* @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
on(type: 'error', callback: ErrorCallback): void;
/**
* Cancels listening for the error events of a WebSocket connection.
* @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 6
*/
/**
* Cancels listening for the error events of a WebSocket connection.
* @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 10
*/
/**
* Cancels listening for the error events of a WebSocket connection.
* @param { 'error' } type - event indicating the WebSocket connection has encountered an error.
* @param { ErrorCallback } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @atomicservice
* @since 11
*/
off(type: 'error', callback?: ErrorCallback): void;
/**
* Enables listening for receiving data ends events of a WebSocket connection.
* @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Enables listening for receiving data ends events of a WebSocket connection.
* @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
* @param { Callback<void> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
on(type: 'dataEnd', callback: Callback<void>): void;
/**
* Cancels listening for receiving data ends events of a WebSocket connection.
* @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
* @param { Callback<void> } [ callback ] - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 11
*/
/**
* Cancels listening for receiving data ends events of a WebSocket connection.
* @param { 'dataEnd' } type - event indicating the WebSocket connection has received data ends.
* @param { Callback<void> } [ callback ] - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @crossplatform
* @since 12
*/
off(type: 'dataEnd', callback?: Callback<void>): void;
/**
* Registers an observer for HTTP Response Header events.
* @param { 'headerReceive'} type - Indicates Event name.
* @param { Callback<ResponseHeaders> } callback - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
on(type: 'headerReceive', callback: Callback<ResponseHeaders>): void;
/**
* Unregisters the observer for HTTP Response Header events.
* @param { 'headerReceive' } type - Indicates Event name.
* @param { Callback<ResponseHeaders> } [callback] - the callback used to return the result.
* @syscap SystemCapability.Communication.NetStack
* @since 12
*/
off(type: 'headerReceive', callback?: Callback<ResponseHeaders>): void;
}
}
export default webSocket;
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lffl8796/interface_sdk-js.git
git@gitee.com:lffl8796/interface_sdk-js.git
lffl8796
interface_sdk-js
interface_sdk-js
master

搜索帮助