Merge pull request #6610 from overleaf/jk-better-editing-heartbeat

[web] CM6: improvements to editor heartbeat

GitOrigin-RevId: b0e5379d221cba76c91d6d21863ca8355749d18e
This commit is contained in:
June Kelly 2022-02-08 09:22:06 +00:00 committed by Copybot
parent fe1cb010b4
commit ef4e137676
3 changed files with 20 additions and 13 deletions

View file

@ -80,7 +80,8 @@ App.controller(
eventTracking, eventTracking,
metadata, metadata,
$q, $q,
CobrandingDataService CobrandingDataService,
$window
) { ) {
// Don't freak out if we're already in an apply callback // Don't freak out if we're already in an apply callback
let err, pdfLayout, userAgent let err, pdfLayout, userAgent
@ -256,8 +257,22 @@ If the project has been renamed please look in your project list for a new proje
return (_loaded = true) return (_loaded = true)
}) })
$scope.$on('cursor:editor:update', eventTracking.editingSessionHeartbeat) ide.editingSessionHeartbeat = () => {
$scope.$on('scroll:editor:update', eventTracking.editingSessionHeartbeat) eventTracking.editingSessionHeartbeat()
}
$scope.$on('cursor:editor:update', () => {
ide.editingSessionHeartbeat()
})
$scope.$on('scroll:editor:update', () => {
ide.editingSessionHeartbeat()
})
angular.element($window).on('click', ide.editingSessionHeartbeat)
$scope.$on('$destroy', () =>
angular.element($window).off('click', ide.editingSessionHeartbeat)
)
const DARK_THEMES = [ const DARK_THEMES = [
'ambiance', 'ambiance',

View file

@ -818,16 +818,6 @@ App.directive(
// deletes and then inserts document content // deletes and then inserts document content
session.setAnnotations(scope.annotations) session.setAnnotations(scope.annotations)
angular
.element($window)
.on('click', eventTracking.editingSessionHeartbeat)
scope.$on('$destroy', () =>
angular
.element($window)
.off('click', eventTracking.editingSessionHeartbeat)
)
if (scope.eventsBridge != null) { if (scope.eventsBridge != null) {
session.on('changeScrollTop', onScroll) session.on('changeScrollTop', onScroll)
} }

View file

@ -70,10 +70,12 @@ App.factory('eventTracking', function ($http, localStorage) {
}, },
editingSessionHeartbeat() { editingSessionHeartbeat() {
sl_console.log('[Event] heartbeat trigger')
if (!(nextHeartbeat <= new Date())) { if (!(nextHeartbeat <= new Date())) {
return return
} }
sl_console.log('[Event] send heartbeat request')
_sendEditingSessionHeartbeat() _sendEditingSessionHeartbeat()
heartbeatsSent++ heartbeatsSent++