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

Commit

Permalink
Add analytics to meet low level
Browse files Browse the repository at this point in the history
  • Loading branch information
alimtunc committed Jul 3, 2023
1 parent 6cb5c69 commit 32e3d18
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions core/modules/meet/client/meet-low-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Template.meetLowLevel.onCreated(function () {
this.connectionStarted = false
this.room = undefined
this.roomName = undefined
this.usersIdsInCall = []
this.usersInCall = {}

this.autorun(() => {
if (!Meteor.userId()) return
Expand Down Expand Up @@ -75,7 +75,7 @@ Template.meetLowLevel.helpers({
return Template.instance().avatarURL.get()
},
isActive() {
return Template.instance().connection.get() !== undefined && Template.instance().usersIdsInCall.length > 0
return Template.instance().connection.get() !== undefined && getCallCount(Template.instance()) > 0
},
remoteTracks() {
console.log(
Expand Down Expand Up @@ -288,7 +288,7 @@ const onConferenceJoined = (template) => {
console.log('conference joined!')

// If the user is the only user in the conference, disconnect from the conference.
if (template.usersIdsInCall.length === 0) {
if (getCallCount(template) === 0) {
disconnect(template)
}
}
Expand Down Expand Up @@ -409,9 +409,19 @@ const onUserPropertyUpdated = async (e, template) => {
const onUsersMovedAway = (e, template) => {
const { users } = e.detail

users.forEach((user) => (template.usersIdsInCall = _.without(template.usersIdsInCall, user._id)))
users.forEach((user) => {
if (template.usersInCall[user._id]) {
const duration = (Date.now() - template.usersInCall[user._id].callStartDate) / 1000
Meteor.call('analyticsDiscussionEnd', {
peerUserId: user._id,
duration,
usersAttendingCount: getCallCount(template),
})
delete template.usersInCall[user._id]
}
})

if (template.connection.get() && template.usersIdsInCall.length === 0) {
if (template.connection.get() && getCallCount(template) === 0) {
disconnect(template)
}
}
Expand Down Expand Up @@ -446,6 +456,16 @@ const onUsersComeCloser = (e, template) => {
}

users.forEach((user) => {
if (!template.usersIdsInCall.includes(user._id)) template.usersIdsInCall.push(user._id)
if (!template.usersInCall[user._id]) {
template.usersInCall[user._id] = {
callStartDate: Date.now(),
}
Meteor.call('analyticsDiscussionAttend', {
peerUserId: user._id,
usersAttendingCount: getCallCount(template),
})
}
})
}

const getCallCount = (template) => Object.keys(template.usersInCall).length

0 comments on commit 32e3d18

Please sign in to comment.