Skip to content

Commit

Permalink
feat: upgrade to rpc-websockets v9 (#2800)
Browse files Browse the repository at this point in the history
  • Loading branch information
steveluscher authored Jun 12, 2024
1 parent 0445a81 commit b20731d
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 75 deletions.
2 changes: 1 addition & 1 deletion packages/library-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"fast-stable-stringify": "^1.0.0",
"jayson": "^4.1.0",
"node-fetch": "^2.7.0",
"rpc-websockets": "^8.0.1",
"rpc-websockets": "^9.0.0",
"superstruct": "^1.0.4"
},
"devDependencies": {
Expand Down
8 changes: 0 additions & 8 deletions packages/library-legacy/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ function generateConfig(configType, format) {
'jayson/lib/client/browser',
'node-fetch',
'rpc-websockets',
'rpc-websockets/dist/lib/client.cjs',
'rpc-websockets/dist/lib/client/client.types.cjs',
'rpc-websockets/dist/lib/client/websocket.cjs',
'rpc-websockets/dist/lib/client/websocket.browser.cjs',
'superstruct',
];
}
Expand Down Expand Up @@ -182,10 +178,6 @@ function generateConfig(configType, format) {
'node-fetch',
'react-native-url-polyfill',
'rpc-websockets',
'rpc-websockets/dist/lib/client.cjs',
'rpc-websockets/dist/lib/client/client.types.cjs',
'rpc-websockets/dist/lib/client/websocket.cjs',
'rpc-websockets/dist/lib/client/websocket.browser.cjs',
'superstruct',
];

Expand Down

This file was deleted.

This file was deleted.

4 changes: 0 additions & 4 deletions packages/library-legacy/src/rpc-websocket-factory.ts

This file was deleted.

22 changes: 9 additions & 13 deletions packages/library-legacy/src/rpc-websocket.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client.cjs';
import WebSocketBrowserImpl from 'rpc-websockets/dist/lib/client/websocket.cjs';
import {
CommonClient,
ICommonWebSocket,
IWSClientAdditionalOptions,
NodeWebSocketType,
NodeWebSocketTypeOptions,
} from 'rpc-websockets/dist/lib/client/client.types.cjs';

import createRpc from './rpc-websocket-factory';
WebSocket as createRpc,
} from 'rpc-websockets';

interface IHasReadyState {
readyState: WebSocket['readyState'];
}

export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
export default class RpcWebSocketClient extends CommonClient {
private underlyingSocket: IHasReadyState | undefined;
constructor(
address?: string,
Expand All @@ -32,9 +30,7 @@ export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
...options,
});
if ('socket' in rpc) {
this.underlyingSocket = rpc.socket as ReturnType<
typeof WebSocketBrowserImpl
>;
this.underlyingSocket = rpc.socket as ReturnType<typeof createRpc>;
} else {
this.underlyingSocket = rpc as NodeWebSocketType;
}
Expand All @@ -43,8 +39,8 @@ export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
super(webSocketFactory, address, options, generate_request_id);
}
call(
...args: Parameters<RpcWebSocketCommonClient['call']>
): ReturnType<RpcWebSocketCommonClient['call']> {
...args: Parameters<CommonClient['call']>
): ReturnType<CommonClient['call']> {
const readyState = this.underlyingSocket?.readyState;
if (readyState === 1 /* WebSocket.OPEN */) {
return super.call(...args);
Expand All @@ -60,8 +56,8 @@ export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
);
}
notify(
...args: Parameters<RpcWebSocketCommonClient['notify']>
): ReturnType<RpcWebSocketCommonClient['notify']> {
...args: Parameters<CommonClient['notify']>
): ReturnType<CommonClient['notify']> {
const readyState = this.underlyingSocket?.readyState;
if (readyState === 1 /* WebSocket.OPEN */) {
return super.notify(...args);
Expand Down
Loading

0 comments on commit b20731d

Please sign in to comment.