Skip to content
Snippets Groups Projects
Commit 6318ba50 authored by Ayc0's avatar Ayc0
Browse files

Set chrono in back

parent 23da7d26
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,6 @@ class App extends Component {
onReceiveMessage = (data) => {
this.setState({ data });
setTimeout(() => {
socketIO.emit('panel_data');
}, data.ttl);
};
render() {
......
......@@ -4,6 +4,10 @@ const path = require('path');
module.exports = {
port: 5000,
uuid: 'UUID A REMPLIR',
api: {
url: 'http://api.hermod.cs-campus.fr',
version: 'v1',
},
fontSize: '4vh',
rowHeight: '100px',
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 {
uuid, fontSize, rowHeight, port,
uuid, fontSize, rowHeight, port, api,
} = require('./config');
const dummyResponse = require('./dummyResponse.json');
const io = require('socket.io')(port || 3000);
const { createSignedJWT } = require('./utils');
const { createSignedJWT, interval } = require('./utils');
const useDummy = false;
io.of('/').on('connection', (socket) => {
socket.emit('config', { fontSize, rowHeight });
// Respond to date message with the date
socket.on('date', () => {
socket.emit('date', { date: Date.now() });
});
// Respond to panel_data message by fetching the info from the server
socket.on('panel_data', () => {
fetch(`http://api.hermod.cs-campus.fr/v1/screen/${uuid}`, {
const chrono = useDummy
? interval(() => {
socket.emit('panel_data', dummyResponse);
return 15000;
}, 0)
: interval(
() =>
fetch(`${api.url}/${api.version}/screen/${uuid}`, {
headers: {
Autorization: `Bearer ${createSignedJWT()}`,
},
})
.then(rawRes => rawRes.json())
.then(res => socket.emit('panel_data', res))
.catch(console.log);
});
.then((res) => {
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
socket.on('panel_data0', () => {
socket.emit('panel_data', {
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' }],
},
],
// Respond to date message with the date
socket.on('date', () => {
socket.emit('date', { date: Date.now() });
});
socket.on('disconnect', () => {
chrono.clear();
});
});
......@@ -28,6 +28,7 @@ const generateRandomString = (length) => {
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 };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment