From c759f9a03ca1b3d6f33b8e4007c7bdb2ea113727 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 2 Aug 2025 16:53:28 +0800 Subject: [PATCH] support websocket ani Issue:https://gitee.com/openharmony/interface_sdk-js/issues/ICQLIV Signed-off-by: leo9001 --- api/@ohos.net.webSocket.d.ts | 173 ++++++++++++++++++++++------------- 1 file changed, 109 insertions(+), 64 deletions(-) diff --git a/api/@ohos.net.webSocket.d.ts b/api/@ohos.net.webSocket.d.ts index e582a5f2ed..e38e1e3bb3 100644 --- a/api/@ohos.net.webSocket.d.ts +++ b/api/@ohos.net.webSocket.d.ts @@ -382,7 +382,8 @@ declare namespace webSocket { * HTTP response headers. * @typedef { object } * @syscap SystemCapability.Communication.NetStack - * @since 12 + * @since arkts {'1.1':'12','1.2':'20'} + * @arkts 1.1&1.2 */ export type ResponseHeaders = { [k: string]: string | string[] | undefined; @@ -786,7 +787,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'open', callback: AsyncCallback): void; @@ -812,7 +814,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'open', callback?: AsyncCallback): void; @@ -841,7 +844,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'message', callback: AsyncCallback): void; @@ -870,7 +874,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'message', callback?: AsyncCallback): void; @@ -899,7 +904,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'close', callback: AsyncCallback): void; @@ -928,7 +934,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'close', callback?: AsyncCallback): void; @@ -954,7 +961,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'error', callback: ErrorCallback): void; @@ -980,7 +988,8 @@ declare namespace webSocket { * @syscap SystemCapability.Communication.NetStack * @crossplatform * @atomicservice - * @since 11 + * @since arkts {'1.1':'11','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'error', callback?: ErrorCallback): void; @@ -997,7 +1006,8 @@ declare namespace webSocket { * @param { Callback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack * @crossplatform - * @since 12 + * @since arkts {'1.1':'12','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'dataEnd', callback: Callback): void; @@ -1014,7 +1024,8 @@ declare namespace webSocket { * @param { Callback } [ callback ] - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack * @crossplatform - * @since 12 + * @since arkts {'1.1':'12','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'dataEnd', callback?: Callback): void; @@ -1023,7 +1034,8 @@ declare namespace webSocket { * @param { 'headerReceive'} type - Indicates Event name. * @param { Callback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 12 + * @since arkts {'1.1':'12','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'headerReceive', callback: Callback): void; @@ -1032,7 +1044,8 @@ declare namespace webSocket { * @param { 'headerReceive' } type - Indicates Event name. * @param { Callback } [callback] - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 12 + * @since arkts {'1.1':'12','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'headerReceive', callback?: Callback): void; } @@ -1041,7 +1054,8 @@ declare namespace webSocket { * Creates a web socket Server. * @returns { WebSocketServer } the WebSocketServer Object. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ function createWebSocketServer(): WebSocketServer; @@ -1049,7 +1063,8 @@ declare namespace webSocket { * Defines parameters for a WebSocket Server. * @interface WebSocketServerConfig * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ export interface WebSocketServerConfig { /** @@ -1057,7 +1072,8 @@ declare namespace webSocket { * The server listens on this specific address. It's 0.0.0.0 by default. * @type {?string} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ serverIP?: string; @@ -1065,7 +1081,8 @@ declare namespace webSocket { * Port number that the server listens on. * @type {number} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ serverPort: number; @@ -1073,7 +1090,8 @@ declare namespace webSocket { * Server cert. * @type {?ServerCert} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ serverCert?: ServerCert; @@ -1081,7 +1099,8 @@ declare namespace webSocket { * Maximum number of concurrent clients. When it's reached, the server will reject new connections. * @type { number } * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ maxConcurrentClientsNumber: number; @@ -1089,7 +1108,8 @@ declare namespace webSocket { * Self defined protocol. * @type {?string} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ protocol?: string; @@ -1097,7 +1117,8 @@ declare namespace webSocket { * Maximum number of one client's connections. When it's reached, the server will reject new connections. * @type {number} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ maxConnectionsForOneClient: number; } @@ -1107,14 +1128,16 @@ declare namespace webSocket { * File paths of server certificate (certPath) and certificate private key (keyPath). Only support PEM format. * @interface ServerCert * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ export interface ServerCert { /** * File path for the server cert. * @type {string} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ certPath: string; @@ -1122,7 +1145,8 @@ declare namespace webSocket { * The path of the server certificate private key file. * @type {string} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ keyPath: string; } @@ -1131,14 +1155,16 @@ declare namespace webSocket { * Info about the connection from each specific client. * @interface WebSocketConnection * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ export interface WebSocketConnection { /** * IP address of the client. * @type {string} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ clientIP: string; @@ -1146,7 +1172,8 @@ declare namespace webSocket { * Port of the client. * @type {number} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ clientPort: number; } @@ -1155,14 +1182,16 @@ declare namespace webSocket { * Info about the message received from a specific client. * @interface WebSocketMessage * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ export interface WebSocketMessage { /** * Contend of the message. * @type {string | ArrayBuffer} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ data: string | ArrayBuffer; @@ -1170,7 +1199,8 @@ declare namespace webSocket { * The connection where the message comes from. * @type {WebSocketConnection} * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ clientConnection: WebSocketConnection; } @@ -1181,7 +1211,8 @@ declare namespace webSocket { * @param { WebSocketConnection } clientConnection - the connection which is closed. * @param { CloseResult } closeReason - the error code and reason why the connection is closed. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ export type ClientConnectionCloseCallback = (clientConnection: WebSocketConnection, closeReason: CloseResult) => void; @@ -1190,7 +1221,8 @@ declare namespace webSocket { * you need to call webSocketServer.createWebSocketServer to create a WebSocket Server.

* @interface WebSocketServer * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ export interface WebSocketServer { /** @@ -1204,7 +1236,8 @@ declare namespace webSocket { * @throws { BusinessError } 2302005 - Can't listen on the given Port. * @throws { BusinessError } 2302999 - Websocket other unknown error. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ start(config: WebSocketServerConfig): Promise; @@ -1214,7 +1247,8 @@ declare namespace webSocket { * @returns { WebSocketConnection[] } an array consists connections from all clients. * @throws { BusinessError } 201 - Permission denied. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ listAllConnections(): WebSocketConnection[]; @@ -1227,7 +1261,8 @@ declare namespace webSocket { * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 2302006 - websocket connection does not exist. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ close(connection: WebSocketConnection, options?: webSocket.WebSocketCloseOptions): Promise; @@ -1240,18 +1275,20 @@ declare namespace webSocket { * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 2302006 - websocket connection does not exist. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ send(data: string | ArrayBuffer, connection: WebSocketConnection): Promise; - /** - * Stop listening. - * @permission ohos.permission.INTERNET - * @returns { Promise } The Indicating whether the server stops sucessfully. - * @throws { BusinessError } 201 - Permission denied. - * @syscap SystemCapability.Communication.NetStack - * @since 19 - */ + /** + * Stop listening. + * @permission ohos.permission.INTERNET + * @returns { Promise } The Indicating whether the server stops sucessfully. + * @throws { BusinessError } 201 - Permission denied. + * @syscap SystemCapability.Communication.NetStack + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 + */ stop(): Promise; /** @@ -1259,7 +1296,8 @@ declare namespace webSocket { * @param { 'error' } type - event indicating that the WebSocket Server has encountered an error. * @param { ErrorCallback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'error', callback: ErrorCallback): void; @@ -1268,26 +1306,29 @@ declare namespace webSocket { * @param { 'connect' } type - event indicating that a client requested to connect the server. * @param { Callback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ on(type: 'connect', callback: Callback): void; - /** - * Enables listening for events that the server received a message. - * @param { 'messageReceive' } type - event indicating that the server received a message. - * @param { Callback } callback - the callback used to return the result. - * @syscap SystemCapability.Communication.NetStack - * @since 19 - */ + /** + * Enables listening for events that the server received a message. + * @param { 'messageReceive' } type - event indicating that the server received a message. + * @param { Callback } callback - the callback used to return the result. + * @syscap SystemCapability.Communication.NetStack + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 + */ on(type: 'messageReceive', callback: Callback): void; - /** - * Enables listening for events that a connection from a given client has been closed. - * @param { 'close' } type - event indicating that a connection from a given client has been closed. - * @param { ClientConnectionCloseCallback } callback - the callback function when a client connection is closed. - * @syscap SystemCapability.Communication.NetStack - * @since 19 - */ + /** + * Enables listening for events that a connection from a given client has been closed. + * @param { 'close' } type - event indicating that a connection from a given client has been closed. + * @param { ClientConnectionCloseCallback } callback - the callback function when a client connection is closed. + * @syscap SystemCapability.Communication.NetStack + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 + */ on(type: 'close', callback: ClientConnectionCloseCallback): void; /** @@ -1295,7 +1336,8 @@ declare namespace webSocket { * @param { 'error' } type - event indicating that the WebSocket Server has encountered an error. * @param { ErrorCallback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'error', callback?: ErrorCallback): void; @@ -1304,7 +1346,8 @@ declare namespace webSocket { * @param { 'connect' } type - event indicating that a client requested to connect the server. * @param { Callback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'connect', callback?: Callback): void; @@ -1313,7 +1356,8 @@ declare namespace webSocket { * @param { 'close' } type - event indicating that a connection from a given client has been closed. * @param { ClientConnectionCloseCallback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'close', callback?: ClientConnectionCloseCallback): void; @@ -1322,7 +1366,8 @@ declare namespace webSocket { * @param { 'messageReceive' } type - event indicating that the server received a message. * @param { Callback } callback - the callback used to return the result. * @syscap SystemCapability.Communication.NetStack - * @since 19 + * @since arkts {'1.1':'19','1.2':'20'} + * @arkts 1.1&1.2 */ off(type: 'messageReceive', callback?: Callback): void; } -- Gitee