-
Notifications
You must be signed in to change notification settings - Fork 289
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
refactor: Make CallingRepository a little more stateless #14553
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bb6256d
refactor: Make media stream switch stateless
atomrc 2464ba3
refactor: Move view-related logic to viewModel
atomrc d817407
refactor: factorize common logic
atomrc ae273db
fix types
atomrc 63252ef
fix check order
atomrc 48b49bd
add tests
atomrc 5710948
remove deprecated tests
atomrc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -692,7 +692,6 @@ export class CallingRepository { | |
const convId = this.serializeQualifiedId(conversationId); | ||
this.logger.log(`Starting a call of type "${callType}" in conversation ID "${convId}"...`); | ||
try { | ||
await this.checkConcurrentJoinedCall(conversationId, CALL_STATE.OUTGOING); | ||
conversationType = | ||
conversationType === CONV_TYPE.GROUP && this.supportsConferenceCalling | ||
? CONV_TYPE.CONFERENCE | ||
|
@@ -813,7 +812,6 @@ export class CallingRepository { | |
async answerCall(call: Call, callType?: CALL_TYPE): Promise<void> { | ||
try { | ||
callType ??= call.getSelfParticipant().sharesCamera() ? call.initialType : CALL_TYPE.NORMAL; | ||
await this.checkConcurrentJoinedCall(call.conversationId, CALL_STATE.INCOMING); | ||
|
||
const isVideoCall = callType === CALL_TYPE.VIDEO; | ||
if (!isVideoCall) { | ||
|
@@ -849,18 +847,14 @@ export class CallingRepository { | |
this.wCall?.reject(this.wUser, this.serializeQualifiedId(conversationId)); | ||
} | ||
|
||
changeCallPage(newPage: number, call: Call): void { | ||
changeCallPage(call: Call, newPage: number): void { | ||
call.currentPage(newPage); | ||
if (!this.callState.isSpeakersViewActive()) { | ||
this.requestCurrentPageVideoStreams(); | ||
this.requestCurrentPageVideoStreams(call); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now inject the call that is concerned with the paging change in order for the CallingRepo not to have to check the state |
||
} | ||
} | ||
|
||
requestCurrentPageVideoStreams(): void { | ||
const call = this.callState.joinedCall(); | ||
if (!call) { | ||
return; | ||
} | ||
requestCurrentPageVideoStreams(call: Call): void { | ||
const currentPageParticipants = call.pages()[call.currentPage()]; | ||
this.requestVideoStreams(call.conversationId, currentPageParticipants); | ||
} | ||
|
@@ -1436,7 +1430,7 @@ export class CallingRepository { | |
} | ||
|
||
call.updatePages(); | ||
this.changeCallPage(call.currentPage(), call); | ||
this.changeCallPage(call, call.currentPage()); | ||
} | ||
|
||
private readonly handleCallParticipantChanges = (convId: SerializedConversationId, membersJson: string) => { | ||
|
@@ -1715,64 +1709,6 @@ export class CallingRepository { | |
return this.apiClient.api.account.getCallConfig(limit); | ||
} | ||
|
||
private checkConcurrentJoinedCall(conversationId: QualifiedId, newCallState: CALL_STATE): Promise<void> { | ||
const idleCallStates = [CALL_STATE.INCOMING, CALL_STATE.NONE, CALL_STATE.UNKNOWN]; | ||
const activeCall = this.callState | ||
.calls() | ||
.find(call => !matchQualifiedIds(call.conversationId, conversationId) && !idleCallStates.includes(call.state())); | ||
if (!activeCall) { | ||
return Promise.resolve(); | ||
} | ||
|
||
let actionString: string; | ||
let messageString: string; | ||
let titleString: string; | ||
|
||
switch (newCallState) { | ||
case CALL_STATE.INCOMING: { | ||
actionString = t('modalCallSecondIncomingAction'); | ||
messageString = t('modalCallSecondIncomingMessage'); | ||
titleString = t('modalCallSecondIncomingHeadline'); | ||
break; | ||
} | ||
|
||
case CALL_STATE.OUTGOING: { | ||
actionString = t('modalCallSecondOutgoingAction'); | ||
messageString = t('modalCallSecondOutgoingMessage'); | ||
titleString = t('modalCallSecondOutgoingHeadline'); | ||
break; | ||
} | ||
|
||
default: { | ||
return Promise.reject(`Tried to join second call in unexpected state '${newCallState}'`); | ||
} | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
PrimaryModal.show(PrimaryModal.type.CONFIRM, { | ||
primaryAction: { | ||
action: () => { | ||
if (activeCall.state() === CALL_STATE.INCOMING) { | ||
this.rejectCall(activeCall.conversationId); | ||
} else { | ||
this.leaveCall(activeCall.conversationId, LEAVE_CALL_REASON.MANUAL_LEAVE_TO_JOIN_ANOTHER_CALL); | ||
} | ||
window.setTimeout(resolve, 1000); | ||
}, | ||
text: actionString, | ||
}, | ||
secondaryAction: { | ||
action: reject, | ||
}, | ||
text: { | ||
message: messageString, | ||
title: titleString, | ||
}, | ||
}); | ||
this.logger.warn(`Tried to join a second call while calling in conversation '${activeCall.conversationId}'.`); | ||
}); | ||
} | ||
|
||
private showNoAudioInputModal(): void { | ||
const modalOptions = { | ||
primaryAction: { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not the responsibility of the CallingRepo to check if there is a call ongoing. This has been moved to the view layer (see
CallingViewModel
)