@ -32,10 +32,16 @@ import type { PaginatedResult } from '@rocket.chat/rest-typings';
import type { MessageSurfaceLayout } from '@rocket.chat/ui-kit' ;
import { MongoInternals } from 'meteor/mongo' ;
import { RocketChatAssets } from '../../../app/assets/server' ;
import { canAccessRoomIdAsync } from '../../../app/authorization/server/functions/canAccessRoom' ;
import { sendMessage } from '../../../app/lib/server/functions/sendMessage' ;
import { metrics } from '../../../app/metrics/server/lib/metrics' ;
import PushNotification from '../../../app/push-notifications/server/lib/PushNotification' ;
import { Push } from '../../../app/push/server/push' ;
import { settings } from '../../../app/settings/server' ;
import { updateCounter } from '../../../app/statistics/server/functions/updateStatsCounter' ;
import { getUserAvatarURL } from '../../../app/utils/server/getUserAvatarURL' ;
import { getUserPreference } from '../../../app/utils/server/lib/getUserPreference' ;
import { Apps } from '../../../ee/server/apps' ;
import { callbacks } from '../../../lib/callbacks' ;
import { availabilityErrors } from '../../../lib/videoConference/constants' ;
@ -199,6 +205,8 @@ export class VideoConfService extends ServiceClassInternal implements IVideoConf
await this . runVideoConferenceChangedEvent ( callId ) ;
this . notifyVideoConfUpdate ( call . rid , call . _id ) ;
await this . sendAllPushNotifications ( call . _id ) ;
}
public async get ( callId : VideoConference [ '_id' ] ) : Promise < Omit < VideoConference , ' providerData ' > | null > {
@ -583,6 +591,69 @@ export class VideoConfService extends ServiceClassInternal implements IVideoConf
} ;
}
private async sendPushNotification (
call : AtLeast < IDirectVideoConference , ' createdBy ' | ' rid ' | ' _id ' | ' status ' > ,
calleeId : IUser [ '_id' ] ,
) : Promise < void > {
if (
settings . get ( 'Push_enable' ) !== true ||
settings . get ( 'VideoConf_Mobile_Ringing' ) !== true ||
! ( await getUserPreference ( calleeId , 'enableMobileRinging' ) )
) {
return ;
}
metrics . notificationsSent . inc ( { notification_type : 'mobile' } ) ;
await Push . send ( {
from : 'push' ,
badge : 0 ,
sound : 'default' ,
priority : 10 ,
title : ` @ ${ call . createdBy . username } ` ,
text : i18n.t ( 'Video_Conference' ) ,
payload : {
host : Meteor.absoluteUrl ( ) ,
rid : call.rid ,
notificationType : 'videoconf' ,
caller : call.createdBy ,
avatar : getUserAvatarURL ( call . createdBy . username ) ,
status : call.status ,
} ,
userId : calleeId ,
notId : PushNotification.getNotificationId ( ` ${ call . rid } | ${ call . _id } ` ) ,
gcm : {
style : 'inbox' ,
image : RocketChatAssets.getURL ( 'Assets_favicon_192' ) ,
} ,
apn : {
category : 'MESSAGE_NOREPLY' ,
topicSuffix : '.voip' ,
} ,
} ) ;
}
private async sendAllPushNotifications ( callId : VideoConference [ '_id' ] ) : Promise < void > {
if ( settings . get ( 'Push_enable' ) !== true || settings . get ( 'VideoConf_Mobile_Ringing' ) !== true ) {
return ;
}
const call = await VideoConferenceModel . findOneById < Pick < VideoConference , ' createdBy ' | ' rid ' | ' _id ' | ' users ' | ' status ' > > ( callId , {
projection : { createdBy : 1 , rid : 1 , users : 1 , status : 1 } ,
} ) ;
if ( ! call ) {
return ;
}
const subscriptions = Subscriptions . findByRoomIdAndNotUserId ( call . rid , call . createdBy . _id , {
projection : { 'u._id' : 1 , '_id' : 0 } ,
} ) ;
for await ( const subscription of subscriptions ) {
await this . sendPushNotification ( call , subscription . u . _id ) ;
}
}
private async startDirect (
providerName : string ,
user : IUser ,
@ -637,6 +708,8 @@ export class VideoConfService extends ServiceClassInternal implements IVideoConf
}
} , 40000 ) ;
await this . sendPushNotification ( call , calleeId ) ;
return {
type : 'direct' ,
callId ,
@ -949,5 +1022,6 @@ export class VideoConfService extends ServiceClassInternal implements IVideoConf
this . notifyVideoConfUpdate ( call . rid , call . _id ) ;
await this . runVideoConferenceChangedEvent ( call . _id ) ;
await this . sendAllPushNotifications ( call . _id ) ;
}
}