-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsampleAppSensorService.js
86 lines (77 loc) · 3.23 KB
/
sampleAppSensorService.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* This file is part of IMS Caliper Analytics™ and is licensed to
* IMS Global Learning Consortium, Inc. (http://www.imsglobal.org)
* under one or more contributor license agreements. See the NOTICE
* file distributed with this work for additional information.
*
* IMS Caliper is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* IMS Caliper is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this program. If not, see http://www.gnu.org/licenses/.
*/
/*
* Sample App Sensor Service
*
* This service wraps the caliper-js sensor, enabling any application specific
* logic to be performed before sending events using the base Javascript sensor
*
* @author: Prashant Nayak, Intellify Learning; Anthony Whyte, University of Michigan
*/
angular.module('sampleCaliperApp')
.factory('sampleAppSensorService', ['sampleAppContextService', function(sampleAppContextService) {
// Initialize Caliper sensor
var sensor = Caliper.Sensor;
sensor.initialize("http://example.org/sensors/1");
// TAKE HEED: you must uncomment and define the HTTPClient options (endpoint, message headers, etc.)
// Example: RequestBin endpoint running in Heroku (Runscope's public version has been disabled due to misuse)
/**
var options = {
uri: 'https://someplace.herokuapp.com/wufdiiwu',
withCredentials: false,
headers: {
"Authorization": "Y2FsaXBlcnYxcDFib290Y2FtcDIwMTc=",
"Content-Type": "application/json"
},
method: "POST"
};
*/
// Initialize then register HTTP client
var client = Caliper.Clients.HttpClient;
client.initialize(sensor.id.concat("/clients/1"), options);
sensor.registerClient(client);
// Wrapper around Caliper Sensor getId()
var getId = function() {
return sensor.getId();
};
// Wrapper around Caliper Sensor createEnvelope()
var createEnvelope = function(opts) {
return sensor.createEnvelope(opts)
};
// Wrapper around Caliper Sensor's sendEnvelope()
var sendEnvelope = function(envelope) {
sensor.sendToClients(envelope);
};
// Export the functions that will be used by controller
var exports = {
getId: getId,
createEnvelope: createEnvelope,
sendEnvelope: sendEnvelope,
currentUser: sampleAppContextService.getUser(),
syllabus: sampleAppContextService.getSyllabus(),
reading: sampleAppContextService.getReading(),
readingFrame: sampleAppContextService.getReadingFrame(),
edApp: sampleAppContextService.getEdApp(),
course: sampleAppContextService.getCourse(),
membership: sampleAppContextService.getMembership(),
courseHomePage: sampleAppContextService.getCourseHomePage(),
quiz: sampleAppContextService.getQuiz(),
quizPage: sampleAppContextService.getQuizPage()
};
return exports;
}]);