generated from gundelsby/js-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
42 lines (34 loc) · 1.06 KB
/
index.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
import { networkInterfaces } from 'os';
import { calcRealBpm } from './lib/helpers/tempoCalculations.js';
import initialize from './lib/index.js';
import { getLogger } from './lib/util/logger.js';
const log = getLogger('main');
initialize(getLocalIpv4Props()).then(({ NetworkServices, registry }) => {
const beatTracker = NetworkServices.beatTrackingService;
beatTracker.on('beat', ({ packet }) => {
log('Beat:', packet);
log('Real BPM', { bpm: calcRealBpm(packet.bpm, packet.pitch) });
});
registry.on('connected', ({ device }) => {
log('Device connected', { ...device });
});
registry.on('disconnected', ({ device }) => {
log('Device disconnected', {
name: device.name,
address: device.macAddress
});
});
log('Registered listeners on registry', registry);
});
function getLocalIpv4Props() {
const interfaces = networkInterfaces();
for (const iface of Object.keys(interfaces)) {
const ipv4Props = interfaces[iface]?.find(
({ family }) => family === 'IPv4'
);
if (ipv4Props?.internal === false) {
return ipv4Props;
}
}
return null;
}