Skip to content
Snippets Groups Projects
Commit ed1759c9 authored by Benjamin Koltes's avatar Benjamin Koltes
Browse files

Merge branch 'chore/chrono' into 'master'

Set chrono in back

See merge request hermod/tv_panel!9
parents 23da7d26 6318ba50
Branches
No related tags found
No related merge requests found
...@@ -16,9 +16,6 @@ class App extends Component { ...@@ -16,9 +16,6 @@ class App extends Component {
onReceiveMessage = (data) => { onReceiveMessage = (data) => {
this.setState({ data }); this.setState({ data });
setTimeout(() => {
socketIO.emit('panel_data');
}, data.ttl);
}; };
render() { render() {
......
...@@ -4,6 +4,10 @@ const path = require('path'); ...@@ -4,6 +4,10 @@ const path = require('path');
module.exports = { module.exports = {
port: 5000, port: 5000,
uuid: 'UUID A REMPLIR', uuid: 'UUID A REMPLIR',
api: {
url: 'http://api.hermod.cs-campus.fr',
version: 'v1',
},
fontSize: '4vh', fontSize: '4vh',
rowHeight: '100px', rowHeight: '100px',
cert: fs.readFileSync(path.resolve(__dirname, '../key.pem')), cert: fs.readFileSync(path.resolve(__dirname, '../key.pem')),
......
{
"version": "0.0.4",
"ttl": 300000,
"rows": [
{
"type": 1,
"image": "https://people.via.ecp.fr/~bebert/toddy.jpg",
"text": [
{ "text": "What I want to display", "style": { "color": "#000000" } },
{ "text": "42", "style": { "color": "#BB8800", "fontWeight": "bold" } }
]
},
{
"type": 0,
"text": [
{ "text": "Some text", "style": { "color": "#000000" } },
{ "text": "66", "style": { "color": "#BB8800", "fontWeight": "bold" } }
]
},
{
"type": 2,
"image": "https://people.via.ecp.fr/~bebert/chatenay.jpg",
"heightFactor": 3,
"text": [{ "text": "Nope" }]
}
]
}
const fetch = require('node-fetch'); const fetch = require('node-fetch');
const { const {
uuid, fontSize, rowHeight, port, uuid, fontSize, rowHeight, port, api,
} = require('./config'); } = require('./config');
const dummyResponse = require('./dummyResponse.json');
const io = require('socket.io')(port || 3000); const io = require('socket.io')(port || 3000);
const { createSignedJWT } = require('./utils'); const { createSignedJWT, interval } = require('./utils');
const useDummy = false;
io.of('/').on('connection', (socket) => { io.of('/').on('connection', (socket) => {
socket.emit('config', { fontSize, rowHeight }); socket.emit('config', { fontSize, rowHeight });
// Respond to date message with the date const chrono = useDummy
socket.on('date', () => { ? interval(() => {
socket.emit('date', { date: Date.now() }); socket.emit('panel_data', dummyResponse);
}); return 15000;
}, 0)
// Respond to panel_data message by fetching the info from the server : interval(
socket.on('panel_data', () => { () =>
fetch(`http://api.hermod.cs-campus.fr/v1/screen/${uuid}`, { fetch(`${api.url}/${api.version}/screen/${uuid}`, {
headers: { headers: {
Autorization: `Bearer ${createSignedJWT()}`, Autorization: `Bearer ${createSignedJWT()}`,
}, },
}) })
.then(rawRes => rawRes.json()) .then(rawRes => rawRes.json())
.then(res => socket.emit('panel_data', res)) .then((res) => {
.catch(console.log); socket.emit('panel_data', res);
}); return res.ttl;
})
.catch(console.log),
0,
);
// TEMP Respond to panel_data message by fetching the info from the server // Respond to date message with the date
socket.on('panel_data0', () => { socket.on('date', () => {
socket.emit('panel_data', { socket.emit('date', { date: Date.now() });
version: '0.0.4',
ttl: 300000,
rows: [
{
type: 1,
image: 'https://people.via.ecp.fr/~bebert/toddy.jpg',
text: [
{ text: 'What I want to display', style: { color: '#000000' } },
{ text: '42', style: { color: '#BB8800', fontWeight: 'bold' } },
],
},
{
type: 0,
text: [
{ text: 'Some text', style: { color: '#000000' } },
{ text: '66', style: { color: '#BB8800', fontWeight: 'bold' } },
],
},
{
type: 2,
image: 'https://people.via.ecp.fr/~bebert/chatenay.jpg',
heightFactor: 3,
text: [{ text: 'Nope' }],
},
],
}); });
socket.on('disconnect', () => {
chrono.clear();
}); });
}); });
...@@ -28,6 +28,7 @@ const generateRandomString = (length) => { ...@@ -28,6 +28,7 @@ const generateRandomString = (length) => {
return text; return text;
}; };
const createSignedJWT = () => jwt.sign({ state: generateRandomString(20) }, cert, { algorithm: 'RS256' }); const createSignedJWT = () =>
jwt.sign({ state: generateRandomString(20) }, cert, { algorithm: 'RS256' });
module.exports = { interval, createSignedJWT }; module.exports = { interval, createSignedJWT };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment