xshell 1.0.208 → 1.0.210

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.browser.d.ts CHANGED
@@ -207,13 +207,13 @@ export declare class Remote {
207
207
  verbose?: boolean;
208
208
  websocket?: WebSocket;
209
209
  keeper?: RemoteKeeperOptions;
210
- on_error?(error: WebSocketConnectionError, websocket?: WebSocket): void;
210
+ on_error?(error: WebSocketConnectionError | Error, websocket?: WebSocket): void;
211
211
  });
212
- /** 统一处理首次连接错误和连接后的错误 */
212
+ /** 统一处理首次连接和连接后的 websocket 错误 */
213
213
  _on_error: (error: WebSocketConnectionError, websocket?: WebSocket) => void;
214
214
  _on_message: (data: ArrayBuffer, websocket: WebSocket) => void;
215
- /** 使用者自定义的在连接后出错时的处理 */
216
- on_error?(error: WebSocketConnectionError, websocket?: WebSocket): void;
215
+ /** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理 */
216
+ on_error(error: WebSocketConnectionError | Error, websocket?: WebSocket): void;
217
217
  /** 幂等,保证 websocket 已连接,否则抛出异常
218
218
  一般情况不需要手动调用,在其它方法中会自动调用这个方法,除非需要手动建立 websocket 连接并确保成功
219
219
  连接断开后,通过传入 url 参数构造的 remote 实例会自动创建新的 websocket 连接,而通过传入 websocket 参数构造的实例只会检查连接状态,在断开时抛出异常
@@ -230,7 +230,8 @@ export declare class Remote {
230
230
  /** 处理接收到的 websocket message 并解析, 根据 message.id 或 message.func 分发到对应的 handler 进行处理
231
231
  如果 message.done == true 则对端指示当前 remote 可以清理 handler
232
232
  如果 handler 返回了值 (一定是数组),则包装为 message 发送
233
- 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214 */
233
+ 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214
234
+ 这个方法一般不会抛出错误,也不需要 await,一般在 websocket on_message 时使用 */
234
235
  handle(data: Uint8Array, websocket: WebSocket): Promise<void>;
235
236
  /** 调用对端 remote 中的 func, 只适用于最简单的一元 rpc (请求, 响应)
236
237
  作为 websocket 连接发起方,不需要传入 websocket
package/net.browser.js CHANGED
@@ -369,10 +369,8 @@ export class Remote {
369
369
  };
370
370
  }
371
371
  }
372
- /** 统一处理首次连接错误和连接后的错误 */
372
+ /** 统一处理首次连接和连接后的 websocket 错误 */
373
373
  _on_error = (error, websocket) => {
374
- if (websocket) // 连接后出现的错误
375
- this.on_error?.(error, websocket);
376
374
  if (this.keeper && !this.reconnecting && !this.disconnected) // 在一段时间后调度错误重连
377
375
  (async () => {
378
376
  this.reconnecting = true;
@@ -396,18 +394,17 @@ export class Remote {
396
394
  // 重连由 this.connect 里面调用 this._on_error 处理
397
395
  }
398
396
  })();
397
+ this.on_error(error, websocket);
399
398
  };
400
399
  _on_message = (data, websocket) => {
401
400
  this.handle(new Uint8Array(data), websocket);
402
401
  };
403
- /** 使用者自定义的在连接后出错时的处理 */
402
+ /** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理 */
404
403
  on_error(error, websocket) {
405
- if (this.keeper) {
406
- if (this.print)
407
- console.log(error.message);
408
- }
409
- else
410
- throw error;
404
+ // 使用者未定义 Remote 如何处理 error 时,一般来说直接忽略即可,因为 handlers 中报错了也会返回给对端
405
+ if (this.print)
406
+ console.log(error);
407
+ // 这里继续往上层抛没有太大意义,上面一般都是 websocket on_message 这些
411
408
  }
412
409
  /** 幂等,保证 websocket 已连接,否则抛出异常
413
410
  一般情况不需要手动调用,在其它方法中会自动调用这个方法,除非需要手动建立 websocket 连接并确保成功
@@ -499,7 +496,8 @@ export class Remote {
499
496
  /** 处理接收到的 websocket message 并解析, 根据 message.id 或 message.func 分发到对应的 handler 进行处理
500
497
  如果 message.done == true 则对端指示当前 remote 可以清理 handler
501
498
  如果 handler 返回了值 (一定是数组),则包装为 message 发送
502
- 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214 */
499
+ 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214
500
+ 这个方法一般不会抛出错误,也不需要 await,一般在 websocket on_message 时使用 */
503
501
  async handle(data, websocket) {
504
502
  const message = Remote.parse(data);
505
503
  const { id, func, done } = message;
@@ -528,7 +526,8 @@ export class Remote {
528
526
  !message.error // 防止无限循环往对方发送 error, 只有在对方无错误时才可以发送
529
527
  )
530
528
  await this.send({ id, error, /* 不能设置 done 清理对面 handler, 理由同上 */ }, websocket);
531
- throw error;
529
+ // 这里继续往上层抛没有太大意义,上面一般都是 websocket on_message 这些,交给自定义或默认的 on_error 处理
530
+ this.on_error(error);
532
531
  }
533
532
  }
534
533
  /** 调用对端 remote 中的 func, 只适用于最简单的一元 rpc (请求, 响应)
package/net.d.ts CHANGED
@@ -274,13 +274,13 @@ export declare class Remote {
274
274
  verbose?: boolean;
275
275
  websocket?: WebSocket;
276
276
  keeper?: RemoteKeeperOptions;
277
- on_error?(error: WebSocketConnectionError, websocket?: WebSocket): void;
277
+ on_error?(error: WebSocketConnectionError | Error, websocket?: WebSocket): void;
278
278
  });
279
- /** 统一处理首次连接错误和连接后的错误 */
279
+ /** 统一处理首次连接和连接后的 websocket 错误 */
280
280
  _on_error: (error: WebSocketConnectionError, websocket?: WebSocket) => void;
281
281
  _on_message: (data: ArrayBuffer, websocket: WebSocket) => void;
282
- /** 使用者自定义的在连接后出错时的处理 */
283
- on_error?(error: WebSocketConnectionError, websocket?: WebSocket): void;
282
+ /** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理 */
283
+ on_error(error: WebSocketConnectionError | Error, websocket?: WebSocket): void;
284
284
  /** 幂等,保证 websocket 已连接,否则抛出异常
285
285
  一般情况不需要手动调用,在其它方法中会自动调用这个方法,除非需要手动建立 websocket 连接并确保成功
286
286
  连接断开后,通过传入 url 参数构造的 remote 实例会自动创建新的 websocket 连接,而通过传入 websocket 参数构造的实例只会检查连接状态,在断开时抛出异常
@@ -297,7 +297,8 @@ export declare class Remote {
297
297
  /** 处理接收到的 websocket message 并解析, 根据 message.id 或 message.func 分发到对应的 handler 进行处理
298
298
  如果 message.done == true 则对端指示当前 remote 可以清理 handler
299
299
  如果 handler 返回了值 (一定是数组),则包装为 message 发送
300
- 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214 */
300
+ 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214
301
+ 这个方法一般不会抛出错误,也不需要 await,一般在 websocket on_message 时使用 */
301
302
  handle(data: Uint8Array, websocket: WebSocket): Promise<void>;
302
303
  /** 调用对端 remote 中的 func, 只适用于最简单的一元 rpc (请求, 响应)
303
304
  作为 websocket 连接发起方,不需要传入 websocket
package/net.js CHANGED
@@ -601,10 +601,8 @@ export class Remote {
601
601
  };
602
602
  }
603
603
  }
604
- /** 统一处理首次连接错误和连接后的错误 */
604
+ /** 统一处理首次连接和连接后的 websocket 错误 */
605
605
  _on_error = (error, websocket) => {
606
- if (websocket) // 连接后出现的错误
607
- this.on_error?.(error, websocket);
608
606
  if (this.keeper && !this.reconnecting && !this.disconnected) // 在一段时间后调度错误重连
609
607
  (async () => {
610
608
  this.reconnecting = true;
@@ -628,18 +626,17 @@ export class Remote {
628
626
  // 重连由 this.connect 里面调用 this._on_error 处理
629
627
  }
630
628
  })();
629
+ this.on_error(error, websocket);
631
630
  };
632
631
  _on_message = (data, websocket) => {
633
632
  this.handle(new Uint8Array(data), websocket);
634
633
  };
635
- /** 使用者自定义的在连接后出错时的处理 */
634
+ /** 使用者自定义的在 websocket 连接出错时,或者 handlers 出错时的处理 */
636
635
  on_error(error, websocket) {
637
- if (this.keeper) {
638
- if (this.print)
639
- console.log(error.message);
640
- }
641
- else
642
- throw error;
636
+ // 使用者未定义 Remote 如何处理 error 时,一般来说直接忽略即可,因为 handlers 中报错了也会返回给对端
637
+ if (this.print)
638
+ console.log(error);
639
+ // 这里继续往上层抛没有太大意义,上面一般都是 websocket on_message 这些
643
640
  }
644
641
  /** 幂等,保证 websocket 已连接,否则抛出异常
645
642
  一般情况不需要手动调用,在其它方法中会自动调用这个方法,除非需要手动建立 websocket 连接并确保成功
@@ -731,7 +728,8 @@ export class Remote {
731
728
  /** 处理接收到的 websocket message 并解析, 根据 message.id 或 message.func 分发到对应的 handler 进行处理
732
729
  如果 message.done == true 则对端指示当前 remote 可以清理 handler
733
730
  如果 handler 返回了值 (一定是数组),则包装为 message 发送
734
- 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214 */
731
+ 使用 Uint8Array 作为参数更灵活 https://stackoverflow.com/a/74505197/7609214
732
+ 这个方法一般不会抛出错误,也不需要 await,一般在 websocket on_message 时使用 */
735
733
  async handle(data, websocket) {
736
734
  const message = Remote.parse(data);
737
735
  const { id, func, done } = message;
@@ -760,7 +758,8 @@ export class Remote {
760
758
  !message.error // 防止无限循环往对方发送 error, 只有在对方无错误时才可以发送
761
759
  )
762
760
  await this.send({ id, error, /* 不能设置 done 清理对面 handler, 理由同上 */ }, websocket);
763
- throw error;
761
+ // 这里继续往上层抛没有太大意义,上面一般都是 websocket on_message 这些,交给自定义或默认的 on_error 处理
762
+ this.on_error(error);
764
763
  }
765
764
  }
766
765
  /** 调用对端 remote 中的 func, 只适用于最简单的一元 rpc (请求, 响应)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.208",
3
+ "version": "1.0.210",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -50,8 +50,8 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@babel/core": "^7.26.0",
53
- "@babel/parser": "^7.26.2",
54
- "@babel/traverse": "^7.25.9",
53
+ "@babel/parser": "^7.26.3",
54
+ "@babel/traverse": "^7.26.3",
55
55
  "@koa/cors": "^5.0.0",
56
56
  "@stylistic/eslint-plugin": "^2.11.0",
57
57
  "@svgr/webpack": "^8.1.0",
@@ -95,7 +95,7 @@
95
95
  "react-object-model": "^1.2.18",
96
96
  "resolve-path": "^1.4.0",
97
97
  "sass": "^1.82.0",
98
- "sass-loader": "^16.0.3",
98
+ "sass-loader": "^16.0.4",
99
99
  "source-map-loader": "^5.0.0",
100
100
  "strip-ansi": "^7.1.0",
101
101
  "style-loader": "^4.0.0",
@@ -113,7 +113,7 @@
113
113
  "ws": "^8.18.0"
114
114
  },
115
115
  "devDependencies": {
116
- "@babel/types": "^7.26.0",
116
+ "@babel/types": "^7.26.3",
117
117
  "@types/ali-oss": "^6.16.11",
118
118
  "@types/archiver": "^6.0.3",
119
119
  "@types/babel__traverse": "^7.20.6",
@@ -127,7 +127,7 @@
127
127
  "@types/lodash": "^4.17.13",
128
128
  "@types/mime-types": "^2.1.4",
129
129
  "@types/node": "^22.10.1",
130
- "@types/react": "^18.3.12",
130
+ "@types/react": "^18.3.13",
131
131
  "@types/through2": "^2.0.41",
132
132
  "@types/tough-cookie": "^4.0.5",
133
133
  "@types/ua-parser-js": "^0.7.39",
package/server.js CHANGED
@@ -148,16 +148,8 @@ export class Server {
148
148
  maxPayload: 2 ** 30 // 1 GB
149
149
  });
150
150
  this.websocket_server.on('connection', (ws, request) => {
151
- ws.addEventListener('message', async ({ data }) => {
152
- // 处理 funcs 中已经注册的 handlers
153
- try {
154
- await this.remote.handle(new Uint8Array(data), ws);
155
- }
156
- catch (error) {
157
- this.on_error(error);
158
- // 这里再往上扔会成为 uncaughtException 使进程退出,
159
- // 通过上面的处理应该足够了
160
- }
151
+ ws.addEventListener('message', ({ data }) => {
152
+ this.remote.handle(new Uint8Array(data), ws);
161
153
  });
162
154
  });
163
155
  const on_upgrade = this.on_upgrade.bind(this);
@@ -261,7 +253,8 @@ export class Server {
261
253
  console.log(`${error.code}:`, ctx?.request?.url);
262
254
  else {
263
255
  console.error(error);
264
- console.log('ctx:', ctx);
256
+ if (ctx)
257
+ console.log('ctx:', ctx);
265
258
  }
266
259
  }
267
260
  on_upgrade(request, socket, head) {