xshell 1.3.1 → 1.3.2

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/net.common.d.ts CHANGED
@@ -100,6 +100,8 @@ export interface RemoteOptions {
100
100
  /** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理
101
101
  用户设置后会覆盖默认的 print 错误功能 */
102
102
  on_error?(error: WebSocketConnectionError | Error, remote: Remote): void;
103
+ /** 使用者自定义的,在重连之前调用的函数,比如可以修改 url,仅连接发起方有效 */
104
+ on_reconnect?(this: Remote): Promise<void>;
103
105
  }
104
106
  /** 通过创建 remote 对象对 websocket rpc 进行抽象
105
107
  使用 remote.call() 进行一元 rpc
@@ -146,10 +148,11 @@ export declare class Remote {
146
148
  error: WebSocketConnectionError | Error;
147
149
  /** 作为 websocket 连接发起方,传入 url
148
150
  作为 websocket 连接接收方,传入 websocket + name */
149
- constructor({ name, url, websocket, funcs, print, verbose, probe, args, on_error, }?: RemoteOptions);
151
+ constructor({ name, url, websocket, funcs, print, verbose, probe, args, on_error, on_reconnect }?: RemoteOptions);
150
152
  /** 统一处理首次连接和连接后的 websocket 错误 */
151
153
  _on_error: (error: WebSocketConnectionError | Error) => void;
152
- reconnect: () => void;
154
+ on_reconnect?: (this: Remote) => Promise<void>;
155
+ reconnect: () => Promise<void>;
153
156
  _on_message: (data: ArrayBuffer) => void;
154
157
  /** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理
155
158
  用户设置后会覆盖默认的 print 错误功能 */
package/net.common.js CHANGED
@@ -238,12 +238,14 @@ export class Remote {
238
238
  error;
239
239
  /** 作为 websocket 连接发起方,传入 url
240
240
  作为 websocket 连接接收方,传入 websocket + name */
241
- constructor({ name, url, websocket, funcs, print, verbose, probe, args, on_error, } = {}) {
241
+ constructor({ name, url, websocket, funcs, print, verbose, probe, args, on_error, on_reconnect } = {}) {
242
242
  if (name)
243
243
  this.name = name;
244
244
  if (url) {
245
245
  check(!websocket, '构建 Remote 时 url 和 websocket 只能传其中一个');
246
246
  this.url = url;
247
+ if (on_reconnect)
248
+ this.on_reconnect = on_reconnect;
247
249
  }
248
250
  else { // 连接接收方,一定是 nodejs 环境
249
251
  check(websocket, '构建 Remote 时需传入 url 或者 websocket');
@@ -313,8 +315,11 @@ export class Remote {
313
315
  }
314
316
  this.on_error(error, this);
315
317
  };
316
- reconnect = () => {
318
+ on_reconnect;
319
+ reconnect = async () => {
317
320
  this.reconnecting = null;
321
+ if (this.on_reconnect)
322
+ await this.on_reconnect();
318
323
  this.try_connect();
319
324
  };
320
325
  _on_message = (data) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/path.d.ts CHANGED
@@ -54,7 +54,7 @@ export declare function extname(path: string): string;
54
54
  /** `/` */
55
55
  export declare const sep = "/";
56
56
  /** The platform-specific file delimiter. ';' or ':'. */
57
- export declare const delimiter: ";" | ":";
57
+ export declare const delimiter: ":" | ";";
58
58
  /** Returns an object from a path string - the opposite of format().
59
59
  @param path path to evaluate.
60
60
  @throws {TypeError} if `path` is not a string. */
@@ -81,7 +81,7 @@ export declare let path: {
81
81
  basename: typeof basename;
82
82
  extname: typeof extname;
83
83
  sep: string;
84
- delimiter: ";" | ":";
84
+ delimiter: ":" | ";";
85
85
  parse: typeof parse;
86
86
  format: typeof format;
87
87
  toNamespacedPath: typeof toNamespacedPath;