Some code review changes.

This commit is contained in:
aforge
2022-04-27 23:08:19 -07:00
parent e938c909a1
commit ed62fe17c5
8 changed files with 56 additions and 65 deletions
+7 -14
View File
@@ -1,21 +1,20 @@
// IncomingCallView: displays Accept & Reject buttons for incoming calls.
import React from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import Tinode from 'tinode-sdk';
import { FormattedMessage } from 'react-intl';
import AvatarUpload from '../widgets/avatar-upload.jsx';
import BadgeList from '../widgets/badge-list.jsx';
import MenuCancel from '../widgets/menu-cancel.jsx';
import { CALL_STATE_INCOMING_RECEIVED, MAX_TITLE_LENGTH } from '../config.js';
import { MAX_TITLE_LENGTH } from '../config.js';
import { CALL_STATE_INCOMING_RECEIVED } from '../constants.js';
import { makeImageUrl } from '../lib/blob-helpers.js';
import { clipStr } from '../lib/utils.js'
const RING_SOUND = new Audio("audio/phone_ring.mp3");
const RING_SOUND = new Audio('audio/phone_ring.mp3');
class IncomingCallView extends React.Component {
export default class IncomingCallView extends React.Component {
constructor(props) {
super(props);
@@ -119,12 +118,8 @@ class IncomingCallView extends React.Component {
}
render() {
const {formatMessage} = this.props.intl;
let panelTitle = 'Unknown';
if (this.props.callState == CALL_STATE_INCOMING_RECEIVED) {
panelTitle = <FormattedMessage id="calls_incoming_title"
defaultMessage="Incoming Call" description="Incoming call title (Incoming call view)" />;
}
let panelTitle = <FormattedMessage id="calls_incoming_title"
defaultMessage="Incoming Call" description="Incoming call title (Incoming call view)" />;
return (
<div id="info-view">
@@ -170,5 +165,3 @@ class IncomingCallView extends React.Component {
);
}
};
export default injectIntl(IncomingCallView);
+12 -3
View File
@@ -21,10 +21,12 @@ import SendMessage from '../widgets/send-message.jsx';
import { DEFAULT_P2P_ACCESS_MODE, IMAGE_PREVIEW_DIM, KEYPRESS_DELAY,
MESSAGES_PAGE, MAX_EXTERN_ATTACHMENT_SIZE, MAX_IMAGE_DIM, MAX_INBAND_ATTACHMENT_SIZE,
READ_DELAY, QUOTED_REPLY_LENGTH, CALL_STATE_OUTGOING_INITATED, CALL_STATE_IN_PROGRESS } from '../config.js';
READ_DELAY, QUOTED_REPLY_LENGTH } from '../config.js';
import { CALL_STATE_OUTGOING_INITATED, CALL_STATE_IN_PROGRESS } from '../constants.js';
import { blobToBase64, fileToBase64, imageScaled, makeImageUrl } from '../lib/blob-helpers.js';
import HashNavigation from '../lib/navigation.js';
import { bytesToHumanSize, shortDateFormat } from '../lib/strformat.js';
import { isVideoCall } from '../lib/utils.js';
// Run timer with this frequency (ms) for checking notification queue.
const NOTIFICATION_EXEC_INTERVAL = 300;
@@ -177,7 +179,6 @@ class MessagesView extends React.Component {
if (prevState.topic && !Tinode.isNewGroupTopicName(prevState.topic)) {
this.leave(prevState.topic);
if (prevState.rtcPanel) {
console.log('hangup: ', prevState.topic);
this.handleCallHangup(prevState.topic, prevProps.callSeq);
}
}
@@ -1146,13 +1147,21 @@ class MessagesView extends React.Component {
);
prevDate = thisDate;
}
let duration;
if (msg.head && isVideoCall(msg.head.mime)) {
topic.messageVersions(msg, (cur, before, unused1, unused2) => {
if (cur.content == 'finished' && before.content == 'accepted') {
duration = msg.ts - before.ts;
}
});
}
messageNodes.push(
<ChatMessage
tinode={this.props.tinode}
content={msg.content}
mimeType={msg.head ? msg.head.mime : null}
timestamp={msg.ts}
duration={msg.origTs ? msg.ts - msg.origTs : null}
duration={duration}
response={isReply}
seq={msg.seq}
isGroup={groupTopic}
+13 -14
View File
@@ -18,9 +18,10 @@ import MessagesView from './messages-view.jsx';
import SidepanelView from './sidepanel-view.jsx';
import { API_KEY, APP_NAME, DEFAULT_P2P_ACCESS_MODE, FORWARDED_PREVIEW_LENGTH, LOGGING_ENABLED,
MEDIA_BREAKPOINT, RECEIVED_DELAY,
CALL_STATE_NONE, CALL_STATE_OUTGOING_INITATED,
CALL_STATE_INCOMING_RECEIVED, CALL_STATE_IN_PROGRESS } from '../config.js';
MEDIA_BREAKPOINT, RECEIVED_DELAY } from '../config.js';
import { CALL_STATE_NONE, CALL_STATE_OUTGOING_INITATED,
CALL_STATE_INCOMING_RECEIVED, CALL_STATE_IN_PROGRESS,
CALL_MESSAGE_MIME_TYPE } from '../constants.js';
import { PACKAGE_VERSION } from '../version.js';
import { base64ReEncode, makeImageUrl } from '../lib/blob-helpers.js';
import { detectServerAddress, isLocalHost, isSecureConnection } from '../lib/host-name.js';
@@ -1037,7 +1038,7 @@ class TinodeWeb extends React.Component {
// TODO: check if return is required.
return topic.publishDraft(msg, Promise.all(completion))
.then(_ => {
.then((ctrl) => {
if (topic.isArchived()) {
topic.archive(false);
}
@@ -1698,11 +1699,10 @@ class TinodeWeb extends React.Component {
handleCallInvite(callTopic, callSeq, callState) {
switch (callState) {
case CALL_STATE_OUTGOING_INITATED:
let head = {mime: 'application/tinode-video-call'};
let head = {mime: CALL_MESSAGE_MIME_TYPE };
this.handleSendMessage('started', undefined, undefined, head)
.then((ctrl) => {
if (ctrl.code < 200 || ctrl.code >= 300 ||
typeof ctrl.params == 'undefined' || typeof ctrl.params['seq'] == 'undefined') {
if (ctrl.code < 200 || ctrl.code >= 300 || !ctrl.params || !ctrl.params.seq) {
this.handleCallClose();
return;
}
@@ -1715,7 +1715,7 @@ class TinodeWeb extends React.Component {
return;
}
// We've accepted the call. Let the other side know.
topic.call('accept', callSeq).catch((err) => {
topic.videoCall('accept', callSeq).catch((err) => {
this.handleCallClose();
this.handleError(err.message, 'err');
});
@@ -1729,7 +1729,7 @@ class TinodeWeb extends React.Component {
return;
}
topic.call('ringing', callSeq);
topic.videoCall('ringing', callSeq);
}
handleCallHangup(callTopic, callSeq) {
@@ -1738,7 +1738,7 @@ class TinodeWeb extends React.Component {
return;
}
topic.call('hang-up', callSeq);
topic.videoCall('hang-up', callSeq);
}
handleCallSendOffer(callTopic, callSeq, sdp) {
@@ -1747,7 +1747,7 @@ class TinodeWeb extends React.Component {
return;
}
topic.call('offer', callSeq, sdp);
topic.videoCall('offer', callSeq, sdp);
}
handleCallIceCandidate(callTopic, callSeq, candidate) {
@@ -1756,7 +1756,7 @@ class TinodeWeb extends React.Component {
return;
}
topic.call('ice-candidate', callSeq, candidate);
topic.videoCall('ice-candidate', callSeq, candidate);
}
handleCallSendAnswer(callTopic, callSeq, sdp) {
const topic = this.tinode.getTopic(callTopic);
@@ -1764,7 +1764,7 @@ class TinodeWeb extends React.Component {
return;
}
topic.call('answer', callSeq, sdp);
topic.videoCall('answer', callSeq, sdp);
}
handleCallClose() {
@@ -1802,7 +1802,6 @@ class TinodeWeb extends React.Component {
}
switch (info.event) {
case 'invite':
console.log('invite: ', info);
if (info.from != this.state.myUserId) {
// Incoming call.
this.setState({