ms-types 0.1.23 → 0.1.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +20 -20
- package/types/action.d.ts +298 -298
- package/types/{appleocr.d.ts → appleOcr.d.ts} +102 -102
- package/types/config.d.ts +54 -54
- package/types/device.d.ts +105 -105
- package/types/global.d.ts +185 -185
- package/types/hid.d.ts +289 -289
- package/types/hotUpdate.d.ts +104 -104
- package/types/http.d.ts +300 -300
- package/types/ime.d.ts +99 -99
- package/types/index.d.ts +26 -26
- package/types/media.d.ts +90 -90
- package/types/mysql.d.ts +174 -174
- package/types/netCard.d.ts +77 -42
- package/types/node.d.ts +279 -279
- package/types/{paddleocr.d.ts → paddleOcr.d.ts} +73 -73
- package/types/pip.d.ts +51 -51
- package/types/system.d.ts +195 -195
- package/types/thread.d.ts +101 -101
- package/types/{tomatoocr.d.ts → tomatoOcr.d.ts} +199 -199
- package/types/tts.d.ts +91 -91
- package/types/ui.d.ts +165 -165
- package/types/yolo.d.ts +98 -98
- package/types/zh/HID/346/250/241/345/235/227.d.ts +293 -293
- package/types/zh/HTTP/346/250/241/345/235/227.d.ts +301 -301
- package/types/zh/{MySql → MySQL}/346/250/241/345/235/227.d.ts +175 -175
- package/types/zh/PaddleOCR/346/250/241/345/235/227.d.ts +74 -74
- package/types/zh/YOLO/346/250/241/345/235/227.d.ts +101 -101
- package/types/zh/index.d.ts +24 -24
- package/types/zh//345/205/250/345/261/200/346/250/241/345/235/227.d.ts +180 -180
- package/types/zh//345/212/250/344/275/234/346/250/241/345/235/227.d.ts +300 -300
- package/types/zh//345/215/241/345/257/206/346/250/241/345/235/227.d.ts +90 -55
- package/types/zh//345/252/222/344/275/223/346/250/241/345/235/227.d.ts +91 -91
- package/types/zh//345/267/245/345/205/267/346/250/241/345/235/227.d.ts +30 -30
- package/types/zh//346/202/254/346/265/256/347/252/227/346/250/241/345/235/227.d.ts +55 -55
- package/types/zh//346/226/207/345/255/227/350/275/254/350/257/255/351/237/263/346/250/241/345/235/227.d.ts +92 -92
- package/types/zh//347/203/255/346/233/264/346/226/260/346/250/241/345/235/227.d.ts +105 -105
- package/types/zh//347/263/273/347/273/237/346/250/241/345/235/227.d.ts +194 -194
- package/types/zh//347/272/277/347/250/213/346/250/241/345/235/227.d.ts +102 -102
- package/types/zh//350/212/202/347/202/271/346/250/241/345/235/227.d.ts +280 -280
- package/types/zh//350/213/271/346/236/234OCR.d.ts +104 -104
- package/types/zh//350/247/206/345/233/276/346/250/241/345/235/227.d.ts +167 -167
- package/types/zh//350/256/276/345/244/207/346/250/241/345/235/227.d.ts +106 -106
- package/types/zh//350/276/223/345/205/245/346/263/225/346/250/241/345/235/227.d.ts +100 -100
- package/types/zh//351/205/215/347/275/256/346/250/241/345/235/227.d.ts +56 -56
package/types/http.d.ts
CHANGED
|
@@ -1,300 +1,300 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP模块 包含发送HTTP请求、下载文件等功能、websocket等功能
|
|
3
|
-
*/
|
|
4
|
-
declare namespace http {
|
|
5
|
-
/**
|
|
6
|
-
* 通用发送HTTP请求
|
|
7
|
-
* @param params 请求参数
|
|
8
|
-
* @returns 请求结果
|
|
9
|
-
* @example
|
|
10
|
-
* http.request({
|
|
11
|
-
* url: "https://www.baidu.com",
|
|
12
|
-
* method: "GET",
|
|
13
|
-
* })
|
|
14
|
-
*/
|
|
15
|
-
function request(params: {
|
|
16
|
-
/**
|
|
17
|
-
* 请求地址
|
|
18
|
-
*/
|
|
19
|
-
url: string;
|
|
20
|
-
/**
|
|
21
|
-
* 请求超时时间
|
|
22
|
-
*/
|
|
23
|
-
timeout?: number;
|
|
24
|
-
/**
|
|
25
|
-
* 请求方法 GET POST PUT DELETE PATCH HEAD OPTIONS
|
|
26
|
-
*/
|
|
27
|
-
method?: string;
|
|
28
|
-
/**
|
|
29
|
-
* 代理服务器
|
|
30
|
-
*/
|
|
31
|
-
proxy?: {
|
|
32
|
-
/**
|
|
33
|
-
* 代理服务器地址
|
|
34
|
-
*/
|
|
35
|
-
host: string;
|
|
36
|
-
/**
|
|
37
|
-
* 代理服务器端口
|
|
38
|
-
*/
|
|
39
|
-
port: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* 是否跟随重定向
|
|
43
|
-
*/
|
|
44
|
-
followRedirects?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* 请求体 仅在POST方法下有效 json 需要进行JSON.stringify
|
|
47
|
-
*/
|
|
48
|
-
requestBody?: string;
|
|
49
|
-
/**
|
|
50
|
-
* 请求头
|
|
51
|
-
*/
|
|
52
|
-
userAgent?: string;
|
|
53
|
-
/**
|
|
54
|
-
* 是否忽略内容类型
|
|
55
|
-
*/
|
|
56
|
-
ignoreContentType?: boolean;
|
|
57
|
-
/**
|
|
58
|
-
* 是否忽略HTTP错误
|
|
59
|
-
*/
|
|
60
|
-
ignoreHttpErrors?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* 最大响应体大小 默认 10MB
|
|
63
|
-
*/
|
|
64
|
-
maxBodySize?: number;
|
|
65
|
-
/**
|
|
66
|
-
* 引用来源
|
|
67
|
-
*/
|
|
68
|
-
referrer?: string;
|
|
69
|
-
/**
|
|
70
|
-
* 请求头
|
|
71
|
-
*/
|
|
72
|
-
header?: Record<string, string>;
|
|
73
|
-
/**
|
|
74
|
-
* Cookie
|
|
75
|
-
*/
|
|
76
|
-
cookie?: Record<string, string>;
|
|
77
|
-
/**
|
|
78
|
-
* 请求参数
|
|
79
|
-
*/
|
|
80
|
-
data?: Record<string, any>;
|
|
81
|
-
/**
|
|
82
|
-
* 请求文件
|
|
83
|
-
*/
|
|
84
|
-
file?: Record<string, string>;
|
|
85
|
-
/**
|
|
86
|
-
* 响应字符集
|
|
87
|
-
*/
|
|
88
|
-
responseCharset?: string;
|
|
89
|
-
}): {
|
|
90
|
-
/**
|
|
91
|
-
* 响应头
|
|
92
|
-
*/
|
|
93
|
-
header: Record<string, string>;
|
|
94
|
-
/**
|
|
95
|
-
* 响应Cookie
|
|
96
|
-
*/
|
|
97
|
-
cookie: Record<string, string>;
|
|
98
|
-
/**
|
|
99
|
-
* 响应状态码
|
|
100
|
-
*/
|
|
101
|
-
statusCode: number;
|
|
102
|
-
/**
|
|
103
|
-
* 响应状态消息
|
|
104
|
-
*/
|
|
105
|
-
statusMessage: string;
|
|
106
|
-
/**
|
|
107
|
-
* 响应字符集
|
|
108
|
-
*/
|
|
109
|
-
charset: string;
|
|
110
|
-
/**
|
|
111
|
-
* 响应内容类型
|
|
112
|
-
*/
|
|
113
|
-
contentType: string;
|
|
114
|
-
/**
|
|
115
|
-
* 响应体
|
|
116
|
-
*/
|
|
117
|
-
body: string;
|
|
118
|
-
} | null;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* 下载文件 支持断点续传
|
|
122
|
-
* @param url 请求地址
|
|
123
|
-
* @param file 文件路径
|
|
124
|
-
* @param timeout 超时时间
|
|
125
|
-
* @param headers 请求头
|
|
126
|
-
* @returns 下载是否成功
|
|
127
|
-
* @example
|
|
128
|
-
* http.downloadFile("https://www.baidu.com", "baidu.html")
|
|
129
|
-
*/
|
|
130
|
-
function downloadFile(
|
|
131
|
-
url: string,
|
|
132
|
-
file: string,
|
|
133
|
-
timeout?: number,
|
|
134
|
-
headers?: Record<string, string>
|
|
135
|
-
): boolean;
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* 发送GET请求
|
|
139
|
-
* @param url 请求地址
|
|
140
|
-
* @param params 请求参数
|
|
141
|
-
* @param timeout 超时时间
|
|
142
|
-
* @param headers 请求头
|
|
143
|
-
* @returns 请求结果
|
|
144
|
-
* @example
|
|
145
|
-
* http.httpGet("https://www.baidu.com")
|
|
146
|
-
*/
|
|
147
|
-
function httpGet(
|
|
148
|
-
url: string,
|
|
149
|
-
params?: Record<string, string>,
|
|
150
|
-
timeout?: number,
|
|
151
|
-
headers?: Record<string, string>
|
|
152
|
-
): string | null;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 发送POST请求
|
|
156
|
-
* @param url 请求地址
|
|
157
|
-
* @param params 请求参数
|
|
158
|
-
* @param files 请求文件
|
|
159
|
-
* @param timeout 超时时间
|
|
160
|
-
* @param headers 请求头
|
|
161
|
-
* @returns 请求结果
|
|
162
|
-
* @example
|
|
163
|
-
* http.httpPost("https://www.baidu.com")
|
|
164
|
-
*/
|
|
165
|
-
function httpPost(
|
|
166
|
-
url: string,
|
|
167
|
-
params?: Record<string, string>,
|
|
168
|
-
files?: Record<string, string>,
|
|
169
|
-
timeout?: number,
|
|
170
|
-
headers?: Record<string, string>
|
|
171
|
-
): string | null;
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* 发送JSON请求
|
|
175
|
-
* @param url 请求地址
|
|
176
|
-
* @param json 请求JSON数据
|
|
177
|
-
* @param timeout 超时时间
|
|
178
|
-
* @param headers 请求头
|
|
179
|
-
* @returns 请求结果
|
|
180
|
-
* @example
|
|
181
|
-
* http.postJSON("https://www.baidu.com", {
|
|
182
|
-
* "name": "快点JS",
|
|
183
|
-
* "version": "1.0.0"
|
|
184
|
-
* })
|
|
185
|
-
*/
|
|
186
|
-
function postJSON(
|
|
187
|
-
url: string,
|
|
188
|
-
json?: Record<string, any>,
|
|
189
|
-
timeout?: number,
|
|
190
|
-
headers?: Record<string, string>
|
|
191
|
-
): string | null;
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* 创建WebSocket连接
|
|
195
|
-
* @param url 连接地址
|
|
196
|
-
* @param header 连接头
|
|
197
|
-
* @returns WebSocket连接对象
|
|
198
|
-
* @example
|
|
199
|
-
* const ws = http.newWebsocket("ws://www.baidu.com")
|
|
200
|
-
* ws.connect()
|
|
201
|
-
* ws.onText((data) => {
|
|
202
|
-
* logi(data)
|
|
203
|
-
* })
|
|
204
|
-
* ws.sendText("hello")
|
|
205
|
-
* ws.close()
|
|
206
|
-
*/
|
|
207
|
-
function newWebsocket(
|
|
208
|
-
url: string,
|
|
209
|
-
header?: Record<string, string>
|
|
210
|
-
): WebSocket;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* WebSocket连接
|
|
214
|
-
*/
|
|
215
|
-
interface WebSocket {
|
|
216
|
-
/**
|
|
217
|
-
* 连接WebSocket服务器
|
|
218
|
-
*/
|
|
219
|
-
connect(): void;
|
|
220
|
-
/**
|
|
221
|
-
* 关闭WebSocket连接
|
|
222
|
-
*/
|
|
223
|
-
close(): void;
|
|
224
|
-
/**
|
|
225
|
-
* 重置WebSocket连接
|
|
226
|
-
* @returns 重置是否成功
|
|
227
|
-
*/
|
|
228
|
-
reset(): boolean;
|
|
229
|
-
/**
|
|
230
|
-
* 获取WebSocket是否已关闭
|
|
231
|
-
* @returns 是否已关闭
|
|
232
|
-
*/
|
|
233
|
-
isClosed(): boolean;
|
|
234
|
-
/**
|
|
235
|
-
* 获取WebSocket是否已连接
|
|
236
|
-
* @returns 是否已连接
|
|
237
|
-
*/
|
|
238
|
-
isConnected(): boolean;
|
|
239
|
-
/**
|
|
240
|
-
* 发送文本消息
|
|
241
|
-
* @param data 文本消息内容
|
|
242
|
-
*/
|
|
243
|
-
sendText(data: string): void;
|
|
244
|
-
/**
|
|
245
|
-
* 发送二进制消息
|
|
246
|
-
* @param data 二进制消息内容
|
|
247
|
-
*/
|
|
248
|
-
sendBinary(data: ArrayBuffer): void;
|
|
249
|
-
/**
|
|
250
|
-
* 设置打开回调
|
|
251
|
-
* @param callback 打开回调函数
|
|
252
|
-
*/
|
|
253
|
-
onOpen(callback: () => void): void;
|
|
254
|
-
/**
|
|
255
|
-
* 设置关闭回调
|
|
256
|
-
* @param callback 关闭回调函数
|
|
257
|
-
*/
|
|
258
|
-
onClose(callback: () => void): void;
|
|
259
|
-
/**
|
|
260
|
-
* 设置文本消息回调
|
|
261
|
-
* @param callback 文本消息回调函数
|
|
262
|
-
*/
|
|
263
|
-
onText(callback: (data: string) => void): void;
|
|
264
|
-
/**
|
|
265
|
-
* 设置二进制消息回调
|
|
266
|
-
* @param callback 二进制消息回调函数
|
|
267
|
-
*/
|
|
268
|
-
onBinary(callback: (data: ArrayBuffer) => void): void;
|
|
269
|
-
/**
|
|
270
|
-
* 设置错误回调
|
|
271
|
-
* @param callback 错误回调函数
|
|
272
|
-
*/
|
|
273
|
-
onError(callback: (error: string) => void): void;
|
|
274
|
-
/**
|
|
275
|
-
* 设置连接超时时间
|
|
276
|
-
* @param timeout 超时时间,单位秒
|
|
277
|
-
*/
|
|
278
|
-
setConnectionTimeout(timeout: number): void;
|
|
279
|
-
/**
|
|
280
|
-
* 设置写入超时时间
|
|
281
|
-
* @param timeout 超时时间,单位秒
|
|
282
|
-
*/
|
|
283
|
-
setWriteTimeout(timeout: number): void;
|
|
284
|
-
/**
|
|
285
|
-
* 设置心跳间隔时间
|
|
286
|
-
* @param interval 间隔时间,单位秒
|
|
287
|
-
* @param callback 心跳回调函数
|
|
288
|
-
*/
|
|
289
|
-
startHeartbeatInterval(interval: number, callback: () => string): void;
|
|
290
|
-
/**
|
|
291
|
-
* 停止心跳间隔
|
|
292
|
-
*/
|
|
293
|
-
stopHeartbeatInterval(): void;
|
|
294
|
-
/**
|
|
295
|
-
* 设置自动重连
|
|
296
|
-
* @param autoReconnect 是否自动重连
|
|
297
|
-
*/
|
|
298
|
-
setAutoReconnect(autoReconnect: boolean): void;
|
|
299
|
-
}
|
|
300
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* HTTP模块 包含发送HTTP请求、下载文件等功能、websocket等功能
|
|
3
|
+
*/
|
|
4
|
+
declare namespace http {
|
|
5
|
+
/**
|
|
6
|
+
* 通用发送HTTP请求
|
|
7
|
+
* @param params 请求参数
|
|
8
|
+
* @returns 请求结果
|
|
9
|
+
* @example
|
|
10
|
+
* http.request({
|
|
11
|
+
* url: "https://www.baidu.com",
|
|
12
|
+
* method: "GET",
|
|
13
|
+
* })
|
|
14
|
+
*/
|
|
15
|
+
function request(params: {
|
|
16
|
+
/**
|
|
17
|
+
* 请求地址
|
|
18
|
+
*/
|
|
19
|
+
url: string;
|
|
20
|
+
/**
|
|
21
|
+
* 请求超时时间
|
|
22
|
+
*/
|
|
23
|
+
timeout?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 请求方法 GET POST PUT DELETE PATCH HEAD OPTIONS
|
|
26
|
+
*/
|
|
27
|
+
method?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 代理服务器
|
|
30
|
+
*/
|
|
31
|
+
proxy?: {
|
|
32
|
+
/**
|
|
33
|
+
* 代理服务器地址
|
|
34
|
+
*/
|
|
35
|
+
host: string;
|
|
36
|
+
/**
|
|
37
|
+
* 代理服务器端口
|
|
38
|
+
*/
|
|
39
|
+
port: number;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* 是否跟随重定向
|
|
43
|
+
*/
|
|
44
|
+
followRedirects?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* 请求体 仅在POST方法下有效 json 需要进行JSON.stringify
|
|
47
|
+
*/
|
|
48
|
+
requestBody?: string;
|
|
49
|
+
/**
|
|
50
|
+
* 请求头
|
|
51
|
+
*/
|
|
52
|
+
userAgent?: string;
|
|
53
|
+
/**
|
|
54
|
+
* 是否忽略内容类型
|
|
55
|
+
*/
|
|
56
|
+
ignoreContentType?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* 是否忽略HTTP错误
|
|
59
|
+
*/
|
|
60
|
+
ignoreHttpErrors?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* 最大响应体大小 默认 10MB
|
|
63
|
+
*/
|
|
64
|
+
maxBodySize?: number;
|
|
65
|
+
/**
|
|
66
|
+
* 引用来源
|
|
67
|
+
*/
|
|
68
|
+
referrer?: string;
|
|
69
|
+
/**
|
|
70
|
+
* 请求头
|
|
71
|
+
*/
|
|
72
|
+
header?: Record<string, string>;
|
|
73
|
+
/**
|
|
74
|
+
* Cookie
|
|
75
|
+
*/
|
|
76
|
+
cookie?: Record<string, string>;
|
|
77
|
+
/**
|
|
78
|
+
* 请求参数
|
|
79
|
+
*/
|
|
80
|
+
data?: Record<string, any>;
|
|
81
|
+
/**
|
|
82
|
+
* 请求文件
|
|
83
|
+
*/
|
|
84
|
+
file?: Record<string, string>;
|
|
85
|
+
/**
|
|
86
|
+
* 响应字符集
|
|
87
|
+
*/
|
|
88
|
+
responseCharset?: string;
|
|
89
|
+
}): {
|
|
90
|
+
/**
|
|
91
|
+
* 响应头
|
|
92
|
+
*/
|
|
93
|
+
header: Record<string, string>;
|
|
94
|
+
/**
|
|
95
|
+
* 响应Cookie
|
|
96
|
+
*/
|
|
97
|
+
cookie: Record<string, string>;
|
|
98
|
+
/**
|
|
99
|
+
* 响应状态码
|
|
100
|
+
*/
|
|
101
|
+
statusCode: number;
|
|
102
|
+
/**
|
|
103
|
+
* 响应状态消息
|
|
104
|
+
*/
|
|
105
|
+
statusMessage: string;
|
|
106
|
+
/**
|
|
107
|
+
* 响应字符集
|
|
108
|
+
*/
|
|
109
|
+
charset: string;
|
|
110
|
+
/**
|
|
111
|
+
* 响应内容类型
|
|
112
|
+
*/
|
|
113
|
+
contentType: string;
|
|
114
|
+
/**
|
|
115
|
+
* 响应体
|
|
116
|
+
*/
|
|
117
|
+
body: string;
|
|
118
|
+
} | null;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 下载文件 支持断点续传
|
|
122
|
+
* @param url 请求地址
|
|
123
|
+
* @param file 文件路径
|
|
124
|
+
* @param timeout 超时时间
|
|
125
|
+
* @param headers 请求头
|
|
126
|
+
* @returns 下载是否成功
|
|
127
|
+
* @example
|
|
128
|
+
* http.downloadFile("https://www.baidu.com", "baidu.html")
|
|
129
|
+
*/
|
|
130
|
+
function downloadFile(
|
|
131
|
+
url: string,
|
|
132
|
+
file: string,
|
|
133
|
+
timeout?: number,
|
|
134
|
+
headers?: Record<string, string>
|
|
135
|
+
): boolean;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 发送GET请求
|
|
139
|
+
* @param url 请求地址
|
|
140
|
+
* @param params 请求参数
|
|
141
|
+
* @param timeout 超时时间
|
|
142
|
+
* @param headers 请求头
|
|
143
|
+
* @returns 请求结果
|
|
144
|
+
* @example
|
|
145
|
+
* http.httpGet("https://www.baidu.com")
|
|
146
|
+
*/
|
|
147
|
+
function httpGet(
|
|
148
|
+
url: string,
|
|
149
|
+
params?: Record<string, string>,
|
|
150
|
+
timeout?: number,
|
|
151
|
+
headers?: Record<string, string>
|
|
152
|
+
): string | null;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* 发送POST请求
|
|
156
|
+
* @param url 请求地址
|
|
157
|
+
* @param params 请求参数
|
|
158
|
+
* @param files 请求文件
|
|
159
|
+
* @param timeout 超时时间
|
|
160
|
+
* @param headers 请求头
|
|
161
|
+
* @returns 请求结果
|
|
162
|
+
* @example
|
|
163
|
+
* http.httpPost("https://www.baidu.com")
|
|
164
|
+
*/
|
|
165
|
+
function httpPost(
|
|
166
|
+
url: string,
|
|
167
|
+
params?: Record<string, string>,
|
|
168
|
+
files?: Record<string, string>,
|
|
169
|
+
timeout?: number,
|
|
170
|
+
headers?: Record<string, string>
|
|
171
|
+
): string | null;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 发送JSON请求
|
|
175
|
+
* @param url 请求地址
|
|
176
|
+
* @param json 请求JSON数据
|
|
177
|
+
* @param timeout 超时时间
|
|
178
|
+
* @param headers 请求头
|
|
179
|
+
* @returns 请求结果
|
|
180
|
+
* @example
|
|
181
|
+
* http.postJSON("https://www.baidu.com", {
|
|
182
|
+
* "name": "快点JS",
|
|
183
|
+
* "version": "1.0.0"
|
|
184
|
+
* })
|
|
185
|
+
*/
|
|
186
|
+
function postJSON(
|
|
187
|
+
url: string,
|
|
188
|
+
json?: Record<string, any>,
|
|
189
|
+
timeout?: number,
|
|
190
|
+
headers?: Record<string, string>
|
|
191
|
+
): string | null;
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* 创建WebSocket连接
|
|
195
|
+
* @param url 连接地址
|
|
196
|
+
* @param header 连接头
|
|
197
|
+
* @returns WebSocket连接对象
|
|
198
|
+
* @example
|
|
199
|
+
* const ws = http.newWebsocket("ws://www.baidu.com")
|
|
200
|
+
* ws.connect()
|
|
201
|
+
* ws.onText((data) => {
|
|
202
|
+
* logi(data)
|
|
203
|
+
* })
|
|
204
|
+
* ws.sendText("hello")
|
|
205
|
+
* ws.close()
|
|
206
|
+
*/
|
|
207
|
+
function newWebsocket(
|
|
208
|
+
url: string,
|
|
209
|
+
header?: Record<string, string>
|
|
210
|
+
): WebSocket;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* WebSocket连接
|
|
214
|
+
*/
|
|
215
|
+
interface WebSocket {
|
|
216
|
+
/**
|
|
217
|
+
* 连接WebSocket服务器
|
|
218
|
+
*/
|
|
219
|
+
connect(): void;
|
|
220
|
+
/**
|
|
221
|
+
* 关闭WebSocket连接
|
|
222
|
+
*/
|
|
223
|
+
close(): void;
|
|
224
|
+
/**
|
|
225
|
+
* 重置WebSocket连接
|
|
226
|
+
* @returns 重置是否成功
|
|
227
|
+
*/
|
|
228
|
+
reset(): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* 获取WebSocket是否已关闭
|
|
231
|
+
* @returns 是否已关闭
|
|
232
|
+
*/
|
|
233
|
+
isClosed(): boolean;
|
|
234
|
+
/**
|
|
235
|
+
* 获取WebSocket是否已连接
|
|
236
|
+
* @returns 是否已连接
|
|
237
|
+
*/
|
|
238
|
+
isConnected(): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* 发送文本消息
|
|
241
|
+
* @param data 文本消息内容
|
|
242
|
+
*/
|
|
243
|
+
sendText(data: string): void;
|
|
244
|
+
/**
|
|
245
|
+
* 发送二进制消息
|
|
246
|
+
* @param data 二进制消息内容
|
|
247
|
+
*/
|
|
248
|
+
sendBinary(data: ArrayBuffer): void;
|
|
249
|
+
/**
|
|
250
|
+
* 设置打开回调
|
|
251
|
+
* @param callback 打开回调函数
|
|
252
|
+
*/
|
|
253
|
+
onOpen(callback: () => void): void;
|
|
254
|
+
/**
|
|
255
|
+
* 设置关闭回调
|
|
256
|
+
* @param callback 关闭回调函数
|
|
257
|
+
*/
|
|
258
|
+
onClose(callback: () => void): void;
|
|
259
|
+
/**
|
|
260
|
+
* 设置文本消息回调
|
|
261
|
+
* @param callback 文本消息回调函数
|
|
262
|
+
*/
|
|
263
|
+
onText(callback: (data: string) => void): void;
|
|
264
|
+
/**
|
|
265
|
+
* 设置二进制消息回调
|
|
266
|
+
* @param callback 二进制消息回调函数
|
|
267
|
+
*/
|
|
268
|
+
onBinary(callback: (data: ArrayBuffer) => void): void;
|
|
269
|
+
/**
|
|
270
|
+
* 设置错误回调
|
|
271
|
+
* @param callback 错误回调函数
|
|
272
|
+
*/
|
|
273
|
+
onError(callback: (error: string) => void): void;
|
|
274
|
+
/**
|
|
275
|
+
* 设置连接超时时间
|
|
276
|
+
* @param timeout 超时时间,单位秒
|
|
277
|
+
*/
|
|
278
|
+
setConnectionTimeout(timeout: number): void;
|
|
279
|
+
/**
|
|
280
|
+
* 设置写入超时时间
|
|
281
|
+
* @param timeout 超时时间,单位秒
|
|
282
|
+
*/
|
|
283
|
+
setWriteTimeout(timeout: number): void;
|
|
284
|
+
/**
|
|
285
|
+
* 设置心跳间隔时间
|
|
286
|
+
* @param interval 间隔时间,单位秒
|
|
287
|
+
* @param callback 心跳回调函数
|
|
288
|
+
*/
|
|
289
|
+
startHeartbeatInterval(interval: number, callback: () => string): void;
|
|
290
|
+
/**
|
|
291
|
+
* 停止心跳间隔
|
|
292
|
+
*/
|
|
293
|
+
stopHeartbeatInterval(): void;
|
|
294
|
+
/**
|
|
295
|
+
* 设置自动重连
|
|
296
|
+
* @param autoReconnect 是否自动重连
|
|
297
|
+
*/
|
|
298
|
+
setAutoReconnect(autoReconnect: boolean): void;
|
|
299
|
+
}
|
|
300
|
+
}
|