From 47cd166c4e73220c61c9cf785621ca6bca078c66 Mon Sep 17 00:00:00 2001 From: loganathan1989 Date: Tue, 26 Mar 2019 09:24:16 +0530 Subject: [PATCH 1/3] Issue SB-11205 fix: adding ets fixes error correction from server ts --- js/core/telemetryV3Interface.js | 3 ++- js/dist/index.js | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/js/core/telemetryV3Interface.js b/js/core/telemetryV3Interface.js index 33f317f..eb9cca2 100644 --- a/js/core/telemetryV3Interface.js +++ b/js/core/telemetryV3Interface.js @@ -385,7 +385,8 @@ var Telemetry = (function() { */ instance.getEvent = function(eventId, data) { telemetryInstance.telemetryEnvelop.eid = eventId; - telemetryInstance.telemetryEnvelop.ets = (new Date()).getTime(); + telemetryInstance.telemetryEnvelop.ets = data.ets || (new Date()).getTime(); + data.ets = undefined telemetryInstance.telemetryEnvelop.ver = Telemetry._version; telemetryInstance.telemetryEnvelop.mid = ''; telemetryInstance.telemetryEnvelop.actor = Object.assign({}, { "id": Telemetry.config.uid || 'anonymous', "type": 'User' }, instance.getUpdatedValue('actor')); diff --git a/js/dist/index.js b/js/dist/index.js index a5a691a..a5789d5 100644 --- a/js/dist/index.js +++ b/js/dist/index.js @@ -2255,7 +2255,8 @@ var Telemetry = (function() { */ instance.getEvent = function(eventId, data) { telemetryInstance.telemetryEnvelop.eid = eventId; - telemetryInstance.telemetryEnvelop.ets = (new Date()).getTime(); + telemetryInstance.telemetryEnvelop.ets = data.ets || (new Date()).getTime(); + data.ets = undefined telemetryInstance.telemetryEnvelop.ver = Telemetry._version; telemetryInstance.telemetryEnvelop.mid = ''; telemetryInstance.telemetryEnvelop.actor = Object.assign({}, { "id": Telemetry.config.uid || 'anonymous', "type": 'User' }, instance.getUpdatedValue('actor')); @@ -2373,6 +2374,9 @@ var Telemetry = (function() { }, audio: { timeout: 1000, + // On iOS 11, audio context can only be used in response to user interaction. + // We require users to explicitly enable audio fingerprinting on iOS 11. + // See https://stackoverflow.com/questions/46363048/onaudioprocess-not-called-on-ios11#46534088 excludeIOS11: true }, fonts: { @@ -2382,6 +2386,7 @@ var Telemetry = (function() { extendedJsFonts: false }, screen: { + // To ensure consistent fingerprints when users rotate their mobile devices detectScreenOrientation: true }, plugins: { From 671ea75bb78411fc5da2e8274e97de3141b858f5 Mon Sep 17 00:00:00 2001 From: loganathan1989 Date: Wed, 27 Mar 2019 09:42:08 +0530 Subject: [PATCH 2/3] Issue #SB-11205 fix: review comment fixes --- js/core/telemetryV3Interface.js | 14 ++++++++++++-- js/dist/index.js | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/js/core/telemetryV3Interface.js b/js/core/telemetryV3Interface.js index eb9cca2..c84b2a7 100644 --- a/js/core/telemetryV3Interface.js +++ b/js/core/telemetryV3Interface.js @@ -317,6 +317,16 @@ var Telemetry = (function() { } } + var calculateTsDifference = function (tsObj) { + var tsDiff = 0; + if (tsObj && tsObj.serverEts) { + var serverTime = new Date(tsObj.serverEts.slice(0, -1)); + var localTime = tsObj.localTime; + tsDiff = Math.round((serverTime.getTime() - localTime.getTime())); + } + return tsDiff; + } + /** * Which is used to initialize the telemetry in globally. * @param {object} config [Telemetry configurations] @@ -337,6 +347,7 @@ var Telemetry = (function() { } config.batchsize = config.batchsize ? (config.batchsize < 10 ? 10 : (config.batchsize > 1000 ? 1000 : config.batchsize)) : _defaultValue.batchsize; Telemetry.config = Object.assign(_defaultValue, config); + Telemetry.config.tsDiff = calculateTsDifference(Telemetry.config.tsData); Telemetry.initialized = true; telemetryInstance.dispatcher = Telemetry.config.dispatcher ? Telemetry.config.dispatcher : libraryDispatcher; instance.updateConfigurations(config); @@ -385,8 +396,7 @@ var Telemetry = (function() { */ instance.getEvent = function(eventId, data) { telemetryInstance.telemetryEnvelop.eid = eventId; - telemetryInstance.telemetryEnvelop.ets = data.ets || (new Date()).getTime(); - data.ets = undefined + telemetryInstance.telemetryEnvelop.ets = new Number(new Date().getTime()) + Telemetry.config.tsDiff; telemetryInstance.telemetryEnvelop.ver = Telemetry._version; telemetryInstance.telemetryEnvelop.mid = ''; telemetryInstance.telemetryEnvelop.actor = Object.assign({}, { "id": Telemetry.config.uid || 'anonymous', "type": 'User' }, instance.getUpdatedValue('actor')); diff --git a/js/dist/index.js b/js/dist/index.js index a5789d5..dc5f139 100644 --- a/js/dist/index.js +++ b/js/dist/index.js @@ -2187,6 +2187,16 @@ var Telemetry = (function() { } } + var calculateTsDifference = function (tsObj) { + var tsDiff = 0; + if (tsObj && tsObj.serverEts) { + var serverTime = new Date(tsObj.serverEts.slice(0, -1)); + var localTime = tsObj.localTime; + tsDiff = Math.round((serverTime.getTime() - localTime.getTime())); + } + return tsDiff; + } + /** * Which is used to initialize the telemetry in globally. * @param {object} config [Telemetry configurations] @@ -2207,6 +2217,7 @@ var Telemetry = (function() { } config.batchsize = config.batchsize ? (config.batchsize < 10 ? 10 : (config.batchsize > 1000 ? 1000 : config.batchsize)) : _defaultValue.batchsize; Telemetry.config = Object.assign(_defaultValue, config); + Telemetry.config.tsDiff = calculateTsDifference(Telemetry.config.tsData); Telemetry.initialized = true; telemetryInstance.dispatcher = Telemetry.config.dispatcher ? Telemetry.config.dispatcher : libraryDispatcher; instance.updateConfigurations(config); @@ -2255,8 +2266,7 @@ var Telemetry = (function() { */ instance.getEvent = function(eventId, data) { telemetryInstance.telemetryEnvelop.eid = eventId; - telemetryInstance.telemetryEnvelop.ets = data.ets || (new Date()).getTime(); - data.ets = undefined + telemetryInstance.telemetryEnvelop.ets = new Number(new Date().getTime()) + Telemetry.config.tsDiff; telemetryInstance.telemetryEnvelop.ver = Telemetry._version; telemetryInstance.telemetryEnvelop.mid = ''; telemetryInstance.telemetryEnvelop.actor = Object.assign({}, { "id": Telemetry.config.uid || 'anonymous', "type": 'User' }, instance.getUpdatedValue('actor')); From 0bc027d60d6f67421392a90acfbfad9ef5f7e34c Mon Sep 17 00:00:00 2001 From: loganathan1989 Date: Wed, 27 Mar 2019 17:31:21 +0530 Subject: [PATCH 3/3] Issue #SB-11205 fix: review comment fixes and test cases --- js/core/telemetryV3Interface.js | 6 ++--- js/dist/index.js | 6 ++--- js/test/spec/telemetryV3Interface.spec.js | 32 +++++++++++++++++++++++ 3 files changed, 38 insertions(+), 6 deletions(-) diff --git a/js/core/telemetryV3Interface.js b/js/core/telemetryV3Interface.js index c84b2a7..4d9326a 100644 --- a/js/core/telemetryV3Interface.js +++ b/js/core/telemetryV3Interface.js @@ -319,8 +319,8 @@ var Telemetry = (function() { var calculateTsDifference = function (tsObj) { var tsDiff = 0; - if (tsObj && tsObj.serverEts) { - var serverTime = new Date(tsObj.serverEts.slice(0, -1)); + if (tsObj && tsObj.serverTime) { + var serverTime = tsObj.serverTime; var localTime = tsObj.localTime; tsDiff = Math.round((serverTime.getTime() - localTime.getTime())); } @@ -347,7 +347,7 @@ var Telemetry = (function() { } config.batchsize = config.batchsize ? (config.batchsize < 10 ? 10 : (config.batchsize > 1000 ? 1000 : config.batchsize)) : _defaultValue.batchsize; Telemetry.config = Object.assign(_defaultValue, config); - Telemetry.config.tsDiff = calculateTsDifference(Telemetry.config.tsData); + Telemetry.config.tsDiff = calculateTsDifference(Telemetry.config.timeStampData); Telemetry.initialized = true; telemetryInstance.dispatcher = Telemetry.config.dispatcher ? Telemetry.config.dispatcher : libraryDispatcher; instance.updateConfigurations(config); diff --git a/js/dist/index.js b/js/dist/index.js index dc5f139..781abca 100644 --- a/js/dist/index.js +++ b/js/dist/index.js @@ -2189,8 +2189,8 @@ var Telemetry = (function() { var calculateTsDifference = function (tsObj) { var tsDiff = 0; - if (tsObj && tsObj.serverEts) { - var serverTime = new Date(tsObj.serverEts.slice(0, -1)); + if (tsObj && tsObj.serverTime) { + var serverTime = tsObj.serverTime; var localTime = tsObj.localTime; tsDiff = Math.round((serverTime.getTime() - localTime.getTime())); } @@ -2217,7 +2217,7 @@ var Telemetry = (function() { } config.batchsize = config.batchsize ? (config.batchsize < 10 ? 10 : (config.batchsize > 1000 ? 1000 : config.batchsize)) : _defaultValue.batchsize; Telemetry.config = Object.assign(_defaultValue, config); - Telemetry.config.tsDiff = calculateTsDifference(Telemetry.config.tsData); + Telemetry.config.tsDiff = calculateTsDifference(Telemetry.config.timeStampData); Telemetry.initialized = true; telemetryInstance.dispatcher = Telemetry.config.dispatcher ? Telemetry.config.dispatcher : libraryDispatcher; instance.updateConfigurations(config); diff --git a/js/test/spec/telemetryV3Interface.spec.js b/js/test/spec/telemetryV3Interface.spec.js index 804012f..1d29b6e 100644 --- a/js/test/spec/telemetryV3Interface.spec.js +++ b/js/test/spec/telemetryV3Interface.spec.js @@ -563,5 +563,37 @@ describe("Telemetry tests", function() { telemetryObj.initialize(config); expect(telemetryObj.initialize).toHaveBeenCalled(); }) + it("It should calculate and add timestamp difference to config when valid timestamp object is present", function() { + var localTime = new Date(); + localTime.setSeconds(localTime.getSeconds()+10); + EkTelemetry.initialized = false; + spyOn(telemetryObj, 'initialize').and.callThrough(); + module = 'undefined' + console.log("Module", module) + config.pdata = { "id": "in.ekstep", "ver": "1.0", "pid": "" } + config.runningEnv = 'client'; + config.batchsize = 9; + config.uid = '343242'; + config.did = '4335345435' + config.channel = 'in.ekstep.' + config.timeStampData = {serverTime: new Date(),localTime: localTime} + telemetryObj.initialize(config); + expect(EkTelemetry.config.tsDiff).not.toEqual(0) + }) + it("It should consider 0 as timestamp difference when timestamp object is not present", function() { + EkTelemetry.initialized = false; + spyOn(telemetryObj, 'initialize').and.callThrough(); + module = 'undefined' + console.log("Module", module) + config.pdata = { "id": "in.ekstep", "ver": "1.0", "pid": "" } + config.runningEnv = 'client'; + config.batchsize = 9; + config.uid = '343242'; + config.did = '4335345435' + config.channel = 'in.ekstep.' + config.timeStampData = undefined + telemetryObj.initialize(config); + expect(EkTelemetry.config.tsDiff).toEqual(0) + }) }) }); \ No newline at end of file