Skip to content

Commit

Permalink
Add channelResponseCallback to onJoinChannel action.
Browse files Browse the repository at this point in the history
  • Loading branch information
BiruliaRaman committed Jan 5, 2022
1 parent d44de98 commit 55e6889
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/actions/channels/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,23 @@ export function leavePhoenixChannelEvent({ channelTopic, event }) {
* @param {string?} params.domainUrl - url for socket to connect to, by default will use PHOENIX_SOCKET_DOMAIN storage key
* @param {string} params.channelTopic - Name of channel/Topic
* @param {String?} params.token - token for channel
* @param {Boolean?} params.logPresence - determines if you presence should be tracked for the channel
* @param {Boolean?} params.logPresence - determines if your presence should be tracked for the channel
*/
export function getPhoenixChannel({
logPresence = false,
channelTopic,
channelResponseEvent = null,
channelErrorResponseEvent = null,
events = [],
token = null,
domainUrl = null,
token = '',
domainUrl = '',
}) {
return {
type: PHOENIX_GET_CHANNEL,
data: {
channelTopic,
channelResponseEvent,
channelErrorResponseEvent,
logPresence,
channelToken: token,
domainUrl,
Expand Down
4 changes: 4 additions & 0 deletions src/middlewares/phoenix/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ export function connectPhoenixChannelPresence({ channel, dispatch }) {
export function connectToPhoenixChannelForEvents({
dispatch,
channelTopic,
channelResponseEvent,
channelErrorResponseEvent,
logPresence,
events,
token = null,
Expand All @@ -200,13 +202,15 @@ export function connectToPhoenixChannelForEvents({
})
);
dispatch(endPhoenixChannelProgress({ channelTopic, loadingStatusKey: channelTopic }));
dispatch(channelResponseEvent({data: response, channelTopic, channel}))
})
.receive(channelStatuses.CHANNEL_ERROR, (response) => {
if (response && response.reason === 'unauthorized') {
dispatch(leavePhoenixChannel({ channelTopic }));
}
dispatch(phoenixChannelJoinError({ error: response, channelTopic, channel }));
dispatch(endPhoenixChannelProgress({ channelTopic, loadingStatusKey: channelTopic }));
dispatch(channelErrorResponseEvent({error: response, channelTopic, channel}))
})
.receive(channelStatuses.CHANNEL_TIMEOUT, (response) => {
dispatch(
Expand Down
4 changes: 3 additions & 1 deletion 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 socketDetails = selectPhoenixSocketDetails(currentState);
const phoenixDomain = selectPhoenixSocketDomain(currentState);
const socketDomain = socket ? socket.endPoint : '';
const { channelTopic, domainUrl, events, channelToken, logPresence } = action.data;
const { channelTopic, channelResponseEvent, channelErrorResponseEvent, domainUrl, events, channelToken, logPresence } = action.data;

const domain = formatSocketDomain({ domainString: domainUrl || phoenixDomain });
const loggedInDomain = `${domain}/websocket`;
Expand Down Expand Up @@ -231,6 +231,8 @@ export const createPhoenixChannelMiddleware = () => (store) => (next) => (action
connectToPhoenixChannelForEvents({
dispatch,
channelTopic,
channelResponseEvent,
channelErrorResponseEvent,
events,
logPresence,
token: channelToken,
Expand Down

0 comments on commit 55e6889

Please sign in to comment.