-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (47 loc) · 1.48 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
43
44
45
46
47
48
49
50
51
52
53
54
55
const io = require('socket.io-client');
const serialport = require("serialport");
const SerialPort = serialport.SerialPort;
const portName = process.argv[2]; // => $ npm start COM4
const streamlabs = io(`https://sockets.streamlabs.com?token=${process.env.STREAMLABS_SOCKET_TOKEN}`, {transports: ['websocket']});
const myPort = new serialport(portName,{
baudRate:9600,
parser: new serialport.parsers.Readline("\r\n")
})
myPort.on('open', ()=>{arduMessage("ARDUINO CONECTADO")});
function arduMessage(message){
setTimeout(function(){
myPort.write(`${message} `);
}, 2000)
}
streamlabs.on('connect', () => {console.log('CONNECTION SUCCESS')});
streamlabs.on('event', (eventData) => {
var message = eventData.message[0]
if (eventData.type === 'donation') {
name = message.from;
amount = message.amount;
data = `${name}: $${amount}`
console.log(data);
arduMessage(data);
}
if (eventData.for === 'twitch_account') {
switch(eventData.type) {
case 'follow':
data = `FOLLOW: ${message.name}`
console.log(data);
arduMessage(data);
break;
case 'subscription':
data = `SUB: ${message.name}`
console.log(data);
arduMessage(data);
break;
case 'beats':
data = `BITS: ${message.name}, ${message.amount}`
console.log(data);
arduMessage(data);
break;
default:
console.log(message);
}
}
});