-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
31 lines (25 loc) · 1022 Bytes
/
lib.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
function receiveSensorData(handler, webjackProfile) {
webjackProfile = webjackProfile || "SoftModem";
// nonsense to start up audio and get past the "click to play" policy
var ac = getAudioContext();
var connection, getConnection = function() { return connection }
ac.suspend().then(function() {
var myButton = createButton('click to start audio');
myButton.position(0, 0);
userStartAudio(myButton, function() {
myButton.remove();
// https://github.com/publiclab/webjack/blob/master/src/profiles.js
var profile = WebJack.Profiles[webjackProfile];
connection = new WebJack.Connection(profile);
// runs every time a signal is 'heard'
connection.listen(function(data) {
// data from WebJack may look like "1,2,3"
data = data.split(',').map(function(i) {
return parseFloat(i)
}); // so we break it apart using the commas, and make them floats
handler(data, connection);
});
});
});
return getConnection;
}