forked from Ivasoft/mattermost-mobile
move currentCall creation into userJoined event (#6571)
This commit is contained in:
committed by
GitHub
parent
7da253e310
commit
59c03b7b36
@@ -19,6 +19,7 @@ import {
|
||||
useCallsState,
|
||||
useChannelsWithCalls,
|
||||
useCurrentCall,
|
||||
userJoinedCall,
|
||||
} from '@calls/state';
|
||||
import {
|
||||
Call,
|
||||
@@ -88,6 +89,7 @@ const addFakeCall = (serverUrl: string, channelId: string) => {
|
||||
ownerId: 'xohi8cki9787fgiryne716u84o',
|
||||
} as Call;
|
||||
act(() => {
|
||||
State.setCallsState(serverUrl, {serverUrl, myUserId: 'myUserId', calls: {}, enabled: {}});
|
||||
State.callStarted(serverUrl, call);
|
||||
});
|
||||
};
|
||||
@@ -138,6 +140,7 @@ describe('Actions.Calls', () => {
|
||||
let response: { data?: string };
|
||||
await act(async () => {
|
||||
response = await CallsActions.joinCall('server1', 'channel-id');
|
||||
userJoinedCall('server1', 'channel-id', 'myUserId');
|
||||
});
|
||||
|
||||
assert.equal(response!.data, 'channel-id');
|
||||
@@ -161,6 +164,7 @@ describe('Actions.Calls', () => {
|
||||
let response: { data?: string };
|
||||
await act(async () => {
|
||||
response = await CallsActions.joinCall('server1', 'channel-id');
|
||||
userJoinedCall('server1', 'channel-id', 'myUserId');
|
||||
});
|
||||
assert.equal(response!.data, 'channel-id');
|
||||
assert.equal((result.current[1] as CurrentCall | null)?.channelId, 'channel-id');
|
||||
@@ -188,6 +192,7 @@ describe('Actions.Calls', () => {
|
||||
let response: { data?: string };
|
||||
await act(async () => {
|
||||
response = await CallsActions.joinCall('server1', 'channel-id');
|
||||
userJoinedCall('server1', 'channel-id', 'myUserId');
|
||||
});
|
||||
assert.equal(response!.data, 'channel-id');
|
||||
assert.equal((result.current[1] as CurrentCall | null)?.channelId, 'channel-id');
|
||||
@@ -214,6 +219,7 @@ describe('Actions.Calls', () => {
|
||||
let response: { data?: string };
|
||||
await act(async () => {
|
||||
response = await CallsActions.joinCall('server1', 'channel-id');
|
||||
userJoinedCall('server1', 'channel-id', 'myUserId');
|
||||
});
|
||||
assert.equal(response!.data, 'channel-id');
|
||||
assert.equal((result.current[1] as CurrentCall | null)?.channelId, 'channel-id');
|
||||
|
||||
@@ -7,7 +7,6 @@ import {forceLogoutIfNecessary} from '@actions/remote/session';
|
||||
import {fetchUsersByIds} from '@actions/remote/user';
|
||||
import {
|
||||
getCallsConfig, getCallsState,
|
||||
myselfJoinedCall,
|
||||
myselfLeftCall,
|
||||
setCalls,
|
||||
setChannelEnabled,
|
||||
@@ -201,7 +200,6 @@ export const joinCall = async (serverUrl: string, channelId: string): Promise<{
|
||||
|
||||
try {
|
||||
await connection.waitForReady();
|
||||
myselfJoinedCall(serverUrl, channelId);
|
||||
return {data: channelId};
|
||||
} catch (e) {
|
||||
connection.disconnect();
|
||||
|
||||
@@ -24,7 +24,6 @@ import {
|
||||
setCallScreenOn,
|
||||
setCallScreenOff,
|
||||
setRaisedHand,
|
||||
myselfJoinedCall,
|
||||
myselfLeftCall,
|
||||
setChannelEnabled,
|
||||
setScreenShareURL,
|
||||
@@ -460,12 +459,25 @@ describe('useCallsState', () => {
|
||||
myUserId: 'myUserId',
|
||||
calls: {'channel-1': call1, 'channel-2': call2},
|
||||
};
|
||||
const newCall1 = {
|
||||
...call1,
|
||||
participants: {
|
||||
...call1.participants,
|
||||
myUserId: {id: 'myUserId', muted: true, raisedHand: 0},
|
||||
},
|
||||
};
|
||||
const expectedCallsState = {
|
||||
...initialCallsState,
|
||||
calls: {...initialCallsState.calls,
|
||||
'channel-1': newCall1,
|
||||
},
|
||||
};
|
||||
const expectedCurrentCallState = {
|
||||
serverUrl: 'server1',
|
||||
myUserId: 'myUserId',
|
||||
screenShareURL: '',
|
||||
speakerphoneOn: false,
|
||||
...call1,
|
||||
...newCall1,
|
||||
} as CurrentCall;
|
||||
|
||||
// setup
|
||||
@@ -477,10 +489,14 @@ describe('useCallsState', () => {
|
||||
assert.deepEqual(result.current[1], null);
|
||||
|
||||
// test
|
||||
act(() => myselfJoinedCall('server1', 'channel-1'));
|
||||
assert.deepEqual(result.current[0], initialCallsState);
|
||||
act(() => userJoinedCall('server1', 'channel-1', 'myUserId'));
|
||||
assert.deepEqual(result.current[0], expectedCallsState);
|
||||
assert.deepEqual(result.current[1], expectedCurrentCallState);
|
||||
act(() => myselfLeftCall());
|
||||
|
||||
act(() => {
|
||||
myselfLeftCall();
|
||||
userLeftCall('server1', 'channel-1', 'myUserId');
|
||||
});
|
||||
assert.deepEqual(result.current[0], initialCallsState);
|
||||
assert.deepEqual(result.current[1], null);
|
||||
});
|
||||
@@ -543,13 +559,14 @@ describe('useCallsState', () => {
|
||||
assert.deepEqual(result.current[1], null);
|
||||
|
||||
// test joining a call and setting url:
|
||||
act(() => myselfJoinedCall('server1', 'channel-1'));
|
||||
act(() => userJoinedCall('server1', 'channel-1', 'myUserId'));
|
||||
assert.deepEqual((result.current[1] as CurrentCall | null)?.screenShareURL, '');
|
||||
act(() => setScreenShareURL('testUrl'));
|
||||
assert.deepEqual((result.current[1] as CurrentCall | null)?.screenShareURL, 'testUrl');
|
||||
|
||||
act(() => {
|
||||
myselfLeftCall();
|
||||
userLeftCall('server1', 'channel-1', 'myUserId');
|
||||
setScreenShareURL('test');
|
||||
});
|
||||
assert.deepEqual(result.current[0], initialCallsState);
|
||||
@@ -562,6 +579,19 @@ describe('useCallsState', () => {
|
||||
myUserId: 'myUserId',
|
||||
calls: {'channel-1': call1, 'channel-2': call2},
|
||||
};
|
||||
const newCall1 = {
|
||||
...call1,
|
||||
participants: {
|
||||
...call1.participants,
|
||||
myUserId: {id: 'myUserId', muted: true, raisedHand: 0},
|
||||
},
|
||||
};
|
||||
const expectedCallsState = {
|
||||
...initialCallsState,
|
||||
calls: {...initialCallsState.calls,
|
||||
'channel-1': newCall1,
|
||||
},
|
||||
};
|
||||
|
||||
// setup
|
||||
const {result} = renderHook(() => {
|
||||
@@ -572,18 +602,18 @@ describe('useCallsState', () => {
|
||||
assert.deepEqual(result.current[1], null);
|
||||
|
||||
// test
|
||||
act(() => myselfJoinedCall('server1', 'channel-1'));
|
||||
act(() => userJoinedCall('server1', 'channel-1', 'myUserId'));
|
||||
assert.deepEqual((result.current[1] as CurrentCall | null)?.speakerphoneOn, false);
|
||||
act(() => setSpeakerPhone(true));
|
||||
assert.deepEqual((result.current[1] as CurrentCall | null)?.speakerphoneOn, true);
|
||||
act(() => setSpeakerPhone(false));
|
||||
assert.deepEqual((result.current[1] as CurrentCall | null)?.speakerphoneOn, false);
|
||||
assert.deepEqual(result.current[0], initialCallsState);
|
||||
assert.deepEqual(result.current[0], expectedCallsState);
|
||||
act(() => {
|
||||
myselfLeftCall();
|
||||
setSpeakerPhone(true);
|
||||
});
|
||||
assert.deepEqual(result.current[0], initialCallsState);
|
||||
assert.deepEqual(result.current[0], expectedCallsState);
|
||||
assert.deepEqual(result.current[1], null);
|
||||
});
|
||||
|
||||
|
||||
@@ -45,15 +45,25 @@ export const userJoinedCall = (serverUrl: string, channelId: string, userId: str
|
||||
|
||||
// Did the user join the current call? If so, update that too.
|
||||
const currentCall = getCurrentCall();
|
||||
if (!currentCall || currentCall.channelId !== channelId) {
|
||||
return;
|
||||
if (currentCall && currentCall.channelId === channelId) {
|
||||
const nextCall2 = {
|
||||
...currentCall,
|
||||
participants: {...currentCall.participants, [userId]: nextCall.participants[userId]},
|
||||
};
|
||||
setCurrentCall(nextCall2);
|
||||
}
|
||||
|
||||
const nextCall2 = {
|
||||
...currentCall,
|
||||
participants: {...currentCall.participants, [userId]: nextCall.participants[userId]},
|
||||
};
|
||||
setCurrentCall(nextCall2);
|
||||
// Was it me that joined the call?
|
||||
if (callsState.myUserId === userId) {
|
||||
setCurrentCall({
|
||||
...nextCall,
|
||||
participants: {...nextCall.participants},
|
||||
serverUrl,
|
||||
myUserId: userId,
|
||||
screenShareURL: '',
|
||||
speakerphoneOn: false,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const userLeftCall = (serverUrl: string, channelId: string, userId: string) => {
|
||||
@@ -95,21 +105,6 @@ export const userLeftCall = (serverUrl: string, channelId: string, userId: strin
|
||||
setCurrentCall(nextCall2);
|
||||
};
|
||||
|
||||
export const myselfJoinedCall = (serverUrl: string, channelId: string) => {
|
||||
const callsState = getCallsState(serverUrl);
|
||||
|
||||
const participants = callsState.calls[channelId]?.participants || {};
|
||||
setCurrentCall({
|
||||
...callsState.calls[channelId],
|
||||
serverUrl,
|
||||
myUserId: callsState.myUserId,
|
||||
participants,
|
||||
channelId,
|
||||
screenShareURL: '',
|
||||
speakerphoneOn: false,
|
||||
});
|
||||
};
|
||||
|
||||
export const myselfLeftCall = () => {
|
||||
setCurrentCall(null);
|
||||
};
|
||||
@@ -122,18 +117,6 @@ export const callStarted = (serverUrl: string, call: Call) => {
|
||||
|
||||
const nextChannelsWithCalls = {...getChannelsWithCalls(serverUrl), [call.channelId]: true};
|
||||
setChannelsWithCalls(serverUrl, nextChannelsWithCalls);
|
||||
|
||||
// Was it the current call? If so, we started it, and need to fill in the currentCall's details.
|
||||
const currentCall = getCurrentCall();
|
||||
if (!currentCall || currentCall.channelId !== call.channelId) {
|
||||
return;
|
||||
}
|
||||
|
||||
const nextCurrentCall = {
|
||||
...currentCall,
|
||||
...call,
|
||||
};
|
||||
setCurrentCall(nextCurrentCall);
|
||||
};
|
||||
|
||||
export const callEnded = (serverUrl: string, channelId: string) => {
|
||||
|
||||
Reference in New Issue
Block a user