Skip to content

Commit fc92959

Browse files
Simon-Lauxlink2xt
authored andcommitted
typescript-client: Remove dependencies on WebSockets npm packages
(`@types/ws`, `ws` and `isomorphic-ws`) Also set the minimum Node.js version to `22`, because that's the version where support for the standard WebSockets was stabilized.
1 parent 8f85557 commit fc92959

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
# Unreleased
6+
- typescript-client: Remove dependencies on WebSockets npm packages (`@types/ws`, `ws` and `isomorphic-ws`).
7+
- typescript-client: Set the minimum Node.js version to `22`, because that's the version where support for the standard WebSockets was stabilized.
8+
59
## 0.6.4 - 2025-04-17
610

711
- Remove 'anyhow:' prefix from errors.
@@ -69,4 +73,4 @@ This release adds [OpenRPC](https://open-rpc.org/) generation support.
6973

7074
## Older
7175

72-
see git commit history for older releases
76+
see git commit history for older releases

typescript/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ A TypeScript integration for the [yerpc](https://github.com/deltachat/yerpc) JSO
55
See the [main README](https://github.com/deltachat/yerpc/blob/main/README.md) for details.
66

77
*TODO: Add more docs*
8+
9+
The minimum nodejs version for this package is `22` if you want to use the `WebsocketTransport`.

typescript/package.json

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@
2828
"prepublishOnly": "run-s lint clean build"
2929
},
3030
"dependencies": {
31-
"@types/ws": "^8.2.2",
32-
"isomorphic-ws": "^4.0.1",
3331
"typescript": "^4.6.3"
3432
},
35-
"optionalDependencies": {
36-
"ws": "^8.5.0"
37-
},
3833
"devDependencies": {
3934
"esbuild": "^0.17.9",
4035
"npm-run-all": "^4.1.5",
4136
"prettier": "^2.6.2"
37+
},
38+
"engines": {
39+
"node": ">=22.0.0"
4240
}
4341
}

typescript/websocket.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import WebSocket from "isomorphic-ws";
21
import { Message } from "./jsonrpc.js";
32
import { BaseTransport } from "./client.js";
43
import { Emitter, EventsT } from "./util/emitter.js";
@@ -9,12 +8,19 @@ type WebsocketOptions = {
98
maxReconnectInterval: number;
109
};
1110

12-
export type WebSocketErrorEvent = WebSocket.ErrorEvent;
11+
type WSMessageEvent = Parameters<
12+
Exclude<typeof WebSocket.prototype.onmessage, null>
13+
>[0];
14+
type WSErrorEvent = Parameters<
15+
Exclude<typeof WebSocket.prototype.onerror, null>
16+
>[0];
17+
18+
export type WebSocketErrorEvent = WSErrorEvent;
1319

1420
export interface WebsocketEvents extends EventsT {
1521
connect: () => void;
1622
disconnect: () => void;
17-
error: (error: WebSocket.ErrorEvent) => void;
23+
error: (error: WSErrorEvent) => void;
1824
}
1925

2026
export class WebsocketTransport extends BaseTransport<WebsocketEvents> {
@@ -27,15 +33,15 @@ export class WebsocketTransport extends BaseTransport<WebsocketEvents> {
2733
}
2834
constructor(public url: string, options?: WebsocketOptions) {
2935
super();
30-
const onmessage = (event: WebSocket.MessageEvent) => {
36+
const onmessage = (event: WSMessageEvent) => {
3137
const message: Message = JSON.parse(event.data as string);
3238
this._onmessage(message);
3339
};
3440
this._socket = new ReconnectingWebsocket(url, onmessage, options);
3541

3642
this._socket.on("connect", () => this.emit("connect"));
3743
this._socket.on("disconnect", () => this.emit("disconnect"));
38-
this._socket.on("error", (error: WebSocket.ErrorEvent) =>
44+
this._socket.on("error", (error: WSErrorEvent) =>
3945
this.emit("error", error)
4046
);
4147
}
@@ -59,12 +65,12 @@ class ReconnectingWebsocket extends Emitter<WebsocketEvents> {
5965
private _connected = false;
6066
private _reconnectAttempts = 0;
6167

62-
onmessage: (event: WebSocket.MessageEvent) => void;
68+
onmessage: (event: WSMessageEvent) => void;
6369
closed = false;
6470

6571
constructor(
6672
public url: string,
67-
onmessage: (event: WebSocket.MessageEvent) => void,
73+
onmessage: (event: WSMessageEvent) => void,
6874
options?: WebsocketOptions
6975
) {
7076
super();

0 commit comments

Comments
 (0)