Skip to content

Commit

Permalink
Previously uncommitted amends for #3.
Browse files Browse the repository at this point in the history
Allows xAPI in Curatr which is a hybrid of ADL Launch and Rustici Launch logic.
  • Loading branch information
danielghost committed Sep 5, 2019
1 parent ac6af9e commit 93d3486
Show file tree
Hide file tree
Showing 6 changed files with 189 additions and 12 deletions.
8 changes: 6 additions & 2 deletions js/adapt-xapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define([
var config = {
_statementConfig: {
lang: Adapt.config.get('_defaultLanguage'),
activityId: this._config._activityId,
activityId: this.getActivityId(),
actor: this.launchModel.get('actor'),
contextActivities: this.launchModel.get('contextActivities')
},
Expand All @@ -50,13 +50,17 @@ define([
this.listenTo(Adapt, 'xapi:stateReady', this.onStateReady);

var config = {
activityId: this._config._activityId,
activityId: this.getActivityId(),
actor: this.launchModel.get('actor')
};

this.stateModel = new StateModel(config, { wrapper: this.launchModel.getWrapper() });
},

getActivityId: function() {
return this._config._activityId || this.launchModel.getWrapper().lrs.activityId;
},

onDataReady: function() {
this._config = Adapt.config.get('_xapi');

Expand Down
51 changes: 43 additions & 8 deletions js/launchModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ define([

defaults: {
actor: null,
contextActivities: {}
contextActivities: {
grouping: []
}
},

_xAPIWrapper: null,
Expand All @@ -18,7 +20,25 @@ define([
},

initializeLaunch: function() {
ADL.launch(_.bind(this.onLaunchAttempt, this), false);
var lrs = ADL.XAPIWrapper.lrs;

// auth could be sent through in a different process, e.g. OAuth?
//if (lrs.endpoint && lrs.auth && lrs.actor) {
if (lrs.endpoint && lrs.actor) {
this._xAPIWrapper = ADL.XAPIWrapper;

// capture grouping URL params - unsure what data this actually contains based on specs - unlike contextActivities for ADL Launch
var launchCredentials = {
'actor': JSON.parse(lrs.actor)/*,
'contextActivities': launchdata.contextActivities*/
};

this.set(launchCredentials);

this.triggerLaunchInitialized();
} else {
ADL.launch(_.bind(this.onADLLaunchAttempt, this), false);
}
},

getWrapper: function() {
Expand All @@ -31,7 +51,13 @@ define([
Adapt.trigger('xapi:launchError');
},

onLaunchAttempt: function(err, launchdata, wrapper) {
triggerLaunchInitialized: function() {
_.defer(function() {
Adapt.trigger('xapi:launchInitialized')
});
},

onADLLaunchAttempt: function(err, launchdata, wrapper) {
/*
200 = OK
400 = launch already initialized
Expand All @@ -51,17 +77,15 @@ define([
sessionStorage.setItem('lrs', JSON.stringify(wrapper.lrs));
sessionStorage.setItem('launchCredentials', JSON.stringify(launchCredentials));

Adapt.trigger('xapi:launchInitialized');
this.triggerLaunchInitialized();
} else if (performance.navigation.type === 1) {
this.onReload();
} else if (this._retryCount < this._retryLimit) {
this._retryCount++;

this.initializeLaunch();
} else {
$('.loading').hide();

this.showErrorNotification();
this.onLaunchFail();
}
},

Expand All @@ -70,12 +94,23 @@ define([
var lrs = JSON.parse(sessionStorage.getItem('lrs'));
var launchCredentials = JSON.parse(sessionStorage.getItem('launchCredentials'));

if (!lrs || !launchCredentials) {
this.onLaunchFail();
return;
}

this._xAPIWrapper = ADL.XAPIWrapper;
this._xAPIWrapper.changeConfig(lrs);

this.set(launchCredentials);

Adapt.trigger('xapi:launchInitialized');
this.triggerLaunchInitialized();
},

onLaunchFail: function() {
$('.loading').hide();

this.showErrorNotification();
},

onNotifyClosed: function() {
Expand Down
6 changes: 4 additions & 2 deletions js/statements/abstractStatementModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ define([
lang: "en",
activityId: null,
actor: null,
contextActivities: {},
contextActivities: {
grouping: []
},
registration: null
},

Expand Down Expand Up @@ -75,7 +77,7 @@ define([
},

getContextActivitiesGrouping: function(model) {
var grouping = (this.get('contextActivities').grouping) ? this.get('contextActivities').grouping.slice() : [];
var grouping = this.get('contextActivities').grouping.slice();
grouping.push(this.getCourseContextActivity());

var modelType = model.get('_type');
Expand Down
84 changes: 84 additions & 0 deletions required/adl_launch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!--[if IE]><![endif]-->
<!doctype html>
<!--[if IE 7 ]><html id="adapt" class="ie ie7 no-js" lang="en"><![endif]-->
<!--[if IE 8 ]><html id="adapt" class="ie ie8 no-js" lang="en"><![endif]-->
<!--[if IE 9 ]><html id="adapt" class="ie ie9 no-js" lang="en"><![endif]-->
<!--[if gt IE 9]><!--><html id="adapt" class="no-js" lang="en"><!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="libraries/jquery.min.js"></script>
<script type="text/javascript">
$.ajax({
type: "POST",
beforeSend: function(request) {
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader("Authorization", getLauncherAuth());
},
url: getLauncherURL(),
data: getData(),
processData: false,
success: function(msg) {
window.location = 'index.html?xAPILaunchService=' + getLauncherEndpoint() + '&xAPILaunchKey=' + encodeURIComponent(msg.key);
}
});

function generateSessionID() {
return Math.random().toString(36).substr(2, 9);
}

function getLauncherURL() {
var url = "https://launcher.learninglocker.net/session/" + generateSessionID() + "/launch";

return url;
}

function getLauncherAuth() {
// "Basic " + toBase64('username:password');
var auth = "";

return auth;
}

function getLauncherEndpoint() {
var endpoint = "https://launcher.learninglocker.net/content/";

return encodeURIComponent(endpoint);
}

function getData() {
var data = {
statement: {
actor: {
mbox: "mailto:username@domain.com",
name: "Test User"
},
context: {
contextActivities: {
grouping: [
{
objectType: "Activity",
id: "http://example.com/course_identifier",
definition: {
name: {
en: "Test Course"
}
}
}
]
}
}
},
ttl: 10
};

return JSON.stringify(data);
}
</script>
</head>

<body>
</body>
</html>
42 changes: 42 additions & 0 deletions required/launch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!--[if IE]><![endif]-->
<!doctype html>
<!--[if IE 7 ]><html id="adapt" class="ie ie7 no-js" lang="en"><![endif]-->
<!--[if IE 8 ]><html id="adapt" class="ie ie8 no-js" lang="en"><![endif]-->
<!--[if IE 9 ]><html id="adapt" class="ie ie9 no-js" lang="en"><![endif]-->
<!--[if gt IE 9]><!--><html id="adapt" class="no-js" lang="en"><!--<![endif]-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="libraries/jquery.min.js"></script>
<script type="text/javascript">
window.location = 'index.html?endpoint=' + getLRSEndpoint() + '&actor=' + getActor() + '&auth=' + getAuth();

function getLRSEndpoint() {
var endpoint = "https://saas.learninglocker.net/data/xAPI/";

return encodeURIComponent(endpoint);
}

function getActor() {
var actor = {
mbox: "mailto:username@domain.com",
name: "Test User"
};

return JSON.stringify(actor);
}

function getAuth() {
// "Basic " + toBase64('username:password');
var auth = "";

return auth;
}
</script>
</head>

<body>
</body>
</html>
10 changes: 10 additions & 0 deletions required/tincan.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<tincan xmlns="http://projecttincan.com/tincan.xsd">
<activities>
<activity id="@@config._xapi._activityId" type="http://adlnet.gov/expapi/activities/course">
<name><![CDATA[@@course.title]]></name>
<description lang="en"><![CDATA[@@course.description]]></description>
<launch lang="en">index.html</launch>
</activity>
</activities>
</tincan>

0 comments on commit 93d3486

Please sign in to comment.