Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit 32e3d18

Browse files
committed
Add analytics to meet low level
1 parent 6cb5c69 commit 32e3d18

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

core/modules/meet/client/meet-low-level.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Template.meetLowLevel.onCreated(function () {
2323
this.connectionStarted = false
2424
this.room = undefined
2525
this.roomName = undefined
26-
this.usersIdsInCall = []
26+
this.usersInCall = {}
2727

2828
this.autorun(() => {
2929
if (!Meteor.userId()) return
@@ -75,7 +75,7 @@ Template.meetLowLevel.helpers({
7575
return Template.instance().avatarURL.get()
7676
},
7777
isActive() {
78-
return Template.instance().connection.get() !== undefined && Template.instance().usersIdsInCall.length > 0
78+
return Template.instance().connection.get() !== undefined && getCallCount(Template.instance()) > 0
7979
},
8080
remoteTracks() {
8181
console.log(
@@ -288,7 +288,7 @@ const onConferenceJoined = (template) => {
288288
console.log('conference joined!')
289289

290290
// If the user is the only user in the conference, disconnect from the conference.
291-
if (template.usersIdsInCall.length === 0) {
291+
if (getCallCount(template) === 0) {
292292
disconnect(template)
293293
}
294294
}
@@ -409,9 +409,19 @@ const onUserPropertyUpdated = async (e, template) => {
409409
const onUsersMovedAway = (e, template) => {
410410
const { users } = e.detail
411411

412-
users.forEach((user) => (template.usersIdsInCall = _.without(template.usersIdsInCall, user._id)))
412+
users.forEach((user) => {
413+
if (template.usersInCall[user._id]) {
414+
const duration = (Date.now() - template.usersInCall[user._id].callStartDate) / 1000
415+
Meteor.call('analyticsDiscussionEnd', {
416+
peerUserId: user._id,
417+
duration,
418+
usersAttendingCount: getCallCount(template),
419+
})
420+
delete template.usersInCall[user._id]
421+
}
422+
})
413423

414-
if (template.connection.get() && template.usersIdsInCall.length === 0) {
424+
if (template.connection.get() && getCallCount(template) === 0) {
415425
disconnect(template)
416426
}
417427
}
@@ -446,6 +456,16 @@ const onUsersComeCloser = (e, template) => {
446456
}
447457

448458
users.forEach((user) => {
449-
if (!template.usersIdsInCall.includes(user._id)) template.usersIdsInCall.push(user._id)
459+
if (!template.usersInCall[user._id]) {
460+
template.usersInCall[user._id] = {
461+
callStartDate: Date.now(),
462+
}
463+
Meteor.call('analyticsDiscussionAttend', {
464+
peerUserId: user._id,
465+
usersAttendingCount: getCallCount(template),
466+
})
467+
}
450468
})
451469
}
470+
471+
const getCallCount = (template) => Object.keys(template.usersInCall).length

0 commit comments

Comments
 (0)