Use enums where possible

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-06-02 10:42:58 +02:00
parent b202f997e3
commit 3331e7bfbe
No known key found for this signature in database
GPG key ID: 9760693FDD98A790

View file

@ -21,7 +21,7 @@ import { _t, _td } from '../../../languageHandler';
import MemberAvatar from '../avatars/MemberAvatar'; import MemberAvatar from '../avatars/MemberAvatar';
import CallEventGrouper, { CallEventGrouperEvent, CustomCallState } from '../../structures/CallEventGrouper'; import CallEventGrouper, { CallEventGrouperEvent, CustomCallState } from '../../structures/CallEventGrouper';
import FormButton from '../elements/FormButton'; import FormButton from '../elements/FormButton';
import { CallState } from 'matrix-js-sdk/src/webrtc/call'; import { CallErrorCode, CallState } from 'matrix-js-sdk/src/webrtc/call';
import InfoTooltip, { InfoTooltipKind } from '../elements/InfoTooltip'; import InfoTooltip, { InfoTooltipKind } from '../elements/InfoTooltip';
interface IProps { interface IProps {
@ -79,7 +79,7 @@ export default class CallEvent extends React.Component<IProps, IState> {
if (state === CallState.Ended) { if (state === CallState.Ended) {
const hangupReason = this.props.callEventGrouper.hangupReason; const hangupReason = this.props.callEventGrouper.hangupReason;
if (["user_hangup", "user hangup"].includes(hangupReason) || !hangupReason) { if ([CallErrorCode.UserHangup, "user hangup"].includes(hangupReason) || !hangupReason) {
// workaround for https://github.com/vector-im/element-web/issues/5178 // workaround for https://github.com/vector-im/element-web/issues/5178
// it seems Android randomly sets a reason of "user hangup" which is // it seems Android randomly sets a reason of "user hangup" which is
// interpreted as an error code :( // interpreted as an error code :(
@ -94,13 +94,13 @@ export default class CallEvent extends React.Component<IProps, IState> {
} }
let reason; let reason;
if (hangupReason === "ice_failed") { if (hangupReason === CallErrorCode.IceFailed) {
// We couldn't establish a connection at all // We couldn't establish a connection at all
reason = _t("Could not connect media"); reason = _t("Could not connect media");
} else if (hangupReason === "ice_timeout") { } else if (hangupReason === "ice_timeout") {
// We established a connection but it died // We established a connection but it died
reason = _t("Connection failed"); reason = _t("Connection failed");
} else if (hangupReason === "user_media_failed") { } else if (hangupReason === CallErrorCode.NoUserMedia) {
// The other side couldn't open capture devices // The other side couldn't open capture devices
reason = _t("Their device couldn't start the camera or microphone"); reason = _t("Their device couldn't start the camera or microphone");
} else if (hangupReason === "unknown_error") { } else if (hangupReason === "unknown_error") {
@ -108,9 +108,9 @@ export default class CallEvent extends React.Component<IProps, IState> {
// (as opposed to an error code they gave but we don't know about, // (as opposed to an error code they gave but we don't know about,
// in which case we show the error code) // in which case we show the error code)
reason = _t("An unknown error occurred"); reason = _t("An unknown error occurred");
} else if (hangupReason === "invite_timeout") { } else if (hangupReason === CallErrorCode.InviteTimeout) {
reason = _t("No answer"); reason = _t("No answer");
} else if (hangupReason === "user_busy") { } else if (hangupReason === CallErrorCode.UserBusy) {
reason = _t("The user you called is busy."); reason = _t("The user you called is busy.");
} else { } else {
reason = _t('Unknown failure: %(reason)s)', {reason: hangupReason}); reason = _t('Unknown failure: %(reason)s)', {reason: hangupReason});