Skip to content
Snippets Groups Projects
Commit ac529601 authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Show thumbnails and data in browser

parent e997d4bc
No related branches found
No related tags found
1 merge request!316Resolves #343 GUI and Frame Refactor
Pipeline #28533 failed
...@@ -196,6 +196,7 @@ private: ...@@ -196,6 +196,7 @@ private:
void add(uint32_t fsid, const std::string &uri, ftl::stream::Stream *s); void add(uint32_t fsid, const std::string &uri, ftl::stream::Stream *s);
nlohmann::json &_add_recent_source(const ftl::URI &uri); nlohmann::json &_add_recent_source(const ftl::URI &uri);
void _saveThumbnail(const ftl::data::FrameSetPtr& fs);
/** callback for network (adds new sorces on connect/...) */ /** callback for network (adds new sorces on connect/...) */
void _updateNetSources(ftl::net::Peer *p); void _updateNetSources(ftl::net::Peer *p);
......
...@@ -71306,14 +71306,14 @@ renderThumbnails = async () => { ...@@ -71306,14 +71306,14 @@ renderThumbnails = async () => {
const encodedURI = encodeURIComponent(thumbnails[i]) const encodedURI = encodeURIComponent(thumbnails[i])
current_data.uri = thumbnails[i] current_data.uri = thumbnails[i]
try{ try{
const someData = await fetch(`./stream/rgb?uri=${encodedURI}`) //const someData = await fetch(`./stream/rgb?uri=${encodedURI}`)
if(!someData.ok){ //if(!someData.ok){
throw new Error('Image not found') // throw new Error('Image not found')
} //}
const myBlob = await someData.blob(); //const myBlob = await someData.blob();
const objectURL = URL.createObjectURL(myBlob); //const objectURL = URL.createObjectURL(myBlob);
// containerDiv.innerHTML += createCard() // containerDiv.innerHTML += createCard()
containerDiv.innerHTML += createCard(objectURL, i+4) containerDiv.innerHTML += createCard(encodedURI, i+4)
}catch(err){ }catch(err){
console.log("Couldn't create thumbnail"); console.log("Couldn't create thumbnail");
console.log(err) console.log(err)
...@@ -71328,7 +71328,7 @@ renderThumbnails = async () => { ...@@ -71328,7 +71328,7 @@ renderThumbnails = async () => {
*/ */
createCard = (url, viewers) => { createCard = (url, viewers) => {
return `<div class='ftlab-card-component' > return `<div class='ftlab-card-component' >
<img src='${url}' class="thumbnail-img" alt="Hups" width="250px"></img> <img src='stream/rgb?uri=${url}' class="thumbnail-img" alt="Hups" width="250px"></img>
<p>Viewers: ${viewers}</p> <p>Viewers: ${viewers}</p>
<button onclick="createVideoPlayer()">button</button> <button onclick="createVideoPlayer()">button</button>
</div>` </div>`
...@@ -72693,8 +72693,8 @@ function Peer(ws) { ...@@ -72693,8 +72693,8 @@ function Peer(ws) {
this._notify("disconnect", this); this._notify("disconnect", this);
} }
   
let error = () => { let error = (e) => {
console.error("Socket error"); console.error("Socket error: ", e);
this.sock.close(); this.sock.close();
this.status = kDisconnected; this.status = kDisconnected;
} }
...@@ -82,14 +82,14 @@ renderThumbnails = async () => { ...@@ -82,14 +82,14 @@ renderThumbnails = async () => {
const encodedURI = encodeURIComponent(thumbnails[i]) const encodedURI = encodeURIComponent(thumbnails[i])
current_data.uri = thumbnails[i] current_data.uri = thumbnails[i]
try{ try{
const someData = await fetch(`./stream/rgb?uri=${encodedURI}`) //const someData = await fetch(`./stream/rgb?uri=${encodedURI}`)
if(!someData.ok){ //if(!someData.ok){
throw new Error('Image not found') // throw new Error('Image not found')
} //}
const myBlob = await someData.blob(); //const myBlob = await someData.blob();
const objectURL = URL.createObjectURL(myBlob); //const objectURL = URL.createObjectURL(myBlob);
// containerDiv.innerHTML += createCard() // containerDiv.innerHTML += createCard()
containerDiv.innerHTML += createCard(objectURL, i+4) containerDiv.innerHTML += createCard(encodedURI, i+4)
}catch(err){ }catch(err){
console.log("Couldn't create thumbnail"); console.log("Couldn't create thumbnail");
console.log(err) console.log(err)
...@@ -104,7 +104,7 @@ renderThumbnails = async () => { ...@@ -104,7 +104,7 @@ renderThumbnails = async () => {
*/ */
createCard = (url, viewers) => { createCard = (url, viewers) => {
return `<div class='ftlab-card-component' > return `<div class='ftlab-card-component' >
<img src='${url}' class="thumbnail-img" alt="Hups" width="250px"></img> <img src='stream/rgb?uri=${url}' class="thumbnail-img" alt="Hups" width="250px"></img>
<p>Viewers: ${viewers}</p> <p>Viewers: ${viewers}</p>
<button onclick="createVideoPlayer()">button</button> <button onclick="createVideoPlayer()">button</button>
</div>` </div>`
......
...@@ -7,7 +7,11 @@ const config = require('./utils/config') ...@@ -7,7 +7,11 @@ const config = require('./utils/config')
const User = require('./models/users') const User = require('./models/users')
const Configs = require('./models/generic') const Configs = require('./models/generic')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
const Url = require('url-parse') const Url = require('url-parse');
const { LogLuvEncoding } = require('three');
const msgpack = require('msgpack5')()
, encode = msgpack.encode
, decode = msgpack.decode;
// ---- INDEXES ---------------------------------------------------------------- // ---- INDEXES ----------------------------------------------------------------
app.use(express.static(__dirname + '/../../public')); app.use(express.static(__dirname + '/../../public'));
...@@ -76,6 +80,8 @@ function RGBDStream(uri, peer) { ...@@ -76,6 +80,8 @@ function RGBDStream(uri, peer) {
this.rxcount = 10; this.rxcount = 10;
this.rxmax = 10; this.rxmax = 10;
this.data = {};
let ix = uri.indexOf("?"); let ix = uri.indexOf("?");
this.base_uri = (ix >= 0) ? uri.substring(0, ix) : uri; this.base_uri = (ix >= 0) ? uri.substring(0, ix) : uri;
...@@ -87,6 +93,7 @@ function RGBDStream(uri, peer) { ...@@ -87,6 +93,7 @@ function RGBDStream(uri, peer) {
//if (this.rxcount >= this.rxmax && this.clients.length > 0) { //if (this.rxcount >= this.rxmax && this.clients.length > 0) {
// this.subscribe(); // this.subscribe();
//} //}
//console.log("Got frame: ", spacket);
}); });
/*peer.bind(uri, (frame, ttime, chunk, rgb, depth) => { /*peer.bind(uri, (frame, ttime, chunk, rgb, depth) => {
...@@ -97,6 +104,9 @@ function RGBDStream(uri, peer) { ...@@ -97,6 +104,9 @@ function RGBDStream(uri, peer) {
this.subscribe(); this.subscribe();
} }
});*/ });*/
console.log("Sending request");
this.peer.send(this.base_uri, 0, [1,255,255,74,1],[7,0,1,255,0,new Uint8Array(0)]);
} }
RGBDStream.prototype.addClient = function(peer) { RGBDStream.prototype.addClient = function(peer) {
...@@ -124,9 +134,8 @@ RGBDStream.prototype.subscribe = function() { ...@@ -124,9 +134,8 @@ RGBDStream.prototype.subscribe = function() {
RGBDStream.prototype.pushFrames = function(latency, spacket, packet) { RGBDStream.prototype.pushFrames = function(latency, spacket, packet) {
//Checks that the type is jpg //Checks that the type is jpg
if (packet[0] === 0){ if (spacket[3] >= 64) {
if (spacket[3] > 0) this.depth = packet[5]; this.data[spacket[3]] = decode(packet[5]);
else this.rgb = packet[5];
} }
//console.log("Frame = ", packet[0], packet[1]); //console.log("Frame = ", packet[0], packet[1]);
...@@ -161,24 +170,29 @@ app.get('/streams', (req, res) => { ...@@ -161,24 +170,29 @@ app.get('/streams', (req, res) => {
* binded to that * binded to that
*/ */
app.get('/stream/rgb', (req, res) => { app.get('/stream/rgb', (req, res) => {
let uri = req.query.uri; let uri = decodeURI(req.query.uri);
let ix = uri.indexOf("?");
let base_uri = (ix >= 0) ? uri.substring(0, ix) : uri;
if (uri_data.hasOwnProperty(uri)) { if (uri_data.hasOwnProperty(uri)) {
//uri_data[uri].peer.send("get_stream", uri, 3, 9, [Peer.uuid], uri); //uri_data[uri].peer.send("get_stream", uri, 3, 9, [Peer.uuid], uri);
res.writeHead(200, {'Content-Type': 'image/jpeg'}); res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.end(uri_data[uri].rgb); res.end(uri_data[uri].data[74]);
} }
res.end(); res.end();
}); });
app.get('/stream/depth', (req, res) => { app.get('/stream/data', (req, res) => {
let uri = req.query.uri; let uri = req.query.uri;
let channel = parseInt(req.query.channel);
const parsedURI = stringSplitter(uri) const parsedURI = stringSplitter(uri)
if (uri_data.hasOwnProperty(parsedURI)) { if (uri_data.hasOwnProperty(parsedURI)) {
res.writeHead(200, {'Content-Type': 'image/png'}); //res.writeHead(200, {'Content-Type': 'image/png'});
res.end(uri_data[parsedURI].depth); res.status(200).json(uri_data[parsedURI].data[channel]);
} } else {
res.end(); res.end();
}
}); });
app.post('/stream/config', async (req, res) => { app.post('/stream/config', async (req, res) => {
...@@ -220,23 +234,19 @@ app.get('/stream/config', async(req, res) => { ...@@ -220,23 +234,19 @@ app.get('/stream/config', async(req, res) => {
//example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi#reconstruction_snap10/merge //example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi#reconstruction_snap10/merge
const settings = req.query.settings; const settings = req.query.settings;
const uri = req.query.uri; const uri = decodeURI(req.query.uri);
const parsedURI = stringSplitter(uri) //const parsedURI = stringSplitter(uri)
// //Checks if DB has data if (uri_data.hasOwnProperty(uri)) {
// let dbData = await Configs.find({Settings: settings}); let peer = uri_data[uri].peer
// if(dbData[0].data){
// return res.status(200).json(dbData[0]);
// }else{
let peer = uri_data[parsedURI].peer
if (peer){ if (peer){
peer.rpc("get_cfg", (response) => { peer.rpc("get_configurable", (response) => {
if(response){ if(response){
return res.status(200).json(response); return res.status(200).json(JSON.parse(response));
}
}, uri);
} }
}, settings)
} }
// }
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment