helper.heartbeat.js
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
/* globals java, sling, com, use */
use(function() {
'use strict';
// Acceptable delay in ms for devices connected to author directly
var ACCEPTABLE_DELAY_LATE = 3 * 1000;
// Acceptable delay in ms for devices connected via publish instances
var ACCEPTABLE_REMOTE_DELAY_LATE = 30 * 1000;
function connectionInfo(deviceStatus) {
var lastPing = deviceStatus ? deviceStatus.getLastPing().getTime() : 0;
var inactiveTime = java.lang.System.currentTimeMillis() - lastPing;
// Read the ping frequency in seconds from the OSGi Configuration
var deviceService = sling.getService(com.adobe.cq.screens.device.DeviceService);
var pingFrequency = deviceService.getPingFrequency() * 1000;
var PING_LATE_TIMEOUT = pingFrequency + ACCEPTABLE_DELAY_LATE;
var PING_LOST_TIMEOUT = pingFrequency + 3 * ACCEPTABLE_DELAY_LATE;
// If the device status originates from a publish, the ping delays need adjustment, see CQ-4227095
if (deviceStatus && deviceStatus.isFromRemote()) {
// Frequency by which the author obtains device stati from publish instances
pingFrequency = 60 * 1000;
PING_LATE_TIMEOUT = pingFrequency + ACCEPTABLE_REMOTE_DELAY_LATE;
PING_LOST_TIMEOUT = pingFrequency + 3 * ACCEPTABLE_REMOTE_DELAY_LATE;
}
return {
isPingLate: inactiveTime > PING_LATE_TIMEOUT,
isPingLost: inactiveTime > PING_LOST_TIMEOUT
};
}
return {
connectionInfo: connectionInfo
};
});