Move calling duration timer into redux state

This commit is contained in:
Josh Perez 2020-10-13 17:02:43 -04:00 committed by GitHub
parent 8a121f1ff7
commit 1507dea351
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 24 deletions

View file

@ -12,6 +12,7 @@ import enMessages from '../../_locales/en/messages.json';
const i18n = setupI18n('en', enMessages); const i18n = setupI18n('en', enMessages);
const callDetails = { const callDetails = {
acceptedTime: Date.now(),
callId: 0, callId: 0,
isIncoming: true, isIncoming: true,
isVideoCall: true, isVideoCall: true,

View file

@ -30,7 +30,6 @@ export type PropsType = {
}; };
type StateType = { type StateType = {
acceptedTime: number | null;
acceptedDuration: number | null; acceptedDuration: number | null;
showControls: boolean; showControls: boolean;
}; };
@ -48,7 +47,6 @@ export class CallScreen extends React.Component<PropsType, StateType> {
super(props); super(props);
this.state = { this.state = {
acceptedTime: null,
acceptedDuration: null, acceptedDuration: null,
showControls: true, showControls: true,
}; };
@ -89,21 +87,15 @@ export class CallScreen extends React.Component<PropsType, StateType> {
} }
updateAcceptedTimer = (): void => { updateAcceptedTimer = (): void => {
const { acceptedTime } = this.state; const { callDetails } = this.props;
const { callState } = this.props;
if (acceptedTime) { if (!callDetails) {
return;
}
if (callDetails.acceptedTime) {
this.setState({ this.setState({
acceptedTime, acceptedDuration: Date.now() - callDetails.acceptedTime,
acceptedDuration: Date.now() - acceptedTime,
});
} else if (
callState === CallState.Accepted ||
callState === CallState.Reconnecting
) {
this.setState({
acceptedTime: Date.now(),
acceptedDuration: 1,
}); });
} }
}; };

View file

@ -206,7 +206,7 @@ export class CallingClass {
this.attachToCall(conversation, call); this.attachToCall(conversation, call);
this.uxActions.outgoingCall({ this.uxActions.outgoingCall({
callDetails: this.getUxCallDetails(conversation, call), callDetails: this.getAcceptedCallDetails(conversation, call),
}); });
} }
@ -702,7 +702,7 @@ export class CallingClass {
this.attachToCall(conversation, call); this.attachToCall(conversation, call);
this.uxActions.incomingCall({ this.uxActions.incomingCall({
callDetails: this.getUxCallDetails(conversation, call), callDetails: this.getAcceptedCallDetails(conversation, call),
}); });
window.log.info('CallingClass.handleIncomingCall(): Proceeding'); window.log.info('CallingClass.handleIncomingCall(): Proceeding');
@ -745,7 +745,7 @@ export class CallingClass {
} }
uxActions.callStateChange({ uxActions.callStateChange({
callState: call.state, callState: call.state,
callDetails: this.getUxCallDetails(conversation, call), callDetails: this.getAcceptedCallDetails(conversation, call),
callEndedReason: call.endedReason, callEndedReason: call.endedReason,
}); });
}; };
@ -825,17 +825,18 @@ export class CallingClass {
}; };
} }
private getUxCallDetails( private getAcceptedCallDetails(
conversation: ConversationModel, conversation: ConversationModel,
call: Call call: Call
): CallDetailsType { ): CallDetailsType {
const conversationProps = conversation.cachedProps; const conversationProps = conversation.cachedProps;
if (!conversationProps) { if (!conversationProps) {
throw new Error('getUxCallDetails: No conversation props?'); throw new Error('getAcceptedCallDetails: No conversation props?');
} }
return { return {
...conversationProps, ...conversationProps,
acceptedTime: Date.now(),
callId: call.callId, callId: call.callId,
isIncoming: call.isIncoming, isIncoming: call.isIncoming,
isVideoCall: call.isVideoCall, isVideoCall: call.isVideoCall,

View file

@ -21,6 +21,7 @@ import {
export type CallId = unknown; export type CallId = unknown;
export type CallDetailsType = { export type CallDetailsType = {
acceptedTime?: number;
callId: CallId; callId: CallId;
isIncoming: boolean; isIncoming: boolean;
isVideoCall: boolean; isVideoCall: boolean;

View file

@ -12847,7 +12847,7 @@
"rule": "React-createRef", "rule": "React-createRef",
"path": "ts/components/CallScreen.js", "path": "ts/components/CallScreen.js",
"line": " this.localVideoRef = react_1.default.createRef();", "line": " this.localVideoRef = react_1.default.createRef();",
"lineNumber": 94, "lineNumber": 87,
"reasonCategory": "usageTrusted", "reasonCategory": "usageTrusted",
"updated": "2020-09-14T23:03:44.863Z" "updated": "2020-09-14T23:03:44.863Z"
}, },
@ -12855,7 +12855,7 @@
"rule": "React-createRef", "rule": "React-createRef",
"path": "ts/components/CallScreen.js", "path": "ts/components/CallScreen.js",
"line": " this.remoteVideoRef = react_1.default.createRef();", "line": " this.remoteVideoRef = react_1.default.createRef();",
"lineNumber": 95, "lineNumber": 88,
"reasonCategory": "usageTrusted", "reasonCategory": "usageTrusted",
"updated": "2020-09-14T23:03:44.863Z" "updated": "2020-09-14T23:03:44.863Z"
}, },
@ -12863,7 +12863,7 @@
"rule": "React-createRef", "rule": "React-createRef",
"path": "ts/components/CallScreen.tsx", "path": "ts/components/CallScreen.tsx",
"line": " this.localVideoRef = React.createRef();", "line": " this.localVideoRef = React.createRef();",
"lineNumber": 58, "lineNumber": 56,
"reasonCategory": "usageTrusted", "reasonCategory": "usageTrusted",
"updated": "2020-06-02T21:51:34.813Z", "updated": "2020-06-02T21:51:34.813Z",
"reasonDetail": "Used to render local preview video" "reasonDetail": "Used to render local preview video"
@ -12872,7 +12872,7 @@
"rule": "React-createRef", "rule": "React-createRef",
"path": "ts/components/CallScreen.tsx", "path": "ts/components/CallScreen.tsx",
"line": " this.remoteVideoRef = React.createRef();", "line": " this.remoteVideoRef = React.createRef();",
"lineNumber": 59, "lineNumber": 57,
"reasonCategory": "usageTrusted", "reasonCategory": "usageTrusted",
"updated": "2020-09-14T23:03:44.863Z" "updated": "2020-09-14T23:03:44.863Z"
}, },