mirror of
https://github.com/karl0ss/orvibo-b25-server-kex.git
synced 2025-04-29 12:53:40 +01:00
big reshuffle and commit
This commit is contained in:
parent
1d7112eb9c
commit
a350dd49f4
@ -1,4 +1,4 @@
|
||||
const Orvibo = require('./Orvibo');
|
||||
const Orvibo = require('./utils/Orvibo');
|
||||
const http = require('http');
|
||||
const url = require('url');
|
||||
|
3288
package-lock.json
generated
3288
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -24,6 +24,11 @@
|
||||
},
|
||||
"homepage": "https://github.com/sandysound/orvibo-b25-server#readme",
|
||||
"dependencies": {
|
||||
"buffer-crc32": "^0.2.13"
|
||||
"buffer-crc32": "^0.2.13",
|
||||
"express": "^4.17.1",
|
||||
"pug": "^2.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"nodemon": "^1.19.1"
|
||||
}
|
||||
}
|
||||
|
89
public/css/style.css
Normal file
89
public/css/style.css
Normal file
@ -0,0 +1,89 @@
|
||||
html {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
*, *::before, *::after {
|
||||
box-sizing: inherit; /* [1] */
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif; /* [2] */
|
||||
}
|
||||
|
||||
.header {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 80px;
|
||||
background-color: #525286;
|
||||
color: #FFFFFF;
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
.container {
|
||||
width: 960px;
|
||||
margin: 0 auto;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
grid-gap: 20px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
.person {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.person > * {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.person-image {
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
}
|
||||
.profile {
|
||||
display: flex;
|
||||
height: 100vh;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.profile-image {
|
||||
height: 100%;
|
||||
flex-grow: 1;
|
||||
flex-basis: 50%;
|
||||
}
|
||||
|
||||
.profile-details {
|
||||
flex-basis: 30%;
|
||||
flex-grow: 1;
|
||||
padding: 50px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.profile-details > * {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.button {
|
||||
height: 50px;
|
||||
line-height: 50px;
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
text-align: center;
|
||||
font-size: 20px
|
||||
}
|
||||
|
||||
.button-twitter {
|
||||
color: #FFFFFF;
|
||||
background-color: #659AF1;
|
||||
border-radius: 5px;
|
||||
}
|
81
server.js
Normal file
81
server.js
Normal file
@ -0,0 +1,81 @@
|
||||
const Orvibo = require('./server/utils/Orvibo');
|
||||
const http = require('http');
|
||||
const url = require('url');
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
|
||||
app.set('view engine', 'pug');
|
||||
app.use(express.static(__dirname + '/public'));
|
||||
|
||||
const createArray = str => {
|
||||
// split on each comma
|
||||
const arr = str.split(',');
|
||||
// put back elements by pairs
|
||||
const pairs = [];
|
||||
for (let i=0; i<arr.length; i+=2) {
|
||||
let o = {};
|
||||
o.uid = arr[i].split(':')[1];
|
||||
o.name = arr[i+1].split(':')[1];
|
||||
pairs.push(o);
|
||||
}
|
||||
return pairs;
|
||||
}
|
||||
|
||||
// Create a settings object to pass PK key and map sockets to names
|
||||
const settings = {
|
||||
LOG_PACKET: true, //Show incoming packet data from the socket
|
||||
ORVIBO_KEY: process.env.orviboPK,
|
||||
plugInfo :
|
||||
createArray(process.env.plugArray)
|
||||
,
|
||||
};
|
||||
let orvibo = new Orvibo(settings);
|
||||
// When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket;
|
||||
orvibo.on('plugConnected', ({uid, name}) => {
|
||||
console.log(`Connected ${uid} name = ${name}`);
|
||||
});
|
||||
|
||||
// If the socket state is updated this event will fire
|
||||
orvibo.on('plugStateUpdated', ({uid, state , name}) => {
|
||||
console.log(`Plug ${name} ${uid} updated state ${state}`);
|
||||
});
|
||||
|
||||
// The plug sends a hearbeat to let the server know it's still alive
|
||||
orvibo.on('gotHeartbeat', ({uid, name}) => {
|
||||
console.log(`Plug ${name} ${uid} sent heartbeat`);
|
||||
});
|
||||
|
||||
// Called when the plug disconnects
|
||||
orvibo.on('plugDisconnected', ({uid, name }) => {
|
||||
console.log(`Plug ${uid} - ${name} disconnected`);
|
||||
});
|
||||
|
||||
// Called when the plug disconnects with an error ie it's been unplugged
|
||||
orvibo.on('plugDisconnectedWithError', ({uid, name }) => {
|
||||
console.log(`Plug ${uid} - ${name} disconnected with error`);
|
||||
});
|
||||
|
||||
|
||||
// Start the Orvibo socket server
|
||||
orvibo.startServer();
|
||||
|
||||
app.get('/', (req, res) => {
|
||||
let sockets = orvibo.getConnectedSocket();
|
||||
|
||||
res.render('index', {
|
||||
title: 'Orvibo b25 Server',
|
||||
sockets
|
||||
})
|
||||
});
|
||||
|
||||
const server = app.listen(3000, () => {
|
||||
console.log(`Express running → PORT ${server.address().port}`);
|
||||
});
|
||||
|
||||
|
||||
// const requestHandler = (request, response) => {
|
||||
// response.writeHead(200, {'Content-Type': 'application/json'});
|
||||
// let q = url.parse(request.url, true).query;
|
||||
// if (q.uid != null) {
|
||||
// orvibo.toggleSocket(q.uid);
|
||||
// }
|
12
views/default.pug
Normal file
12
views/default.pug
Normal file
@ -0,0 +1,12 @@
|
||||
doctype html
|
||||
html
|
||||
head
|
||||
title #{title}
|
||||
link(rel='stylesheet', href='css/style.css')
|
||||
meta(name="viewport" content="width=device-width, initial-scale=1")
|
||||
body
|
||||
main
|
||||
block header
|
||||
header.header
|
||||
h1 #{title}
|
||||
block content
|
12
views/index.pug
Normal file
12
views/index.pug
Normal file
@ -0,0 +1,12 @@
|
||||
extends default
|
||||
|
||||
block content
|
||||
div.container
|
||||
each modelId in sockets
|
||||
div.person
|
||||
h2.person-name
|
||||
| #{modelId.name}
|
||||
h2.person-name2
|
||||
| #{modelId.uid}
|
||||
a(href=`/?uid=${modelId.uid}`)
|
||||
| Toggle
|
Loading…
x
Reference in New Issue
Block a user