Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
[NEW] add-jitsi-call-support
Browse files Browse the repository at this point in the history
Co-Authored-By: Deepak Agarwal <56799414+Deepak-learner@users.noreply.github.com>
  • Loading branch information
murtaza98 and Deepak-learner committed Nov 16, 2021
1 parent 5820ea5 commit 2d2ca32
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/components/Calls/CallNotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,26 @@ import { createClassName, getAvatarUrl, isMobileDevice } from '../helpers';
import styles from './styles.scss';


export const CallNotification = ({ callProvider, callerUsername, url, dispatch, time, rid, callId } = { callProvider: undefined, callerUsername: undefined, dispatch: undefined, time: undefined }) => {
export const CallNotification = ({ callProvider, callerUsername, url, dispatch, time, rid, callId } = { callProvider: undefined, callerUsername: undefined, dispatch: undefined, time: undefined, url: undefined }) => {
const [show, setShow] = useState(true);

const callInNewTab = async () => {
const { token, room } = store.state;
const url = `${ Livechat.client.host }/meet/${ room._id }?token=${ token }`;
await dispatch({ ongoingCall: { callStatus: 'ongoingCallInNewTab', time: { time } }, incomingCallAlert: { show: false, callProvider } });
window.open(url, room._id);
window.open(url, rid);
};

const acceptClick = async () => {
setShow(!{ show });
await Livechat.updateCallStatus('inProgress', rid, callId);
switch (callProvider) {
case constants.jitsiCallStartedMessageType: {
window.open(url);
window.open(url, rid);
await dispatch({ incomingCallAlert: { show: false, url, callProvider }, ongoingCall: { callStatus: 'accept', time: { time } } });
break;
}
case constants.webrtcCallStartedMessageType: {
await Livechat.updateCallStatus('inProgress', rid, callId);
if (isMobileDevice()) {
callInNewTab();
break;
Expand Down
2 changes: 1 addition & 1 deletion src/components/Calls/JoinCallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const JoinCallButton = (props) => {
const clickJoinCall = () => {
switch (props.callProvider) {
case constants.jitsiCallStartedMessageType: {
window.open(props.url);
window.open(props.url, room._id);
break;
}
case constants.webrtcCallStartedMessageType: {
Expand Down
3 changes: 2 additions & 1 deletion src/components/Messages/MessageList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { parseISO } from 'date-fns/fp';
import isSameDay from 'date-fns/isSameDay';
import { h } from 'preact';

import constants from '../../../lib/constants';
import store from '../../../store';
import { CallTime } from '../../Calls/CallTime';
import { JoinCallButton } from '../../Calls/JoinCallButton';
Expand Down Expand Up @@ -116,7 +117,7 @@ export class MessageList extends MemoizedComponent {
const { incomingCallAlert } = store.state;
const { ongoingCall } = store.state;

if (message.actionLinks && message.actionLinks.length === 2 && ongoingCall) {
if ((message.t === constants.webrtcCallStartedMessageType || message.t === constants.jitsiCallStartedMessageType) && message.actionLinks && message.actionLinks.length > 0 && ongoingCall) {
const { url, callProvider, rid } = incomingCallAlert || {};
items.push(
<JoinCallButton callStatus={ongoingCall.callStatus} url={url} callProvider={callProvider} rid={rid} />,
Expand Down
11 changes: 6 additions & 5 deletions src/lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const processCallMessage = async (message) => {
rid: message.rid,
time: message.ts,
callId: message._id,
url: message.t === constants.jitsiCallStartedMessageType ? message.customFields.jitsiCallUrl : '',
},
ongoingCall: {
callStatus: 'ring',
Expand All @@ -50,15 +51,13 @@ export const processCallMessage = async (message) => {
};

const processMessage = async (message) => {
const { incomingCallAlert } = store.state;

if (message.t === 'livechat-close') {
closeChat(message);
} else if (message.t === 'command') {
commands[message.msg] && commands[message.msg]();
} else if (message.endTs) {
await store.setState({ ongoingCall: { callStatus: 'ended', time: message.ts }, incomingCallAlert: null });
} else if (!incomingCallAlert && (message.t === constants.webrtcCallStartedMessageType || message.t === constants.jitsiCallStartedMessageType)) {
} else if (message.t === constants.webrtcCallStartedMessageType || message.t === constants.jitsiCallStartedMessageType) {
await processCallMessage(message);
}
};
Expand Down Expand Up @@ -185,7 +184,7 @@ Livechat.onMessage(async (message) => {
});

export const getGreetingMessages = (messages) => messages && messages.filter((msg) => msg.trigger);
export const getLatestCallMessage = (messages) => messages && messages.filter((msg) => msg.t === 'livechat_webrtc_video_call' || msg.t === 'livechat_video_call').pop();
export const getLatestCallMessage = (messages) => messages && messages.filter((msg) => msg.t === constants.webrtcCallStartedMessageType || msg.t === constants.jitsiCallStartedMessageType).pop();

export const loadMessages = async () => {
const { ongoingCall } = store.state;
Expand Down Expand Up @@ -213,7 +212,9 @@ export const loadMessages = async () => {
}

const latestCallMessage = getLatestCallMessage(messages);
if (callStatus === 'inProgress') {
if (latestCallMessage && latestCallMessage.t === constants.jitsiCallStartedMessageType) {
store.setState({ ongoingCall: { callStatus: 'ongoingCallInNewTab', time: latestCallMessage.ts }, incomingCallAlert: { show: false, callProvider: latestCallMessage.t, url: latestCallMessage.customFields.jitsiCallUrl } });
} else if (callStatus === 'inProgress') {
if (!latestCallMessage) {
return;
}
Expand Down

0 comments on commit 2d2ca32

Please sign in to comment.