Skip to content

Commit 6c9ae27

Browse files
renovate[bot]renovate-botMethuselah96
authored
chore(deps): update socketcluster to v16 (major) (#1167)
* chore(deps): update socketcluster to v16 * Use the right packages * stash * stash * stash * Fixes * Fixes Co-authored-by: Renovate Bot <[email protected]> Co-authored-by: Nathan Bierema <[email protected]>
1 parent 1ee787e commit 6c9ae27

File tree

16 files changed

+646
-812
lines changed

16 files changed

+646
-812
lines changed

packages/redux-devtools-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"react-redux": "^8.0.2",
6565
"redux": "^4.2.0",
6666
"redux-persist": "^6.0.0",
67-
"socketcluster-client": "^14.3.2"
67+
"socketcluster-client": "^16.1.1"
6868
},
6969
"devDependencies": {
7070
"@babel/cli": "^7.17.10",
@@ -84,7 +84,7 @@
8484
"@types/node": "^16.11.38",
8585
"@types/react": "^18.0.12",
8686
"@types/react-dom": "^18.0.5",
87-
"@types/socketcluster-client": "^13.0.5",
87+
"@types/socketcluster-client": "^16.0.0",
8888
"@types/styled-components": "^5.1.25",
8989
"@types/testing-library__jest-dom": "^5.14.3",
9090
"@types/webpack-env": "^1.17.0",

packages/redux-devtools-app/src/actions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SchemeName, ThemeName } from '@redux-devtools/ui';
2-
import { AuthStates, States } from 'socketcluster-client/lib/scclientsocket';
2+
import { AuthStates, States } from 'socketcluster-client/lib/clientsocket';
33
import { REHYDRATE } from 'redux-persist';
44
import {
55
CHANGE_SECTION,

packages/redux-devtools-app/src/constants/socketActionTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const {
1616
AUTHENTICATED,
1717
PENDING,
1818
UNAUTHENTICATED,
19-
} = socketCluster.SCClientSocket as unknown as States;
19+
} = socketCluster.AGClientSocket as unknown as States;
2020
export const CONNECT_REQUEST = 'socket/CONNECT_REQUEST';
2121
export const CONNECT_SUCCESS = 'socket/CONNECT_SUCCESS';
2222
export const CONNECT_ERROR = 'socket/CONNECT_ERROR';

packages/redux-devtools-app/src/middlewares/api.ts

Lines changed: 96 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import socketCluster, { SCClientSocket } from 'socketcluster-client';
1+
import socketClusterClient, { AGClientSocket } from 'socketcluster-client';
22
import { stringify } from 'jsan';
33
import { Dispatch, MiddlewareAPI } from 'redux';
44
import * as actions from '../constants/socketActionTypes';
@@ -25,11 +25,16 @@ import {
2525
import { nonReduxDispatch } from '../utils/monitorActions';
2626
import { StoreState } from '../reducers';
2727

28-
let socket: SCClientSocket;
28+
let socket: AGClientSocket;
2929
let store: MiddlewareAPI<Dispatch<StoreAction>, StoreState>;
3030

3131
function emit({ message: type, id, instanceId, action, state }: EmitAction) {
32-
socket.emit(id ? `sc-${id}` : 'respond', { type, action, state, instanceId });
32+
void socket.transmit(id ? `sc-${id}` : 'respond', {
33+
type,
34+
action,
35+
state,
36+
instanceId,
37+
});
3338
}
3439

3540
function startMonitoring(channel: string) {
@@ -120,7 +125,7 @@ function monitoring(request: MonitoringRequest) {
120125
instanceId === instances.selected &&
121126
(request.type === 'ACTION' || request.type === 'STATE')
122127
) {
123-
socket.emit('respond', {
128+
void socket.transmit('respond', {
124129
type: 'SYNC',
125130
state: stringify(instances.states[instanceId]),
126131
id: request.id,
@@ -134,65 +139,84 @@ function subscribe(
134139
subscription: typeof UPDATE_STATE | typeof UPDATE_REPORTS
135140
) {
136141
const channel = socket.subscribe(channelName);
137-
if (subscription === UPDATE_STATE) channel.watch(monitoring);
138-
else {
142+
if (subscription === UPDATE_STATE) {
143+
void (async () => {
144+
for await (const data of channel) {
145+
monitoring(data as MonitoringRequest);
146+
}
147+
})();
148+
} else {
139149
const watcher = (request: UpdateReportsRequest) => {
140150
store.dispatch({ type: subscription, request });
141151
};
142-
channel.watch(watcher);
143-
socket.on(channelName, watcher);
152+
void (async () => {
153+
for await (const data of channel) {
154+
watcher(data as UpdateReportsRequest);
155+
}
156+
})();
144157
}
145158
}
146159

147160
function handleConnection() {
148-
socket.on('connect', (status) => {
149-
store.dispatch({
150-
type: actions.CONNECT_SUCCESS,
151-
payload: {
152-
id: status.id,
153-
authState: socket.authState,
154-
socketState: socket.state,
155-
},
156-
error: status.authError,
157-
});
158-
if (socket.authState !== actions.AUTHENTICATED) {
159-
store.dispatch({ type: actions.AUTH_REQUEST });
161+
void (async () => {
162+
for await (const data of socket.listener('connect')) {
163+
store.dispatch({
164+
type: actions.CONNECT_SUCCESS,
165+
payload: {
166+
id: data.id,
167+
authState: socket.authState,
168+
socketState: socket.state,
169+
},
170+
// @ts-expect-error Is this legitimate?
171+
error: data.authError,
172+
});
173+
if (socket.authState !== actions.AUTHENTICATED) {
174+
store.dispatch({ type: actions.AUTH_REQUEST });
175+
}
160176
}
161-
});
162-
socket.on('disconnect', (code) => {
163-
store.dispatch({ type: actions.DISCONNECTED, code });
164-
});
177+
})();
178+
void (async () => {
179+
for await (const data of socket.listener('disconnect')) {
180+
store.dispatch({ type: actions.DISCONNECTED, code: data.code });
181+
}
182+
})();
165183

166-
socket.on('subscribe', (channel) => {
167-
store.dispatch({ type: actions.SUBSCRIBE_SUCCESS, channel });
168-
});
169-
socket.on('unsubscribe', (channel) => {
170-
socket.unsubscribe(channel);
171-
socket.unwatch(channel);
172-
socket.off(channel);
173-
store.dispatch({ type: actions.UNSUBSCRIBE, channel });
174-
});
175-
socket.on('subscribeFail', (error) => {
176-
store.dispatch({
177-
type: actions.SUBSCRIBE_ERROR,
178-
error,
179-
status: 'subscribeFail',
180-
});
181-
});
182-
socket.on('dropOut', (error) => {
183-
store.dispatch({ type: actions.SUBSCRIBE_ERROR, error, status: 'dropOut' });
184-
});
184+
void (async () => {
185+
for await (const data of socket.listener('subscribe')) {
186+
store.dispatch({
187+
type: actions.SUBSCRIBE_SUCCESS,
188+
channel: data.channel,
189+
});
190+
}
191+
})();
192+
void (async () => {
193+
for await (const data of socket.listener('unsubscribe')) {
194+
void socket.unsubscribe(data.channel);
195+
store.dispatch({ type: actions.UNSUBSCRIBE, channel: data.channel });
196+
}
197+
})();
198+
void (async () => {
199+
for await (const data of socket.listener('subscribeFail')) {
200+
store.dispatch({
201+
type: actions.SUBSCRIBE_ERROR,
202+
error: data.error,
203+
status: 'subscribeFail',
204+
});
205+
}
206+
})();
185207

186-
socket.on('error', (error) => {
187-
store.dispatch({ type: actions.CONNECT_ERROR, error });
188-
});
208+
void (async () => {
209+
for await (const data of socket.listener('error')) {
210+
store.dispatch({ type: actions.CONNECT_ERROR, error: data.error });
211+
}
212+
})();
189213
}
190214

191215
function connect() {
192216
if (process.env.NODE_ENV === 'test') return;
193217
const connection = store.getState().connection;
194218
try {
195-
socket = socketCluster.create(connection.options);
219+
socket = socketClusterClient.create(connection.options);
196220
handleConnection();
197221
} catch (error) {
198222
store.dispatch({ type: actions.CONNECT_ERROR, error: error as Error });
@@ -205,43 +229,42 @@ function connect() {
205229
function disconnect() {
206230
if (socket) {
207231
socket.disconnect();
208-
socket.off();
209232
}
210233
}
211234

212235
function login() {
213-
socket.emit('login', {}, (error: Error, baseChannel: string) => {
214-
if (error) {
215-
store.dispatch({ type: actions.AUTH_ERROR, error });
216-
return;
236+
void (async () => {
237+
try {
238+
const baseChannel = (await socket.invoke('login', {})) as string;
239+
store.dispatch({ type: actions.AUTH_SUCCESS, baseChannel });
240+
store.dispatch({
241+
type: actions.SUBSCRIBE_REQUEST,
242+
channel: baseChannel,
243+
subscription: UPDATE_STATE,
244+
});
245+
store.dispatch({
246+
type: actions.SUBSCRIBE_REQUEST,
247+
channel: 'report',
248+
subscription: UPDATE_REPORTS,
249+
});
250+
} catch (error) {
251+
store.dispatch({ type: actions.AUTH_ERROR, error: error as Error });
217252
}
218-
store.dispatch({ type: actions.AUTH_SUCCESS, baseChannel });
219-
store.dispatch({
220-
type: actions.SUBSCRIBE_REQUEST,
221-
channel: baseChannel,
222-
subscription: UPDATE_STATE,
223-
});
224-
store.dispatch({
225-
type: actions.SUBSCRIBE_REQUEST,
226-
channel: 'report',
227-
subscription: UPDATE_REPORTS,
228-
});
229-
});
253+
})();
230254
}
231255

232256
function getReport(reportId: unknown) {
233-
socket.emit(
234-
'getReport',
235-
reportId,
236-
(error: Error, data: { payload: string }) => {
237-
if (error) {
238-
store.dispatch({ type: GET_REPORT_ERROR, error });
239-
return;
240-
}
257+
void (async () => {
258+
try {
259+
const data = (await socket.invoke('getReport', reportId)) as {
260+
payload: string;
261+
};
241262
store.dispatch({ type: GET_REPORT_SUCCESS, data });
242263
store.dispatch(importState(data.payload));
264+
} catch (error) {
265+
store.dispatch({ type: GET_REPORT_ERROR, error: error as Error });
243266
}
244-
);
267+
})();
245268
}
246269

247270
export function api(inStore: MiddlewareAPI<Dispatch<StoreAction>, StoreState>) {

packages/redux-devtools-app/src/reducers/socket.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthStates, States } from 'socketcluster-client/lib/scclientsocket';
1+
import { AuthStates, States } from 'socketcluster-client/lib/clientsocket';
22
import * as actions from '../constants/socketActionTypes';
33
import { StoreAction } from '../actions';
44

packages/redux-devtools-cli/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"react-dom": "^18.1.0",
6161
"react-is": "^18.1.0",
6262
"semver": "^7.3.7",
63-
"socketcluster": "^14.4.2",
63+
"socketcluster-server": "^16.2.1",
6464
"sqlite3": "^5.0.8",
6565
"styled-components": "^5.3.5",
6666
"uuid": "^8.3.2"
@@ -76,9 +76,8 @@
7676
"@types/morgan": "^1.9.3",
7777
"@types/node": "^16.11.38",
7878
"@types/semver": "^7.3.9",
79-
"@types/socketcluster": "^14.0.4",
80-
"@types/socketcluster-client": "^13.0.5",
81-
"@types/socketcluster-server": "^14.2.6",
79+
"@types/socketcluster-client": "^16.0.0",
80+
"@types/socketcluster-server": "^16.1.0",
8281
"@types/styled-components": "^5.1.25",
8382
"@types/supertest": "^2.0.12",
8483
"@types/uuid": "^8.3.4",
@@ -90,7 +89,7 @@
9089
"jest": "^27.5.1",
9190
"ncp": "^2.0.0",
9291
"rimraf": "^3.0.2",
93-
"socketcluster-client": "^14.3.2",
92+
"socketcluster-client": "^16.1.1",
9493
"supertest": "^6.2.3",
9594
"ts-jest": "^27.1.5",
9695
"typescript": "~4.7.3"

packages/redux-devtools-cli/src/bin/redux-devtools.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ if (argv.injectserver) {
8888
}
8989

9090
// eslint-disable-next-line @typescript-eslint/no-floating-promises
91-
server(argv).then(function (r) {
91+
server(argv).then(async function (r) {
9292
if (argv.open && argv.open !== 'false') {
93-
r.on('ready', async function () {
94-
await openApp(argv.open as string, options);
95-
});
93+
await r.listener('ready').once();
94+
await openApp(argv.open as string, options);
9695
}
9796
});

packages/redux-devtools-cli/src/db/connector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import path from 'path';
22
import knexModule, { Knex } from 'knex';
3-
import { SCServer } from 'socketcluster-server';
3+
import { AGServer } from 'socketcluster-server';
44

5-
export default function connector(options: SCServer.SCServerOptions) {
5+
export default function connector(options: AGServer.AGServerOptions) {
66
const dbOptions = options.dbOptions as Knex.Config;
77
dbOptions.useNullAsDefault = true;
88
if (!(dbOptions as any).migrate) {

0 commit comments

Comments
 (0)