Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// encapsulate Funf functionality | ||
define([], function() { | ||
|
||
var FUNF_ACTION_RECORD = 'edu.mit.media.funf.RECORD'; | ||
var FUNF_ACTION_ARCHIVE = 'edu.mit.media.funf.ARCHIVE'; | ||
var FUNF_DATABASE_NAME = 'mainPipeline'; | ||
|
||
var Funf = function(appName) { | ||
console.assert(appName.indexOf('-') < 0, | ||
"funf doesn't like hyphens in the appName"); | ||
this.appName = appName; | ||
}; | ||
Funf.prototype = {}; | ||
Funf.prototype.record = function(name, value) { | ||
if (typeof value === 'object' /* includes arrays */) { | ||
// protect complex values from funf flattening | ||
value = JSON.stringify(value); | ||
} | ||
console.log('CSA FUNF '+name+' / '+value); | ||
try { | ||
// send custom event; there's a Firefox add-on which will | ||
// turn this into an Android Intent: | ||
// https://github.com/cscott/intent-addon | ||
var event = document.createEvent('CustomEvent'); | ||
var o = { name: name, value: value, millis: Date.now() }; | ||
var intent = { | ||
action: FUNF_ACTION_RECORD, | ||
method: 'sendBroadcast', | ||
extras: { | ||
DATABASE_NAME: FUNF_DATABASE_NAME, | ||
TIMESTAMP: Math.floor(Date.now()/1000), | ||
NAME: this.appName, | ||
VALUE: JSON.stringify(o) | ||
} | ||
}; | ||
event.initCustomEvent("intent-addon", true, true, intent); | ||
document.documentElement.dispatchEvent(event); | ||
} catch(e) { | ||
console.log("Sending custom event failed: "+e); | ||
} | ||
}; | ||
Funf.prototype.archive = function() { | ||
try { | ||
var event = document.createEvent('CustomEvent'); | ||
var intent = { | ||
action: FUNF_ACTION_ARCHIVE, | ||
method: 'sendBroadcast', | ||
extras: { | ||
DATABASE_NAME: FUNF_DATABASE_NAME | ||
} | ||
}; | ||
event.initCustomEvent("intent-addon", true, true, intent); | ||
document.documentElement.dispatchEvent(event); | ||
} catch(e) { | ||
console.log("Sending custom event failed: "+e); | ||
} | ||
}; | ||
return Funf; | ||
}); |