xshell 1.2.89 → 1.3.1
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/antd.sass +4 -31
- package/apps.js +1 -1
- package/builder.js +12 -17
- package/development.js +1 -1
- package/file.d.ts +11 -7
- package/file.js +8 -4
- package/i18n/dict.json +12 -0
- package/i18n/scanner/index.d.ts +1 -0
- package/i18n/scanner/index.js +14 -5
- package/net.browser.d.ts +1 -142
- package/net.browser.js +34 -443
- package/net.common.d.ts +178 -0
- package/net.common.js +564 -0
- package/net.d.ts +6 -175
- package/net.js +65 -530
- package/package.json +29 -30
- package/path.d.ts +2 -2
- package/platform.browser.js +9 -1
- package/platform.common.d.ts +10 -1
- package/platform.js +11 -1
- package/process.d.ts +2 -2
- package/process.js +2 -2
- package/prototype.common.d.ts +2 -2
- package/prototype.common.js +8 -8
- package/prototype.js +1 -1
- package/react.development.js +9199 -6036
- package/react.development.js.map +1 -1
- package/react.production.js +4958 -4306
- package/react.production.js.map +1 -1
- package/repl.js +7 -3
- package/server.d.ts +27 -12
- package/server.js +209 -71
- package/utils.browser.d.ts +1 -1
- package/utils.browser.js +3 -1
- package/utils.common.d.ts +29 -10
- package/utils.common.js +102 -35
- package/utils.d.ts +2 -2
- package/utils.js +10 -4
- package/i18n/utils.d.ts +0 -1
- package/i18n/utils.js +0 -11
package/net.common.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type Message } from './io.common.ts';
|
|
2
|
+
import { Lock, TimeoutError } from './utils.common.ts';
|
|
1
3
|
/** 对于 request() 函数来说无意义的 headers,会自动过滤掉 */
|
|
2
4
|
export declare const drop_request_headers: Set<string>;
|
|
3
5
|
export interface BasicAuth {
|
|
@@ -26,3 +28,179 @@ export interface RemoteKeeperOptions {
|
|
|
26
28
|
heartbeat_interval?: number;
|
|
27
29
|
error_delay?: number;
|
|
28
30
|
}
|
|
31
|
+
export declare const WebSocketConnecting = 0;
|
|
32
|
+
export declare const WebSocketOpen = 1;
|
|
33
|
+
export declare const WebSocketClosing = 2;
|
|
34
|
+
export declare const WebSocketClosed = 3;
|
|
35
|
+
export declare const websocket_states: readonly ["connecting", "open", "closing", "closed"];
|
|
36
|
+
export declare class WebSocketConnectionError extends Error {
|
|
37
|
+
name: "WebSocketConnectionError";
|
|
38
|
+
url: string;
|
|
39
|
+
protocols?: string[];
|
|
40
|
+
type?: 'close' | 'error';
|
|
41
|
+
/** close 事件时为 close code (非 1000 的 number), error 事件为 error code (可能是 string) */
|
|
42
|
+
code?: string | number;
|
|
43
|
+
reason?: string;
|
|
44
|
+
event?: CloseEvent | ErrorEvent;
|
|
45
|
+
address?: string;
|
|
46
|
+
errno?: number;
|
|
47
|
+
port?: number;
|
|
48
|
+
syscall?: string;
|
|
49
|
+
static get_reason_string(code: number | string, reason?: string): string | number;
|
|
50
|
+
constructor(url: string, protocols: string[] | undefined, event?: CloseEvent | ErrorEvent, message?: string);
|
|
51
|
+
}
|
|
52
|
+
/** 连接 websocket url, 设置各种事件监听器。在 open 事件后 resolve, 返回 websocket
|
|
53
|
+
遇到 error, close 事件时会创建 WebSocketConnectionError:
|
|
54
|
+
- reject 掉返回的 promise (若此时未 settle)
|
|
55
|
+
- 作为参数调用 on_error (已 settle 且有 on_error 回调)
|
|
56
|
+
可以用 WebSocket.bufferedAmount 来查询大消息的发送进度
|
|
57
|
+
https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/bufferedAmount
|
|
58
|
+
- url
|
|
59
|
+
- options:
|
|
60
|
+
- print?: 是否打印连接、关闭信息
|
|
61
|
+
- protocols?
|
|
62
|
+
- max_payload?: `8 gb` (仅 nodejs 环境有效)
|
|
63
|
+
- proxy?: string (仅 nodejs 环境有效)
|
|
64
|
+
- on_message: 根据 websocket frame 的 opcode 不同 (text frame 或 binary frame),event 中的 data 对应为 ArrayBuffer 或者 string
|
|
65
|
+
https://datatracker.ietf.org/doc/html/rfc6455#section-5.2
|
|
66
|
+
- on_error?: 在 websocket 出错和非正常关闭 (close, error 事件) 时都调用,可以根据 error.type 来区分,error 的类型是 WebSocketConnectionError,
|
|
67
|
+
type 为 'close' 时有 code 和 reason 属性
|
|
68
|
+
- on_close?: 和 websocket 的 'close' 事件不相同,只在正常关闭 (close code 为 1000) 时才调用,否则都会调用 on_error
|
|
69
|
+
https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes */
|
|
70
|
+
export declare function connect_websocket(url: string | URL, { print, protocols, max_payload, // 8 GB
|
|
71
|
+
proxy, on_message, on_error, on_close, }: {
|
|
72
|
+
print?: boolean;
|
|
73
|
+
protocols?: string[];
|
|
74
|
+
max_payload?: number;
|
|
75
|
+
proxy?: string;
|
|
76
|
+
on_message(data: ArrayBuffer | string, websocket: WebSocket): any;
|
|
77
|
+
on_error?(error: WebSocketConnectionError, websocket: WebSocket): any;
|
|
78
|
+
on_close?(event: CloseEvent, websocket: WebSocket): any;
|
|
79
|
+
}): Promise<WebSocket>;
|
|
80
|
+
/** 接收到消息后的处理函数
|
|
81
|
+
返回值会自动被 await,然后可能被封装为 message 回传 */
|
|
82
|
+
export type MessageHandler<TData = any> = (message: Message<TData>, remote: Remote) => void | any | Promise<void | any>;
|
|
83
|
+
export interface RemoteOptions {
|
|
84
|
+
/** 对端名称,方便接收端提供更明确的报错信息 */
|
|
85
|
+
name?: string;
|
|
86
|
+
/** 作为 websocket 连接发起方,对端的 url 地址 */
|
|
87
|
+
url?: string;
|
|
88
|
+
/** 作为 websocket 连接接收方,将已有的 websocket 连接转为 rpc 通道 */
|
|
89
|
+
websocket?: WebSocket;
|
|
90
|
+
/** 能被对端调用的函数 */
|
|
91
|
+
funcs?: Remote['funcs'];
|
|
92
|
+
/** `false` 是否启用主动探测连接,在连接状态下以 30s 间隔发送心跳包确保连接状态 */
|
|
93
|
+
probe?: boolean;
|
|
94
|
+
/** websocket 连接建立成功时调用对端 register 函数的参数 (仅发起方有效) */
|
|
95
|
+
args?: any[];
|
|
96
|
+
/** `true` 是否打印连接信息、错误信息 */
|
|
97
|
+
print?: boolean;
|
|
98
|
+
/** `false` 打印所有交互的 rpc messages */
|
|
99
|
+
verbose?: boolean;
|
|
100
|
+
/** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理
|
|
101
|
+
用户设置后会覆盖默认的 print 错误功能 */
|
|
102
|
+
on_error?(error: WebSocketConnectionError | Error, remote: Remote): void;
|
|
103
|
+
}
|
|
104
|
+
/** 通过创建 remote 对象对 websocket rpc 进行抽象
|
|
105
|
+
使用 remote.call() 进行一元 rpc
|
|
106
|
+
使用 remote.send() 结合 message.id 进行复杂 rpc
|
|
107
|
+
|
|
108
|
+
可传入 funcs 注册函数,使得对端能调用,传入后,
|
|
109
|
+
连接发起方在检测到连接断开后间隔 2s (首次) / 10s 尝试重连
|
|
110
|
+
|
|
111
|
+
可启用 probe 选项启用主动探测连接,进一步确保连接可靠性
|
|
112
|
+
|
|
113
|
+
有两种创建方法:
|
|
114
|
+
- 传入 url 主动创建 websocket 连接
|
|
115
|
+
创建后等到首个 remote.call 或 remote.send 时建立实际 websocket 连接
|
|
116
|
+
- 传入 websocket,监听事件,将已有的 websocket 连接转为 rpc 通道
|
|
117
|
+
|
|
118
|
+
rpc 状态与底层连接的状态无关,如果是发起方,remote.send 时检测到断线会自动尝试建立新的 websocket 连接 */
|
|
119
|
+
export declare class Remote {
|
|
120
|
+
/** 对端名称,方便接收端提供更明确的报错信息 */
|
|
121
|
+
name?: string;
|
|
122
|
+
/** 作为 websocket 连接发起方,对端的 url 地址 */
|
|
123
|
+
url?: string;
|
|
124
|
+
/** 能被对端调用的函数 */
|
|
125
|
+
funcs: Record<string, MessageHandler>;
|
|
126
|
+
/** `false` 是否启用主动探测连接,在连接状态下以 30s 间隔发送心跳包确保连接状态 */
|
|
127
|
+
probe: boolean;
|
|
128
|
+
/** websocket 连接建立成功时调用对端 register 函数的参数 (仅发起方有效) */
|
|
129
|
+
args?: any[];
|
|
130
|
+
/** `true` 是否打印连接信息、错误信息 */
|
|
131
|
+
print: boolean;
|
|
132
|
+
/** `false` 打印所有交互的 rpc messages */
|
|
133
|
+
verbose: boolean;
|
|
134
|
+
/** 防止作为 websocket 连接发起方时并发创建 websocket 连接 */
|
|
135
|
+
lwebsocket: Lock<WebSocket>;
|
|
136
|
+
/** map<id, message handler>: 通过 (rpc message).id 找到对应的 handler
|
|
137
|
+
一元 rpc 接收方不需要设置 handlers, 发送方需要 */
|
|
138
|
+
handlers: Map<number, MessageHandler<any>>;
|
|
139
|
+
/** 是否正在定时主动检测重连 */
|
|
140
|
+
probing: boolean;
|
|
141
|
+
/** websocket 检测到错误,_on_error 被调用,此时会尝试一段时间后重连 */
|
|
142
|
+
reconnecting: NodeJS.Timeout;
|
|
143
|
+
/** 用户是否手动调用了 disconnect() 主动断开了连接 (仅发起方有效) */
|
|
144
|
+
disconnected: boolean;
|
|
145
|
+
/** on_error 接收到的,正常 websocket 连接发生的首个非 TimeoutError 错误 */
|
|
146
|
+
error: WebSocketConnectionError | Error;
|
|
147
|
+
/** 作为 websocket 连接发起方,传入 url
|
|
148
|
+
作为 websocket 连接接收方,传入 websocket + name */
|
|
149
|
+
constructor({ name, url, websocket, funcs, print, verbose, probe, args, on_error, }?: RemoteOptions);
|
|
150
|
+
/** 统一处理首次连接和连接后的 websocket 错误 */
|
|
151
|
+
_on_error: (error: WebSocketConnectionError | Error) => void;
|
|
152
|
+
reconnect: () => void;
|
|
153
|
+
_on_message: (data: ArrayBuffer) => void;
|
|
154
|
+
/** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理
|
|
155
|
+
用户设置后会覆盖默认的 print 错误功能 */
|
|
156
|
+
on_error(error: WebSocketConnectionError | Error, remote: Remote): void;
|
|
157
|
+
print_error(error: WebSocketConnectionError | Error): void;
|
|
158
|
+
/** 检查是否已经有 error, websocket 状态是否正常 (open | connecting)
|
|
159
|
+
返回 true: 连接正常,false: 连接异常 */
|
|
160
|
+
check_connection(): boolean;
|
|
161
|
+
/** 幂等,保证 websocket 已连接,否则抛出异常
|
|
162
|
+
通常用于手动建立 websocket 连接并确保成功
|
|
163
|
+
连接断开后,作为发起方会自动创建新的 websocket 连接;
|
|
164
|
+
作为接收方只会检查连接状态,在断开时抛出异常
|
|
165
|
+
保存的 rpc 状态在 this.handlers, 与 websocket 无关,因此即使断开重连也不影响 rpc 的运行,即
|
|
166
|
+
底层连接断开后自动重连对上层应该是无感知的,除非再次连接时失败 */
|
|
167
|
+
connect(): Promise<void>;
|
|
168
|
+
_connect: () => Promise<void>;
|
|
169
|
+
/** 尝试建立连接,通常用于开始保活
|
|
170
|
+
重连错误会在 this.connect 里面调用 this._on_error 处理 */
|
|
171
|
+
try_connect(): Promise<void>;
|
|
172
|
+
/** 开始心跳保活 */
|
|
173
|
+
probe_connection(print_timeout?: boolean): Promise<void>;
|
|
174
|
+
/** 检测连接,返回连接错误,出错时触发 on_error 打印错误信息
|
|
175
|
+
返回值:
|
|
176
|
+
- 连接正常返回: undefined
|
|
177
|
+
- 连接错误返回: 实际的连接错误,通常是 WebSocketConnectionError | TimeoutError */
|
|
178
|
+
test(print_timeout?: boolean): Promise<WebSocketConnectionError | TimeoutError | Error>;
|
|
179
|
+
/** 手动关闭到对端的 websocket 连接 */
|
|
180
|
+
disconnect(): void;
|
|
181
|
+
/** 发送 message 到对端 remote
|
|
182
|
+
发送或连接出错时自动清理 message.id 对应的 handler */
|
|
183
|
+
send(message: Message): Promise<void>;
|
|
184
|
+
/** 能发就发一下,忽略发送失败, best effort */
|
|
185
|
+
try_send(message: Message): void;
|
|
186
|
+
/** 处理接收到的 websocket message 并解析, 根据 message.id 或 message.func 分发到对应的 handler 进行处理,
|
|
187
|
+
handler 处理完成后:
|
|
188
|
+
- 传了 func: 调用函数的情况下 (通常是一元 rpc),总是将返回值包装为 message 回传
|
|
189
|
+
- 未传 func: 通过 id 调用,如果 handler 返回非 undefined 的值,也包装为 message 回传
|
|
190
|
+
|
|
191
|
+
如果 message.done == true 则对端指示当前 remote 可以清理 handler
|
|
192
|
+
使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214
|
|
193
|
+
这个方法一般不会抛出错误,也不需要 await,一般在 websocket on_message 时使用 */
|
|
194
|
+
handle(data: Uint8Array): Promise<void>;
|
|
195
|
+
/** 调用对端 remote 中的 func, 只适用于最简单的一元 rpc (请求, 响应) */
|
|
196
|
+
call<TReturn = any>(func: string, args?: any[]): Promise<TReturn>;
|
|
197
|
+
/** 调用对端 remote 中的 func, 开始订阅并接收连续的消息 (订阅流)
|
|
198
|
+
- func: 订阅处理函数
|
|
199
|
+
- on_data: 接收开始订阅后的数据
|
|
200
|
+
- options?:
|
|
201
|
+
- on_error?: 处理开始订阅后的错误 */
|
|
202
|
+
subscribe<TData, TSubscribed = void>(func: string, on_data: (data: TData) => void, on_error?: Remote['on_error']): Promise<{
|
|
203
|
+
id: number;
|
|
204
|
+
data: TSubscribed;
|
|
205
|
+
}>;
|
|
206
|
+
}
|