Skip to content

Commit

Permalink
Merge pull request #14 from trixtateam/fix/disconnect_socket
Browse files Browse the repository at this point in the history
fix: dont disconnect socket on error
  • Loading branch information
jacqueswho authored Jun 11, 2021
2 parents ac2795e + 9426e09 commit 424d58c
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 62 deletions.
22 changes: 10 additions & 12 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ export function* socketConnectedSaga({ isAnonymous, socket, domainKey }) {
* @param {string} params.domainKey - domain for socket
*/
export function* socketErrorSaga({ error, socketState, domainKey }) {
// here you should check if your token is valid or not expired, if not
// disconnect phoenix
console.error('socketErrorSaga',{ error, socketState, domainKey });
}

Expand All @@ -386,20 +388,20 @@ export function* socketErrorSaga({ error, socketState, domainKey }) {
* @param {Object} params - parameters
* @param {Object} params.socket = socket being closed
* @param {string} params.domainKey - domain for socket
* @param {boolean} params.isAnonymous - true if socket was anonymous
* @param {object} params.params - socket.params()
*/
export function* socketCloseSaga({ isAnonymous, socket, domainKey }) {
console.info('socketCloseSaga',{ isAnonymous, socket, domainKey });
export function* socketCloseSaga({ params, socket, domainKey }) {
console.info('socketCloseSaga',{ params, socket, domainKey });
}
/**
* After phoenix socket disconnects
* @param {Object} params - parameters
* @param {Object} params.socket = socket being disconnected
* @param {string} params.domainKey - domain for socket
* @param {boolean} params.isAnonymous - true if socket was anonymous
* @param {Object} params.params - socket.params()
*/
export function* socketDisconnectionSaga({ isAnonymous, socket, domainKey }) {
console.info('socketDisconnectionSaga',{ isAnonymous, socket, domainKey });
export function* socketDisconnectionSaga({ params, socket, domainKey }) {
console.info('socketDisconnectionSaga',{ params, socket, domainKey });
}

export default function* defaultSaga() {
Expand Down Expand Up @@ -439,11 +441,7 @@ const appReducer = (state = initialState, action) =>
case PHOENIX_CHANNEL_END_PROGRESS:
// when the progress for loadingStatusKey for channel has completed
{
const loadingStatusKey = _.get(
action,
'data.loadingStatusKey',
false
);
const loadingStatusKey = action.data.loadingStatusKey
if (!loadingStatusKey) {
draft.loading = false;
} else {
Expand All @@ -453,7 +451,7 @@ const appReducer = (state = initialState, action) =>
break;
case PHOENIX_CHANNEL_LOADING_STATUS:
// when the progress for loadingStatusKey is being updated
draft.loadingStatus[_.get(action, 'data.loadingStatusKey', '')] = {
draft.loadingStatus[action.data.loadingStatusKey] = {
status: true,
};
break;
Expand Down
5 changes: 2 additions & 3 deletions docs/maintenance/dependency.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Identify problems that occur and try to resolve them by rolling back the respect
**[0] PATCH UPDATES**

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

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

```
phoenix 1.3.4 → 1.5.4
phoenix 1.5.4 → 1.5.9
babel-eslint 10.0.3 → 10.1.0
@babel/core ^7.10.5 → ^7.11.1
@babel/preset-env ^7.10.4 → ^7.11.0
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trixta/phoenix-to-redux",
"version": "3.5.0-beta.0",
"version": "3.5.1-beta.0",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -69,13 +69,13 @@
"node": ">=6"
},
"peerDependencies": {
"phoenix": "~1.5.4",
"phoenix": "~1.5.9",
"reselect": ">=4.0.0",
"immer": ">=8.0.1"
},
"dependencies": {
"immer": ">=8.0.1",
"phoenix": "1.5.4"
"immer": "~8.0.1",
"phoenix": "~1.5.9"
},
"devDependencies": {
"@babel/cli": "^7.10.5",
Expand Down
30 changes: 15 additions & 15 deletions src/constants/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ export const channelStatuses = {
};

export const channelActionTypes = {
CHANNEL_JOIN: 'PHOENIX_CHANNEL_JOIN',
CHANNEL_LEAVE: 'PHOENIX_CHANNEL_LEAVE',
CHANNEL_PUSH: 'PHOENIX_CHANNEL_PUSH',
CHANNEL_CLOSE: 'PHOENIX_CHANNEL_CLOSE',
CHANNEL_PUSH_ERROR: 'PHOENIX_CHANNEL_PUSH_ERROR',
CHANNEL_JOIN_ERROR: 'PHOENIX_CHANNEL_JOIN_ERROR',
CHANNEL_ERROR: 'PHOENIX_CHANNEL_ERROR',
CHANNEL_TIMEOUT: 'PHOENIX_CHANNEL_TIMEOUT',
CHANNEL_PRESENCE_LOG: 'PHOENIX_CHANNEL_PRESENCE_LOG',
CHANNEL_UPDATED: 'PHOENIX_CHANNEL_UPDATED',
CHANNEL_PRESENCE_UPDATE: 'PHOENIX_CHANNEL_PRESENCE_UPDATE',
CHANNEL_PRESENCE_LEAVE: 'PHOENIX_CHANNEL_PRESENCE_LEAVE',
CHANNEL_PRESENCE_JOIN: 'PHOENIX_CHANNEL_PRESENCE_JOIN',
CHANNEL_PRESENCE_STATE: 'PHOENIX_CHANNEL_PRESENCE_STATE',
CHANNEL_PRESENCE_CHANGE: 'PHOENIX_CHANNEL_PRESENCE_CHANGE',
CHANNEL_JOIN: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_JOIN',
CHANNEL_LEAVE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_LEAVE',
CHANNEL_PUSH: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PUSH',
CHANNEL_CLOSE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_CLOSE',
CHANNEL_PUSH_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PUSH_ERROR',
CHANNEL_JOIN_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_JOIN_ERROR',
CHANNEL_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_ERROR',
CHANNEL_TIMEOUT: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_TIMEOUT',
CHANNEL_PRESENCE_LOG: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_LOG',
CHANNEL_UPDATED: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_UPDATED',
CHANNEL_PRESENCE_UPDATE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_UPDATE',
CHANNEL_PRESENCE_LEAVE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_LEAVE',
CHANNEL_PRESENCE_JOIN: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_JOIN',
CHANNEL_PRESENCE_STATE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_STATE',
CHANNEL_PRESENCE_CHANGE: '@trixta/phoenix-to-redux-event/PHOENIX_CHANNEL_PRESENCE_CHANGE',
};

export const phoenixChannelStatuses = {
Expand Down
10 changes: 5 additions & 5 deletions src/constants/socket.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const socketActionTypes = {
SOCKET_OPEN: 'PHOENIX_SOCKET_OPEN',
SOCKET_CLOSE: 'PHOENIX_SOCKET_CLOSE',
SOCKET_ERROR: 'PHOENIX_SOCKET_ERROR',
SOCKET_CONNECT: 'PHOENIX_SOCKET_CONNECT',
SOCKET_DISCONNECT: 'PHOENIX_SOCKET_DISCONNECT',
SOCKET_OPEN: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_OPEN',
SOCKET_CLOSE: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_CLOSE',
SOCKET_ERROR: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_ERROR',
SOCKET_CONNECT: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_CONNECT',
SOCKET_DISCONNECT: '@trixta/phoenix-to-redux-event/PHOENIX_SOCKET_DISCONNECT',
};

export const socketStatuses = {
Expand Down
7 changes: 1 addition & 6 deletions src/middlewares/phoenix/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
PHOENIX_CHANNEL_END_PROGRESS,
PHOENIX_CHANNEL_LOADING_STATUS,
socketActionTypes,
socketStatuses,
} from '../../../constants';
import {
formatSocketDomain,
Expand Down Expand Up @@ -291,15 +290,11 @@ export function setUpSocket({ dispatch, domain, params }) {
socket = new Socket(domainUrl, { params });
socket.connect();
socket.onError((error) => {
const connectionState = socket.connectionState();
if (connectionState === socketStatuses.CLOSED || connectionState === socketStatuses.CLOSING) {
dispatch(disconnectPhoenix());
}
dispatch(
phoenixSocketError({
domainKey: getDomainKeyFromUrl({ domainUrl }),
error,
socketState: connectionState,
socketState: socket.connectionState(),
})
);
});
Expand Down
10 changes: 5 additions & 5 deletions src/middlewares/phoenix/phoenixChannelMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import {
PHOENIX_LEAVE_CHANNEL,
PHOENIX_LEAVE_CHANNEL_EVENTS,
PHOENIX_PUSH_TO_CHANNEL,
socketStatuses
socketStatuses,
} from '../../constants';
import {
selectPhoenixSocket,
selectPhoenixSocketDetails,
selectPhoenixSocketDomain
selectPhoenixSocketDomain,
} from '../../selectors/socket/selectors';
import {
formatSocketDomain,
getDomainKeyFromUrl,
hasValidSocket,
isEqual,
isNullOrEmpty
isNullOrEmpty,
} from '../../utils';
import {
connectToPhoenixChannelForEvents,
Expand All @@ -29,7 +29,7 @@ import {
leaveChannel,
leaveEventsForPhoenixChannel,
setUpSocket,
updatePhoenixChannelLoadingStatus
updatePhoenixChannelLoadingStatus,
} from './actions';
import { phoenixChannelPushError, phoenixChannelTimeOut } from './actions/channel';
import { disconnectPhoenixSocket } from './actions/socket';
Expand Down Expand Up @@ -79,7 +79,7 @@ export const createPhoenixChannelMiddleware = () => (store) => (next) => (action
const socket = selectPhoenixSocket(currentState);
const domainKey = selectPhoenixSocketDomain(currentState);
if (socket && !isNullOrEmpty(socket) && socket.disconnect) {
socket.disconnect();
socket.disconnect(null, 1000, 'Intentionally disconnecting socket');
dispatch(disconnectPhoenixSocket({ domainKey, socket }));
}
return store.getState();
Expand Down
1 change: 0 additions & 1 deletion src/reducers/phoenixReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export const phoenixReducer = (state = initialState, action) =>
if (action.channel) {
draft.channelPresence[action.channel.topic].users = action.list;
}

break;
case socketActionTypes.SOCKET_OPEN:
draft.socketStatus = socketStatuses.CONNECTED;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5511,10 +5511,10 @@ performance-now@^2.1.0:
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=

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

picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1, picomatch@^2.2.2:
version "2.2.2"
Expand Down

0 comments on commit 424d58c

Please sign in to comment.