Skip to content

Commit

Permalink
Fix client state on Desktop (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
streamer45 authored Nov 2, 2023
1 parent 1cc67c8 commit 7d98158
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions webapp/src/components/call_widget/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ export default class CallWidget extends React.PureComponent<Props, State> {
if (this.props.global) {
sendDesktopEvent('calls-joined-call', {
callID: window.callsClient?.channelID,
sessionID: window.callsClient?.getSessionID(),
});
}

Expand Down
5 changes: 4 additions & 1 deletion webapp/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,10 @@ export default class Plugin {
}
store.dispatch({
type: DESKTOP_WIDGET_CONNECTED,
data: {channelID: ev.data.message.callID},
data: {
channel_id: ev.data.message.callID,
session_id: ev.data.message.sessionID,
},
});
} else if (ev.data?.type === 'calls-join-request') {
// we can assume that we are already in a call, since the global widget sent this.
Expand Down
32 changes: 22 additions & 10 deletions webapp/src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,38 @@ const profiles = (state: profilesState = {}, action: profilesAction) => {
}
};

type channelIDState = string | null;
type clientState = {
channelID: string;
sessionID: string;
} | null;

type channelIDAction = {
type clientStateAction = {
type: string;
data: {
channelID: string;
currentUserID: string;
userID: string;
channel_id: string;
session_id: string;
};
}

// channelID is the channel ID of the call the current user is connected to.
const channelID = (state: channelIDState = null, action: channelIDAction) => {
// clientStateReducer holds the channel and session ID for the call the current user is connected to.
// This reducer is only needed by the Desktop app client to be aware that the user is
// connected through the global widget.
const clientStateReducer = (state: clientState = null, action: clientStateAction) => {
switch (action.type) {
case UNINIT:
return null;
case DESKTOP_WIDGET_CONNECTED:
return action.data.channelID;
return {
channelID: action.data.channel_id,
sessionID: action.data.session_id,
};
case USER_LEFT:
if (action.data.session_id === state?.sessionID) {
return null;
}
return state;
case CALL_END:
if (state === action.data.channelID) {
if (action.data.channel_id === state?.channelID) {
return null;
}
return state;
Expand Down Expand Up @@ -895,7 +907,7 @@ const dismissedCalls = (state: { [callID: string]: boolean } = {}, action: RingN

export default combineReducers({
channels,
channelID,
clientStateReducer,
profiles,

// DEPRECATED - Needed to keep compatibility with older MM server
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {pluginId} from './manifest';
const pluginState = (state: GlobalState) => state['plugins-' + pluginId] || {};

export const channelIDForCurrentCall = (state: GlobalState): string =>
pluginState(state).channelID || window.callsClient?.channelID || window.opener?.callsClient?.channelID || '';
window.callsClient?.channelID || window.opener?.callsClient?.channelID || pluginState(state).clientStateReducer?.channelID || '';

export const channelForCurrentCall: (state: GlobalState) => Channel | undefined =
createSelector(
Expand Down

0 comments on commit 7d98158

Please sign in to comment.