Skip to content

Commit

Permalink
closes #3416 and RocketChat#3830
Browse files Browse the repository at this point in the history
  • Loading branch information
rrzharikov committed Mar 1, 2019
1 parent 36a0fc3 commit 2880f00
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 86 deletions.
69 changes: 69 additions & 0 deletions client/lib/jitsiCallClasses/JitsiCallHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { Meteor } from 'meteor/meteor';
import toastr from 'toastr';
import { modal } from 'meteor/rocketchat:ui-utils';
import { t } from 'meteor/rocketchat:utils';
import { FlowRouter } from 'meteor/kadira:flow-router';

export class JitsiCallHandler {
static getAudioElement() {
return document.getElementById('jitsi-sound');
}

constructor(payload) {
if (payload === undefined) {
throw new Error('Parameter payload is required');
}
this.payload = payload;
this.audioElement = JitsiCallHandler.getAudioElement();
}

handle() {
if (Meteor.userId() !== this.payload.sender._id) {
this.playIncomeSound();
this.showIncomeModal();
}
}

playIncomeSound() {
this.audioElement.play();
}

stopIncomeSound() {
this.audioElement.pause();
}

showIncomeModal() {
modal.open({
title: `${ t('Video_Conference_From') } ${ this.payload.sender.username }`,
text: t('Accept_video_call'),
type: 'warning',
showCancelButton: true,
confirmButtonText: t('Yes'),
cancelButtonText: t('Cancel'),
allowOutsideClick: false,
html: false,
}, () => {
this.goToCallingRoom();
}, () => {
this.stopIncomeSound();
this.rejectCall();
});
}

goToCallingRoom() {
this.stopIncomeSound();
toastr.info('Connecting...');
FlowRouter.goToRoomByIdWithParams(this.payload.rid, { forceJitsiConnection: 1, jitsiMessage: this.payload._id });
// after that render room and joinToJitsiConference( messageId ) activate
}

rejectCall() {
// when someone reject a call, a system message is sent to the room
Meteor.call('jitsi:rejectCall', this.payload.rid);
}

static rejectCallGlobal() {
JitsiCallHandler.getAudioElement().pause();
modal.close();
}
}
11 changes: 11 additions & 0 deletions client/lib/jitsiCallClasses/callDetector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { JitsiCallHandler } from './JitsiCallHandler';

export default function(payload) {
if (payload.message.t === 'jitsi_call_finished_creator') {
JitsiCallHandler.rejectCallGlobal();
}
if (payload.message.t !== 'jitsi_call_started') {
return;
}
return new JitsiCallHandler(payload);
}
16 changes: 16 additions & 0 deletions client/lib/jitsiCallMessages/messageTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
import { MessageTypes } from 'meteor/rocketchat:ui-utils';

Meteor.startup(function() {
MessageTypes.registerType({
id: 'jitsi_call_rejected',
system: true,
message: TAPi18n.__('Rejected_a_video_call'),
});
MessageTypes.registerType({
id: 'jitsi_call_finished_creator',
system: true,
message: TAPi18n.__('Finished_a_video_call_creator'),
});
});
3 changes: 3 additions & 0 deletions client/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import '../imports/startup/client';
import '../lib/RegExp';
import '../lib/francocatena_fix';

import './lib/jitsiCallMessages/messageTypes';
import './lib/jitsiCallClasses/callDetector';
import './lib/jitsiCallClasses/JitsiCallHandler';
import './lib/toastr';
import './helpers/escapeCssUrl';
import './helpers/log';
Expand Down
7 changes: 7 additions & 0 deletions client/notifications/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { Notifications } from 'meteor/rocketchat:notifications';
// We trust the server to only send notifications for interesting messages, e.g. direct messages or
// group messages in which the user is mentioned.

import callDetector from '../lib/jitsiCallClasses/callDetector';
import { JitsiCallHandler } from '../lib/jitsiCallClasses/JitsiCallHandler';

function notifyNewRoom(sub) {

// Do not play new room sound if user is busy
Expand All @@ -28,6 +31,10 @@ Meteor.startup(function() {
Tracker.autorun(function() {
if (Meteor.userId()) {
Notifications.onUser('notification', function(notification) {
const callJitsiMessage = callDetector(notification.payload);
if (callJitsiMessage instanceof JitsiCallHandler) {
callJitsiMessage.handle();
}

let openedRoomId = undefined;
if (['channel', 'group', 'direct'].includes(FlowRouter.getRouteName())) {
Expand Down
7 changes: 7 additions & 0 deletions client/routes/roomRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ FlowRouter.goToRoomById = async(rid) => {
const room = await call('getRoomById', rid);
return roomTypes.openRouteLink(room.t, room, FlowRouter.current().queryParams);
};

FlowRouter.goToRoomByIdWithParams = (roomId, queryParams) => {
const subscription = ChatSubscription.findOne({ rid: roomId });
if (subscription) {
roomTypes.openRouteLink(subscription.t, subscription, queryParams);
}
};
4 changes: 4 additions & 0 deletions packages/rocketchat-i18n/i18n/de.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2537,9 +2537,12 @@
"Start_of_conversation": "Beginn des Gesprächs",
"Start_OTR": "OTR starten",
"Start_video_call": "Videoanruf starten",
"Accept_video_call": "Videoanruf Zu akzeptieren",
"Start_video_conference": "Eine Video-Konferenz starten?",
"Start_with_s_for_user_or_s_for_channel_Eg_s_or_s": "Starte mit <code class=\"inline\">%s</code> für Nutzer oder <code class=\"inline\">%s</code> für Kanäle. Beispiel: <code class=\"inline\">%s</code> oder <code class=\"inline\">%s</code>",
"Started_a_video_call": "Ein Video-Anruf wurde gestartet",
"Rejected_a_video_call": "Video-Anruf abgelehnt",
"Finished_a_video_call_creator": "Video-Anruf vom Konferenzersteller abgeschlossen",
"Started_At": "Gestartet um",
"Statistics": "Statistiken",
"Statistics_reporting": "Sende Statistiken an Rocket.Chat",
Expand Down Expand Up @@ -2897,6 +2900,7 @@
"Video Conference": "Video-Konferenz",
"Video_Chat_Window": "Video-Chat",
"Video_Conference": "Video-Konferenz",
"Video_Conference_From": "Eingehende Video-Konferenz von ",
"Video_message": "Videonachricht",
"Videocall_declined": "Videoanruf abgelehnt",
"Videocall_enabled": "Videoanruf aktiviert",
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2616,9 +2616,12 @@
"Start_of_conversation": "Start of conversation",
"Start_OTR": "Start OTR",
"Start_video_call": "Start video call",
"Accept_video_call": "Accept video call",
"Start_video_conference": "Start video conference?",
"Start_with_s_for_user_or_s_for_channel_Eg_s_or_s": "Start with <code class=\"inline\">%s</code> for user or <code class=\"inline\">%s</code> for channel. Eg: <code class=\"inline\">%s</code> or <code class=\"inline\">%s</code>",
"Started_a_video_call": "Started a Video Call",
"Rejected_a_video_call": "Video Call rejected",
"Finished_a_video_call_creator": "Video сall completed by conference creator",
"Started": "Started",
"Started_At": "Started At",
"Statistics": "Statistics",
Expand Down Expand Up @@ -2982,6 +2985,7 @@
"Video Conference": "Video Conference",
"Video_Chat_Window": "Video Chat",
"Video_Conference": "Video Conference",
"Video_Conference_From": "Incoming Video Conference from ",
"Video_message": "Video message",
"Videocall_declined": "Video Call Declined.",
"Videocall_enabled": "Video Call Enabled",
Expand Down
4 changes: 4 additions & 0 deletions packages/rocketchat-i18n/i18n/ru.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2547,9 +2547,12 @@
"Start_of_conversation": "Начало беседы",
"Start_OTR": "Начать конфиденциальную беседу",
"Start_video_call": "Начать видеозвонок",
"Accept_video_call": "Принять видеозвонок",
"Start_video_conference": "Начать видео конференцию?",
"Start_with_s_for_user_or_s_for_channel_Eg_s_or_s": "Начните с <code class=\"inline\">%s</code> для пользователя или <code class=\"inline\">%s</code> для канала. Например: <code class=\"inline\">%s</code> или <code class=\"inline\">%s</code>",
"Started_a_video_call": "Начать видеозвонок",
"Rejected_a_video_call": "Видеозвонок отклонён",
"Finished_a_video_call_creator": "Видеозвонок завершён создателем конференции",
"Started_At": "Начато",
"Statistics": "Статистика",
"Statistics_reporting": "Отправлять статистику в Rocket.Chat",
Expand Down Expand Up @@ -2904,6 +2907,7 @@
"Video Conference": "Видеоконференция",
"Video_Chat_Window": "Видеочат",
"Video_Conference": "Видеоконференция",
"Video_Conference_From": "Входящий видеовызов от ",
"Video_message": "Видеосообщение",
"Videocall_declined": "Видео-звонок отклонён.",
"Videocall_enabled": "Включить видеозвонки",
Expand Down
1 change: 1 addition & 0 deletions packages/rocketchat-ui-master/client/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
{{> status}}
</div>
{{> audioNotification }}
{{> audioNotificationJitsi }}
{{/if}}
{{/if}}
{{/unless}}
Expand Down
18 changes: 18 additions & 0 deletions packages/rocketchat-ui-message/client/startup/restoreText.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ import { Meteor } from 'meteor/meteor';
import { RoomManager } from 'meteor/rocketchat:ui-utils';
import { chatMessages } from 'meteor/rocketchat:ui';
import { callbacks } from 'meteor/rocketchat:callbacks';
import toastr from 'toastr';
import { modal } from 'meteor/rocketchat:ui-utils';
import { FlowRouter } from 'meteor/kadira:flow-router';


Meteor.startup(() => {
const joinToJitsiConference = function(messageId) {
const messageJitsiButton = $(`#${ messageId } .actionLinks li span`);
if (!messageJitsiButton.length) {
modal.close();
toastr.error('Some problem with connect to room');
throw new Error('message element dont\'t find');
}
messageJitsiButton.click();
};

callbacks.add('enter-room', () => {
setTimeout(() => {
if (!chatMessages[RoomManager.openedRoom].input) {
Expand All @@ -17,6 +30,11 @@ Meteor.startup(() => {
if (mediaQueryList.matches) {
chatMessages[RoomManager.openedRoom].input.focus();
}

const isForceJitsiConnect = Boolean(parseInt(FlowRouter.current().queryParams.forceJitsiConnection));
if (isForceJitsiConnect) {
joinToJitsiConference(FlowRouter.current().queryParams.jitsiMessage);
}
}, 200);
});
});
1 change: 1 addition & 0 deletions packages/rocketchat-ui/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import './views/modal.html';
import './views/404/roomNotFound.html';
import './views/404/invalidSecretURL.html';
import './views/app/audioNotification.html';
import './views/app/audioNotificationJitsi.html';
import './views/app/burger.html';
import './views/app/createChannel.html';
import './views/app/fullModal.html';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template name="audioNotificationJitsi">
<div id="audioNotificationJitsi">
<audio id="jitsi-sound" preload loop>
<source src="sounds/sound-call.mp3" type="audio/mpeg" />
</audio>
</div>
</template>
Loading

0 comments on commit 2880f00

Please sign in to comment.