Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Hover = require('hover-nodejs');
- var WebSocket = require('ws');
- var hover = new Hover(0x42, 23, 24, 1);
- //hover.debug = true;
- hover.init().then(function() {
- // Ready to listen or do anything else
- console.log('Hover ready');
- hover.listen(handleHoverEvent, 1);
- }, function(error) {
- console.error('Could not init hover board');
- console.error(error);
- });
- var handleHoverEvent = function(event) {
- console.log(event);
- connections.forEach(function(c) {
- if(c.readyState === WebSocket.OPEN) {
- c.send(JSON.stringify({
- type: 'event',
- action: 'move',
- data: {
- direction: event
- }
- }));
- }
- });
- };
- // Web Sockets
- var connections = [];
- const wss = new WebSocket.Server({
- perMessageDeflate: false,
- port: 8000
- });
- wss.on('connection', function connection(ws) {
- console.log('Device Connected');
- connections.push(ws);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement