-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteraction
More file actions
72 lines (62 loc) · 1.78 KB
/
interaction
File metadata and controls
72 lines (62 loc) · 1.78 KB
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
var Beam = require('beam-client-node');
var Interactive = require('beam-interactive-node');
var rjs = require('robotjs');
var channelId = 3705;
var username = config.beam.ownername;
var password = config.beam.ownerpass;
var totals = [0, 0, 0, 0, 0];
var tact;
var joystick;
var beam = new Beam();
beam.use('password', {
username,
password,
})
.attempt()
.then(() => beam.game.join(channelId))
.then(res => createRobot(res))
.then(robot => performRobotHandShake(robot))
.then(robot => setupRobotEvents(robot))
.catch(err => {
if (err.res) {
throw new Error('Error connecting to Interactive:' + err.res.body.mesage);
}
throw new Error('Error connecting to Interactive', err);
});
function createRobot(res) {
return new Interactive.Robot({
remote: res.body.address,
channel: channelId,
key: res.body.key,
});
}
function performRobotHandShake(robot) {
return new Promise((resolve, reject) => {
robot.handshake(err => {
if (err) {
reject(err);
}
resolve(robot);
});
});
}
function setupRobotEvents(robot) {
robot.on('report', report => {
tact = report.tactile;
for (var i = 0; i < report.tactile.length; i++) {
totals[report.tactile[i].id] += report.tactile[i].releaseFrequency;
if (tact[i].releaseFrequency >= 1) {
io.emit('tact', { id: report.tactile[i].id, freq: report.tactile[i].releaseFrequency });
interactiveButtons(report.tactile[i].id);
}
}
});
robot.on('error', err => {
throw new Error('There was an error in the Interactive connection', err);
});
}
function interactiveButtons(id) {
console.log(id);
console.log(totals);
//do your stuff here
};