Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: socket params is not a function #50

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@trixtateam/phoenix-to-redux",
"version": "1.2.1",
"version": "1.2.2-beta.1",
"publishConfig": {
"access": "public"
},
Expand Down
11 changes: 7 additions & 4 deletions src/middlewares/phoenix/actions/socket/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { socketActionTypes } from '../../../../constants';
import { getSocketParams } from '../../../../services/socket';

/** Should an error occur from the phoenix socket, this action will be dispatched
* @param {Object} params - parameters
Expand All @@ -25,7 +26,7 @@ export function phoenixSocketError({ error, socketState, domainKey }) {
export function openPhoenixSocket({ socket, domainKey }) {
return {
type: socketActionTypes.SOCKET_OPEN,
params: socket.params(),
params: getSocketParams(socket),
socket,
domainKey,
};
Expand All @@ -37,12 +38,14 @@ export function openPhoenixSocket({ socket, domainKey }) {
* @param {Object} params - parameters
* @param {string} params.domainKey - domain for socket
* @param {Object} params.socket = socket being opened
* @param {Object=} [params.options = {}] parameters.options - socket options
* @param {Object=} params.options = {} parameters.options - socket options
*/

export function connectPhoenixSocket({ socket, domainKey, options }) {
return {
type: socketActionTypes.SOCKET_CONNECT,
socket,
params: getSocketParams(socket),
options,
domainKey,
};
Expand All @@ -58,7 +61,7 @@ export function connectPhoenixSocket({ socket, domainKey, options }) {
export function closePhoenixSocket({ domainKey, socket }) {
return {
type: socketActionTypes.SOCKET_CLOSE,
params: socket.params(),
params: getSocketParams(socket),
domainKey,
socket,
};
Expand All @@ -73,7 +76,7 @@ export function closePhoenixSocket({ domainKey, socket }) {
export function disconnectPhoenixSocket({ domainKey, socket }) {
return {
type: socketActionTypes.SOCKET_DISCONNECT,
params: socket.params(),
params: getSocketParams(socket),
domainKey,
socket,
};
Expand Down
6 changes: 3 additions & 3 deletions src/middlewares/phoenix/phoenixChannelMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const createPhoenixChannelMiddleware = () => (store) => (next) => (action
const currentState = getState();
let { socket } = socketService;
const socketDetails = selectPhoenixSocketDetails(currentState);
const socketOptions = selectPhoenixSocketOptions(currentState);
const options = selectPhoenixSocketOptions(currentState);
const phoenixDomain = selectPhoenixSocketDomain(currentState);
const socketDomain = socket ? socket.endPoint : '';
const { channelTopic, domainUrl, events, channelToken, logPresence, additionalData } =
Expand All @@ -218,7 +218,7 @@ export const createPhoenixChannelMiddleware = () => (store) => (next) => (action

const connectionState = socket && socket.connectionState();
if (!socket || (connectionState === socketStatuses.CLOSED && socket.closeWasClean)) {
socket = socketService.initialize(domain, socketDetails, socketOptions);
socket = socketService.initialize(domain, socketDetails, options);
if (socket) {
socket.onError((error) =>
dispatch(
Expand All @@ -232,7 +232,7 @@ export const createPhoenixChannelMiddleware = () => (store) => (next) => (action
socket.onOpen(() => dispatch(openPhoenixSocket({ socket, domainKey })));
socket.onClose(() => dispatch(closePhoenixSocket({ socket, domainKey })));
socket.connect();
dispatch(connectPhoenixSocket({ domainKey, socket, options: socketOptions }));
dispatch(connectPhoenixSocket({ domainKey, socket, options }));
}
}
dispatch(
Expand Down
7 changes: 3 additions & 4 deletions src/reducers/phoenixReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
import produce from 'immer';
import { channelActionTypes, socketActionTypes, socketStatuses } from '../constants';
import { getDomainKeyFromUrl } from '../services/helpers';

export const initialState = {
socket: false,
Expand Down Expand Up @@ -51,9 +50,9 @@ export const phoenixReducer = (state = initialState, action) =>
case socketActionTypes.SOCKET_CONNECT:
draft.socketStatus = socketStatuses.CONNECTING;
draft.channels = {};
draft.details = action.socket.params();
draft.options = action.socket.options;
draft.domain = getDomainKeyFromUrl(action.socket.endPoint);
draft.details = action.params;
draft.options = action.options;
draft.domain = action.domainKey;
draft.socket = action.socket;
break;
case socketActionTypes.SOCKET_DISCONNECT:
Expand Down
3 changes: 3 additions & 0 deletions src/services/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// https://gist.github.com/reggi/923c6704104dd50395e5
import { Socket } from 'phoenix';

export const getSocketParams = (s) =>
s ? (typeof s.params === 'function' ? s.params() : s.params) : undefined;

export const socketService = {
socket: undefined,
domain: undefined,
Expand Down
Loading