Support for when cookies are disabled

HFJ-1915
pull/23/head
Frode Petterson 2016-06-20 14:57:14 +02:00
parent d4d9f81518
commit a6656c2e6f
1 changed files with 16 additions and 10 deletions

View File

@ -24,7 +24,7 @@ H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent;
*/ */
H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, completion, success) { H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, completion, success) {
this.data.statement.result = {}; this.data.statement.result = {};
if (typeof score !== 'undefined') { if (typeof score !== 'undefined') {
if (typeof maxScore === 'undefined') { if (typeof maxScore === 'undefined') {
this.data.statement.result.score = {'raw': score}; this.data.statement.result.score = {'raw': score};
@ -40,22 +40,22 @@ H5P.XAPIEvent.prototype.setScoredResult = function (score, maxScore, instance, c
} }
} }
} }
if (typeof completion === 'undefined') { if (typeof completion === 'undefined') {
this.data.statement.result.completion = (this.getVerb() === 'completed' || this.getVerb() === 'answered'); this.data.statement.result.completion = (this.getVerb() === 'completed' || this.getVerb() === 'answered');
} }
else { else {
this.data.statement.result.completion = completion; this.data.statement.result.completion = completion;
} }
if (typeof success !== 'undefined') { if (typeof success !== 'undefined') {
this.data.statement.result.success = success; this.data.statement.result.success = success;
} }
if (instance && instance.activityStartTime) { if (instance && instance.activityStartTime) {
var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100; var duration = Math.round((Date.now() - instance.activityStartTime ) / 10) / 100;
// xAPI spec allows a precision of 0.01 seconds // xAPI spec allows a precision of 0.01 seconds
this.data.statement.result.duration = 'PT' + duration + 'S'; this.data.statement.result.duration = 'PT' + duration + 'S';
} }
}; };
@ -188,12 +188,18 @@ H5P.XAPIEvent.prototype.setActor = function () {
} }
else { else {
var uuid; var uuid;
if (localStorage.H5PUserUUID) { try {
uuid = localStorage.H5PUserUUID; if (localStorage.H5PUserUUID) {
uuid = localStorage.H5PUserUUID;
}
else {
uuid = H5P.createUUID();
localStorage.H5PUserUUID = uuid;
}
} }
else { catch (err) {
uuid = H5P.createUUID(); // LocalStorage and Cookies are probably disabled. Do not track the user.
localStorage.H5PUserUUID = uuid; uuid = 'not-trackable-' + H5P.createUUID();
} }
this.data.statement.actor = { this.data.statement.actor = {
'account': { 'account': {