Skip to content
Snippets Groups Projects
Commit 498cd7e8 authored by Aymeric Bernard's avatar Aymeric Bernard
Browse files

Merge branch 'real-api' into 'master'

Real api

See merge request hermod/tv_panel!2
parents a6366815 0fea11ab
No related branches found
No related tags found
No related merge requests found
......@@ -12,13 +12,19 @@ const concatTextParts = textParts =>
const jsonTextToHtml = data => <div className="text-bloc">{concatTextParts(data.text)}</div>;
const jsonImageToHtml = data => <div className="image-bloc">{data.image}</div>;
const jsonImageToHtml = data => <div className="image-bloc">
<img
src="https://people.via.ecp.fr/~bebert/chatenay.jpg"
alt-src={data.image}
style="height: 80px; margin-right: 10px; border: solid 1px #A0A0A0"
/>
</div>;
const jsonImageTextToHtml = data => (
<div className="image-text-bloc" style="display: flex">
<img
src="https://people.via.ecp.fr/~stook/perso/ancien_public_html/stickerFlat.png"
style="height: 40px; margin-right: 10px"
src="https://people.via.ecp.fr/~bebert/toddy.jpg"
style="height: 80px; margin-right: 10px; border: solid 1px #A0A0A0"
/>
<div style="width: 100%; display: flex; justify-content: space-between">
{concatTextParts(data.text)}
......@@ -30,6 +36,9 @@ export default (data) => {
const head = <div style="background-color:#F2F2FF; padding:10px" />;
data.rows
.map((row) => {
if (!row) {
return '';
}
switch (row.type) {
case 0:
return jsonTextToHtml(row);
......
......@@ -2,12 +2,12 @@
<html>
<head>
<title>Socket IO test</title>
<title>Hermod TV Panel</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<p>Date:
<p style="color: #DDDDDD">Date:
<span id="date">
Not connected
</span>
......@@ -15,6 +15,9 @@
<div id="panel_data"></div>
<style type="text/css" id="root">
</style>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.slim.js"></script>
<script type="text/javascript" src="./setup.js" defer></script>
<script type="text/javascript" src="./socket.js" defer></script>
......
......@@ -18,11 +18,13 @@ socketIO.on('date', (data) => {
socketIO.on('panel_data', (data) => {
console.log(data);
// data.ttl = 500000;
setTimeout(() => {
socketIO.emit('panel_data');
console.log(`Next call in ${data.ttl} milliseconds.`);
}, data.ttl);
const panelData = document.getElementById('panel_data');
document.getElementById('root').innerHTML = 'html {--size: 80px;}';
diffNodes(panelData, jsonToHtmlArray(data));
});
......
.text-element {
font-size: 40px;
font-size: var(--size);
}
.text-bloc {
......
const fetch = require('node-fetch');
const io = require('socket.io')(3000);
let incr = 0;
io.of('/').on('connection', (socket) => {
fetch('http://hermod.cs-campus.fr/api/v1/screen/1')
.then(res => res.json())
.then(res => socket.emit('message', res));
// 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', () => {
socket.emit(
'panel_data',
// Pour les tests, json en dur
{
version: '0.0.3',
ttl: 2000,
rows: [
{
type: 1, // 0 for "text", 1 for "text + image", 2 for "image"...
image: 'base_url',
text: [
{ text: 'What I want to display', style: { color: '#440044' } },
{ text: incr.toString(), style: { color: '#BB8800', fontWeight: 'bold' } },
],
},
{
type: 0,
text: [
{ text: 'Some text', style: { color: '#440044' } },
{ text: incr.toString(), style: { color: '#BB8800', fontWeight: 'bold' } },
],
},
{
type: 2,
image: 'base_url',
text: [{ text: 'Nope' }],
},
],
},
);
// Truc qui change juste pour voir si ça refresh
incr += 1;
fetch('http://hermod.cs-campus.fr/api/v1/screen/10') // TODO get the uid from a config
.then(rawRes => rawRes.json())
.then(res => socket.emit('panel_data', res))
.catch(console.log);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment