diff --git a/web-service/server/public/index.html b/web-service/server/public/index.html index 2c12186d0c7748010ab49f67d3a4df252513d9ed..9a99592171f99413a7020bb002123421540ecc3b 100644 --- a/web-service/server/public/index.html +++ b/web-service/server/public/index.html @@ -5,28 +5,7 @@ <link rel="stylesheet" href="./css/index.css"> </head> <body onload="checkIfLoggedIn()"> - <div id="container" style="padding-top: 150px; text-align: center"> - <div id='Login'> - <h2>Welcome to Future Technology Lab</h2> - <h3>Please login!</h3> - <a className="button" onClick="handleLogin()"> - <div> - <span class="svgIcon t-popup-svg"> - <svg class="svgIcon-use" width="25" height="37" viewBox="0 0 25 25"> - <g fill="none" fill-rule="evenodd"> - <path d="M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z" fill="#4285F4"/> - <path d="M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z" fill="#34A853"/> - <path d="M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z" fill="#FBBC05"/> - <path d="M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z" fill="#EA4335"/> - </g> - </svg> - </span> - <span class="button-label">Sign in with Google</span> - </div> - </a> - </div> - </div> - <button style="padding-top: 150px; text-align: center" onclick="checkIfLoggedIn()"></button> + <div id="container" style="padding-top: 150px; text-align: center"></div> </body> <script src='./js/index.js'></script> <script src='./js/lib/libde265.min.js'></script> diff --git a/web-service/server/public/js/index.js b/web-service/server/public/js/index.js index 872bea82d4017b05ecc0801036f5bc828098c9db..77f275e4268680ccc88e63f6b339c1d39706af92 100644 --- a/web-service/server/public/js/index.js +++ b/web-service/server/public/js/index.js @@ -3,9 +3,7 @@ const checkIfLoggedIn = async () => { console.log(token) if(!token){ console.log("You need to login") - const containerDiv = document.getElementById('container'); - containerDiv = login; - //User has a token saved in the browser + renderLogin() }else{ //Check if the token is valid @@ -15,12 +13,9 @@ const checkIfLoggedIn = async () => { }) console.log('RESPONSE', response) - //Token is valid, show the streams + //Token is valid, show available streams if(response.status === 200){ console.log("SUCCESS") - /* - Most likely it will render a new HTML file - */ renderThumbnails() } } @@ -41,10 +36,17 @@ const getAvailableStreams = async () => { return streams; } +const videoPlayer = () => { + const containerDiv = document.getElementById('container'); + const asd = 'yeahboiii' + window.open(`http://localhost:8080/stream?uri=${asd}`) +} -//Creates thumbnail (image) for all available streams and adds them to div class='container' +/** + * Creates thumbnail (image) for all available streams and adds them to div class='container' + */ const renderThumbnails = async () => { const thumbnails = await getAvailableStreams(); console.log('THUMBNAILS', thumbnails) @@ -68,4 +70,31 @@ const renderThumbnails = async () => { return } } +} + +/** + * Renders button that will redirect to google login + */ +const renderLogin = () => { + const containerDiv = document.getElementById('container'); + containerDiv.innerHTML = + `<div id='Login'> + <h2>Welcome to Future Technology Lab</h2> + <h3>Please login!</h3> + <a className="button" onClick="handleLogin()"> + <div> + <span class="svgIcon t-popup-svg"> + <svg class="svgIcon-use" width="25" height="37" viewBox="0 0 25 25"> + <g fill="none" fill-rule="evenodd"> + <path d="M20.66 12.693c0-.603-.054-1.182-.155-1.738H12.5v3.287h4.575a3.91 3.91 0 0 1-1.697 2.566v2.133h2.747c1.608-1.48 2.535-3.65 2.535-6.24z" fill="#4285F4"/> + <path d="M12.5 21c2.295 0 4.22-.76 5.625-2.06l-2.747-2.132c-.76.51-1.734.81-2.878.81-2.214 0-4.088-1.494-4.756-3.503h-2.84v2.202A8.498 8.498 0 0 0 12.5 21z" fill="#34A853"/> + <path d="M7.744 14.115c-.17-.51-.267-1.055-.267-1.615s.097-1.105.267-1.615V8.683h-2.84A8.488 8.488 0 0 0 4 12.5c0 1.372.328 2.67.904 3.817l2.84-2.202z" fill="#FBBC05"/> + <path d="M12.5 7.38c1.248 0 2.368.43 3.25 1.272l2.437-2.438C16.715 4.842 14.79 4 12.5 4a8.497 8.497 0 0 0-7.596 4.683l2.84 2.202c.668-2.01 2.542-3.504 4.756-3.504z" fill="#EA4335"/> + </g> + </svg> + </span> + <span class="button-label">Sign in with Google</span> + </div> + </a> + </div>` } \ No newline at end of file diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index 49a9d78dbb586d2a84abc5edaeec5d2a8d8dd740..0c99b14e6e16a20b0ab0e47085aa3c48459be51c 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -9,7 +9,8 @@ const keys = require('./passport/keys') const mongoose = require('mongoose') const config = require('./utils/config') const User = require('./models/users') -const Config = require('./models/configs') +const Configs = require('./models/generic') +const Disparity = require('./models/disparity') const bodyParser = require('body-parser') // ---- INDEXES ---------------------------------------------------------------- @@ -159,11 +160,14 @@ app.get('/', (req, res) => { app.post('/auth/validation', async (req, res) => { const token = req.headers.authorization.split(" ") const decoded = jwt.verify(token[1], keys.jwt.secret) + console.log('DECODED', decoded) try{ - const data = await User.find({decoded}) - if(data){ - console.log(data) + const data = await User.find({ googleID: decoded }) + console.log('DATA', data) + if(data.length !== 0){ return res.status(200).json("success") + }else { + return res.status(403) } }catch(err){ console.log('ERROR ERROR') @@ -205,7 +209,6 @@ app.get('/stream/depth', (req, res) => { app.post('/stream/config', async (req, res) => { const {board_size, square_size, frame_delay, num_frames, name} = req.body - const savedConfigs = new Config({ board_size, square_size, @@ -213,6 +216,7 @@ app.post('/stream/config', async (req, res) => { num_frames, name }); + try{ await savedConfigs.save(); return res.status(200).json('Your configurations were saved successfully') @@ -223,16 +227,103 @@ app.post('/stream/config', async (req, res) => { }) app.get('/stream/config', async(req, res) => { - //example of uri /stream/config?uri=ftl.utu.fi/stream/calibrations/ - //example of uri /stream/config?uri=ftl.utu.fi/stream/calibrations/board_size/value=1 - const uri = req.query.uri + //example of uri ftlab.utu.fi/stream/config?uri=ftl://utu.fi/stream/configurations/calibrations/default/board_size + + const wholeURI = encodeURIComponent(req.query.uri) + const baseURI = "ftl%3A%2F%2Futu.fi%2Fstream%2Fconfigurations" + const uri = wholeURI.substring(47); + let depth = uri.split("%2F"); + console.log("DEPTH", depth) + let queryURI = baseURI + '%2F' + depth[0] + console.log("QUERYURI", queryURI) + let response = await Configs.find({ URI : queryURI}); + + const objects = response[0].data + console.log(objects) + //Check that DB has atleast some data + if(response.length){ + const firstLayerObj = Object.entries(objects) + const helpObj = {} + for(const [key, value] of firstLayerObj){ + //Save the right named object into helpObj + if(key == depth[1]){ + helpObj[`${key}`] = value + } + } + //If the URI ends into the second objects name e.g. default + if(depth.length==2){ + return res.status(200).json(helpObj) + + //Else send the value of the attribute + }else if(depth.length==3){ + const secondLayerObj = Object.values(helpObj); + const finalLayer = Object.entries(secondLayerObj[0]); + for(const [key, value] of finalLayer){ + console.log("PIIPPIIP") + if(key == depth[2]){ + const data = { data : value } + return res.status(200).json(data) + } + } + } + } + return res.status(200).json("kääkkääk"); + + + + //FOR LATER + // const uri = wholeURI.substring(47) + // let depth = uri.split("%2F"); + // console.log(depth[1]) + + // if(depth.length == 2){ + // const splitted = wholeURI.split(depth[1]) + // const uri = splitted[0].substring(0, splitted[0].length-3) + // console.log('VAL', uri) + // const responseData = await Configs.find({URI : uri}) + // const realData = responseData[0].data + // const obj = Object.entries(realData); + // const helpObj = {} + // for(const [key, data] of obj){ + // //Check if the data is an object + // if(data ==) + // console.log('PIIPPIIP', depth[1] in data) + // if(depth[1] in data) { + // helpObj[`${key}`] = data + // } + // } + // console.log("HELPOBJECT", helpObj) + // const actualData = Object.entries(helpObj) + // for(const [key, data] of actualData){ + // console.log("KEY2", key) + // console.log("DATA2", data) + // } + // return res.status(200).json(realData) + // } + + + // if(depth.length ==3){ + // get the value + // save the get the first depth + // save the value with default values into the first depth + // } + + console.log(depth) + console.log(wholeURI) console.log(uri) + console.log(depth) - //const listOfCongifs = await Config.find({}); - return res.status(200).json(uri) + return res.send(200) }) -//app.get('/stream', (req, res)) +const uriParser = (uri) => { + +} + +app.get('/stream', (req, res) => { + let uri = req.query.uri; + console.log(uri) +}) /* * Route for Google authentication API page @@ -419,6 +510,26 @@ app.ws('/', (ws, req) => { } }); + /** + * Get configuration JSON values + */ + p.bind("get_cfg", (cb, uri) => { + let peer = uri_data[uri].peer + if(peer){ + peer.rpc("get_cfg", cb, uri) + } + }) + + /** + * Update certain URIs values + */ + p.bind("update_cfg", (uri, json) => { + let peer = uri_data[uri].peer + if(peer){ + peer.send("update_cfg", uri, json) + } + }) + // Register a new stream p.bind("add_stream", (uri) => { console.log("Adding stream: ", uri); diff --git a/web-service/server/src/models/disparity.js b/web-service/server/src/models/disparity.js new file mode 100644 index 0000000000000000000000000000000000000000..03795f815cead0e1663a8595b0656df6071b63ef --- /dev/null +++ b/web-service/server/src/models/disparity.js @@ -0,0 +1,23 @@ +const mongoose = require('mongoose') + +const disparitySchema = mongoose.Schema({ + name: {type: String, default: null}, + algorithm: {type: String, default: 'libsgm'}, + use_cuda: {type: Boolean, default: true}, + minimum: {type: Number, default: 0}, + maximum: {type: Number, default: 256}, + tau: {type: Number, default: 0.0}, + gamma: {type: Number, default: 0.0}, + window_size: {type: Number, default: 5}, + sigma: {type: Number, default: 1.5}, + lambda: {type: Number, default: 8000.0} +}) + +disparitySchema.set('toJSON', { + transform: (document, returnedObject) => { + delete returnedObject._id + delete returnedObject.__v + } + }) + +module.exports = mongoose.model('disparityConfig', disparitySchema) \ No newline at end of file diff --git a/web-service/server/src/models/generic.js b/web-service/server/src/models/generic.js new file mode 100644 index 0000000000000000000000000000000000000000..efb4db9afb2a7b4797d547246f88d8010a6ee325 --- /dev/null +++ b/web-service/server/src/models/generic.js @@ -0,0 +1,53 @@ +/** + * This is the generic model for the MongoDB + * + * Single collection contains the following values + * URI: {type: String, not null} + * data: Object + * the actual data + * + * + * e.g + * + * URI: 'ftl://utu.fi/stream/configurations/calibrations + * data: { + * default: { + * board_size: [9,7] + * square_size: 1 + * } + * + * HD_quality: { + * board_size: [5,2] + * square_size: 5 + * } + * } + * + * URI: 'ftl://utu.fi/stream/configurations/disparity/name/' + * data: { + * default: { + * name: 'default' + * } + * + * HD_quality: { + * name: 'HD_quality' + * } + * + * } + */ + + +const mongoose = require('mongoose') + +const configsSchema = mongoose.Schema({ + URI: String, + data: Object + }) + + configsSchema.set('toJSON', { + transform: (document, returnedObject) => { + delete returnedObject._id + delete returnedObject.__v + } + }) + +module.exports = mongoose.model('configs', configsSchema) \ No newline at end of file