Skip to content

Commit 9426e09

Browse files
fix: dont disconnect socket on error
1 parent ac2795e commit 9426e09

File tree

10 files changed

+53
-62
lines changed

10 files changed

+53
-62
lines changed

docs/README.md

+10-12
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ export function* socketConnectedSaga({ isAnonymous, socket, domainKey }) {
377377
* @param {string} params.domainKey - domain for socket
378378
*/
379379
export function* socketErrorSaga({ error, socketState, domainKey }) {
380+
// here you should check if your token is valid or not expired, if not
381+
// disconnect phoenix
380382
console.error('socketErrorSaga',{ error, socketState, domainKey });
381383
}
382384

@@ -386,20 +388,20 @@ export function* socketErrorSaga({ error, socketState, domainKey }) {
386388
* @param {Object} params - parameters
387389
* @param {Object} params.socket = socket being closed
388390
* @param {string} params.domainKey - domain for socket
389-
* @param {boolean} params.isAnonymous - true if socket was anonymous
391+
* @param {object} params.params - socket.params()
390392
*/
391-
export function* socketCloseSaga({ isAnonymous, socket, domainKey }) {
392-
console.info('socketCloseSaga',{ isAnonymous, socket, domainKey });
393+
export function* socketCloseSaga({ params, socket, domainKey }) {
394+
console.info('socketCloseSaga',{ params, socket, domainKey });
393395
}
394396
/**
395397
* After phoenix socket disconnects
396398
* @param {Object} params - parameters
397399
* @param {Object} params.socket = socket being disconnected
398400
* @param {string} params.domainKey - domain for socket
399-
* @param {boolean} params.isAnonymous - true if socket was anonymous
401+
* @param {Object} params.params - socket.params()
400402
*/
401-
export function* socketDisconnectionSaga({ isAnonymous, socket, domainKey }) {
402-
console.info('socketDisconnectionSaga',{ isAnonymous, socket, domainKey });
403+
export function* socketDisconnectionSaga({ params, socket, domainKey }) {
404+
console.info('socketDisconnectionSaga',{ params, socket, domainKey });
403405
}
404406

405407
export default function* defaultSaga() {
@@ -439,11 +441,7 @@ const appReducer = (state = initialState, action) =>
439441
case PHOENIX_CHANNEL_END_PROGRESS:
440442
// when the progress for loadingStatusKey for channel has completed
441443
{
442-
const loadingStatusKey = _.get(
443-
action,
444-
'data.loadingStatusKey',
445-
false
446-
);
444+
const loadingStatusKey = action.data.loadingStatusKey
447445
if (!loadingStatusKey) {
448446
draft.loading = false;
449447
} else {
@@ -453,7 +451,7 @@ const appReducer = (state = initialState, action) =>
453451
break;
454452
case PHOENIX_CHANNEL_LOADING_STATUS:
455453
// when the progress for loadingStatusKey is being updated
456-
draft.loadingStatus[_.get(action, 'data.loadingStatusKey', '')] = {
454+
draft.loadingStatus[action.data.loadingStatusKey] = {
457455
status: true,
458456
};
459457
break;

docs/maintenance/dependency.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Identify problems that occur and try to resolve them by rolling back the respect
7474
**[0] PATCH UPDATES**
7575

7676
```
77-
phoenix 1.3.4 → 1.5.4
77+
phoenix 1.5.4 → 1.5.9
7878
@rollup/plugin-commonjs ^13.0.2 → ^14.0.0
7979
eslint 5.16.0 → 7.6.0
8080
eslint-config-airbnb 17.1.1 → 18.2.0
@@ -89,7 +89,6 @@ Identify problems that occur and try to resolve them by rolling back the respect
8989
**[1] MINOR UPDATES**
9090

9191
```
92-
lodash 4.17.15 → 4.17.19
9392
@babel/cli ^7.10.1 → ^7.10.5
9493
@babel/core ^7.10.2 → ^7.10.5
9594
@babel/preset-env ^7.10.2 → ^7.10.4
@@ -108,7 +107,7 @@ Identify problems that occur and try to resolve them by rolling back the respect
108107
**[3] MAJOR UPDATES**
109108

110109
```
111-
phoenix 1.3.4 → 1.5.4
110+
phoenix 1.5.4 → 1.5.9
112111
babel-eslint 10.0.3 → 10.1.0
113112
@babel/core ^7.10.5 → ^7.11.1
114113
@babel/preset-env ^7.10.4 → ^7.11.0

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@trixta/phoenix-to-redux",
3-
"version": "3.5.0-beta.0",
3+
"version": "3.5.1-beta.0",
44
"publishConfig": {
55
"access": "public"
66
},
@@ -69,13 +69,13 @@
6969
"node": ">=6"
7070
},
7171
"peerDependencies": {
72-
"phoenix": "~1.5.4",
72+
"phoenix": "~1.5.9",
7373
"reselect": ">=4.0.0",
7474
"immer": ">=8.0.1"
7575
},
7676
"dependencies": {
77-
"immer": ">=8.0.1",
78-
"phoenix": "1.5.4"
77+
"immer": "~8.0.1",
78+
"phoenix": "~1.5.9"
7979
},
8080
"devDependencies": {
8181
"@babel/cli": "^7.10.5",

src/constants/channel.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ export const channelStatuses = {
66
};
77

88
export const channelActionTypes = {
9-
CHANNEL_JOIN: 'PHOENIX_CHANNEL_JOIN',
10-
CHANNEL_LEAVE: 'PHOENIX_CHANNEL_LEAVE',
11-
CHANNEL_PUSH: 'PHOENIX_CHANNEL_PUSH',
12-
CHANNEL_CLOSE: 'PHOENIX_CHANNEL_CLOSE',
13-
CHANNEL_PUSH_ERROR: 'PHOENIX_CHANNEL_PUSH_ERROR',
14-
CHANNEL_JOIN_ERROR: 'PHOENIX_CHANNEL_JOIN_ERROR',
15-
CHANNEL_ERROR: 'PHOENIX_CHANNEL_ERROR',
16-
CHANNEL_TIMEOUT: 'PHOENIX_CHANNEL_TIMEOUT',
17-
CHANNEL_PRESENCE_LOG: 'PHOENIX_CHANNEL_PRESENCE_LOG',
18-
CHANNEL_UPDATED: 'PHOENIX_CHANNEL_UPDATED',
19-
CHANNEL_PRESENCE_UPDATE: 'PHOENIX_CHANNEL_PRESENCE_UPDATE',
20-
CHANNEL_PRESENCE_LEAVE: 'PHOENIX_CHANNEL_PRESENCE_LEAVE',
21-
CHANNEL_PRESENCE_JOIN: 'PHOENIX_CHANNEL_PRESENCE_JOIN',
22-
CHANNEL_PRESENCE_STATE: 'PHOENIX_CHANNEL_PRESENCE_STATE',
23-
CHANNEL_PRESENCE_CHANGE: 'PHOENIX_CHANNEL_PRESENCE_CHANGE',
9+
CHANNEL_JOIN: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_JOIN',
10+
CHANNEL_LEAVE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_LEAVE',
11+
CHANNEL_PUSH: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PUSH',
12+
CHANNEL_CLOSE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_CLOSE',
13+
CHANNEL_PUSH_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PUSH_ERROR',
14+
CHANNEL_JOIN_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_JOIN_ERROR',
15+
CHANNEL_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_ERROR',
16+
CHANNEL_TIMEOUT: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_TIMEOUT',
17+
CHANNEL_PRESENCE_LOG: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_LOG',
18+
CHANNEL_UPDATED: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_UPDATED',
19+
CHANNEL_PRESENCE_UPDATE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_UPDATE',
20+
CHANNEL_PRESENCE_LEAVE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_LEAVE',
21+
CHANNEL_PRESENCE_JOIN: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_JOIN',
22+
CHANNEL_PRESENCE_STATE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_STATE',
23+
CHANNEL_PRESENCE_CHANGE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_CHANGE',
2424
};
2525

2626
export const phoenixChannelStatuses = {

src/constants/socket.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export const socketActionTypes = {
2-
SOCKET_OPEN: 'PHOENIX_SOCKET_OPEN',
3-
SOCKET_CLOSE: 'PHOENIX_SOCKET_CLOSE',
4-
SOCKET_ERROR: 'PHOENIX_SOCKET_ERROR',
5-
SOCKET_CONNECT: 'PHOENIX_SOCKET_CONNECT',
6-
SOCKET_DISCONNECT: 'PHOENIX_SOCKET_DISCONNECT',
2+
SOCKET_OPEN: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_OPEN',
3+
SOCKET_CLOSE: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_CLOSE',
4+
SOCKET_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_ERROR',
5+
SOCKET_CONNECT: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_CONNECT',
6+
SOCKET_DISCONNECT: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_DISCONNECT',
77
};
88

99
export const socketStatuses = {

src/middlewares/phoenix/actions/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
PHOENIX_CHANNEL_END_PROGRESS,
1010
PHOENIX_CHANNEL_LOADING_STATUS,
1111
socketActionTypes,
12-
socketStatuses,
1312
} from '../../../constants';
1413
import {
1514
formatSocketDomain,
@@ -291,15 +290,11 @@ export function setUpSocket({ dispatch, domain, params }) {
291290
socket = new Socket(domainUrl, { params });
292291
socket.connect();
293292
socket.onError((error) => {
294-
const connectionState = socket.connectionState();
295-
if (connectionState === socketStatuses.CLOSED || connectionState === socketStatuses.CLOSING) {
296-
dispatch(disconnectPhoenix());
297-
}
298293
dispatch(
299294
phoenixSocketError({
300295
domainKey: getDomainKeyFromUrl({ domainUrl }),
301296
error,
302-
socketState: connectionState,
297+
socketState: socket.connectionState(),
303298
})
304299
);
305300
});

src/middlewares/phoenix/phoenixChannelMiddleware.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ import {
88
PHOENIX_LEAVE_CHANNEL,
99
PHOENIX_LEAVE_CHANNEL_EVENTS,
1010
PHOENIX_PUSH_TO_CHANNEL,
11-
socketStatuses
11+
socketStatuses,
1212
} from '../../constants';
1313
import {
1414
selectPhoenixSocket,
1515
selectPhoenixSocketDetails,
16-
selectPhoenixSocketDomain
16+
selectPhoenixSocketDomain,
1717
} from '../../selectors/socket/selectors';
1818
import {
1919
formatSocketDomain,
2020
getDomainKeyFromUrl,
2121
hasValidSocket,
2222
isEqual,
23-
isNullOrEmpty
23+
isNullOrEmpty,
2424
} from '../../utils';
2525
import {
2626
connectToPhoenixChannelForEvents,
@@ -29,7 +29,7 @@ import {
2929
leaveChannel,
3030
leaveEventsForPhoenixChannel,
3131
setUpSocket,
32-
updatePhoenixChannelLoadingStatus
32+
updatePhoenixChannelLoadingStatus,
3333
} from './actions';
3434
import { phoenixChannelPushError, phoenixChannelTimeOut } from './actions/channel';
3535
import { disconnectPhoenixSocket } from './actions/socket';
@@ -79,7 +79,7 @@ export const createPhoenixChannelMiddleware = () => (store) => (next) => (action
7979
const socket = selectPhoenixSocket(currentState);
8080
const domainKey = selectPhoenixSocketDomain(currentState);
8181
if (socket && !isNullOrEmpty(socket) && socket.disconnect) {
82-
socket.disconnect();
82+
socket.disconnect(null, 1000, 'Intentionally disconnecting socket');
8383
dispatch(disconnectPhoenixSocket({ domainKey, socket }));
8484
}
8585
return store.getState();

src/reducers/phoenixReducer.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const phoenixReducer = (state = initialState, action) =>
4343
if (action.channel) {
4444
draft.channelPresence[action.channel.topic].users = action.list;
4545
}
46-
4746
break;
4847
case socketActionTypes.SOCKET_OPEN:
4948
draft.socketStatus = socketStatuses.CONNECTED;

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -5511,10 +5511,10 @@ performance-now@^2.1.0:
55115511
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
55125512
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
55135513

5514-
5515-
version "1.5.4"
5516-
resolved "https://registry.yarnpkg.com/phoenix/-/phoenix-1.5.4.tgz#d42bb537f03f55076b4e7a6757fe29318a8439f0"
5517-
integrity sha512-mTxseCKWDgrBQRIriqzvxL+QH5xruu6KQPqFdDx0jrdu/nqWCo914MLihVksn7SV2Bol3T+e/VtovJgC5UZT+w==
5514+
5515+
version "1.5.9"
5516+
resolved "https://registry.yarnpkg.com/phoenix/-/phoenix-1.5.9.tgz#5aad82072c8d90e7e20a187063c5db9b9ab9b5cd"
5517+
integrity sha512-NBRQaCYIrXL/wd5+OoO+DLlNTIdRvxKat0DSkfJ/c8qwYqKK7jNrf1GWPBOPzSVJ9HNMPjgmniJ87m9Os9IQGg==
55185518

55195519
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2:
55205520
version "2.2.2"

0 commit comments

Comments
 (0)