diff --git a/web-service/server/public/css/index.css b/web-service/server/public/css/index.css index 1a1d01a1a9152da2700863fbc2a4b3e565467623..7eb21e91ae3f3c7929ca71ca867c5ac7938fbe6d 100644 --- a/web-service/server/public/css/index.css +++ b/web-service/server/public/css/index.css @@ -44,7 +44,6 @@ body { } #container { - height: 100%; padding: 0; margin: 0; display: -webkit-box; diff --git a/web-service/server/public/js/index.js b/web-service/server/public/js/index.js index 0f9ca0e384bab661d84948799756662ff4526035..ca18fad653c631593ec253de5c14aa19abec1fb8 100644 --- a/web-service/server/public/js/index.js +++ b/web-service/server/public/js/index.js @@ -1,31 +1,34 @@ const checkIfLoggedIn = async () => { - const token = window.localStorage.getItem('token') - console.log(token) - if(!token){ - console.log("You need to login") - renderLogin() - }else{ +// const token = window.localStorage.getItem('token') +// console.log(token) +// if(!token){ +// console.log("You need to login") +// renderLogin() +// }else{ - //Check if the token is valid - const response = await fetch('http://localhost:8080/auth/validation', { - method: 'POST', - headers: {'Authorization': token} - }) - console.log('RESPONSE', response) +// //Check if the token is valid +// const response = await fetch('http://localhost:8080/auth/validation', { +// method: 'POST', +// headers: {'Authorization': token} +// }) +// console.log('RESPONSE', response) - //Token is valid, show available streams - if(response.status === 200){ - console.log("SUCCESS") +// //Token is valid, show available streams +// if(response.status === 200){ +// console.log("SUCCESS") renderThumbnails() - } - } -} +// } +// } + } //Redirects the user to google authentication const handleLogin = () => { window.location.href="/google"; } +let current_uri = ''; + + /** * Returns a list of available streams */ @@ -38,42 +41,51 @@ const getAvailableStreams = async () => { const videoPlayer = () => { const containerDiv = document.getElementById('container'); - const asd = 'yeahboiii' window.open(`http://localhost:8080/stream?uri=${asd}`) } +let webSocket = new WebSocket('ws://localhost:8080/') /** * 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) + const thumbnails = await getAvailableStreams(); + console.log('THUMBNAILS', thumbnails) const containerDiv = document.getElementById('container') containerDiv.innerHTML = ''; console.log(containerDiv) - for(var i=0; i<2; i++){ - // const encodedURI = encodeURIComponent(thumbnails[i]) - // console.log("THUMBNAIL[i]", thumbnails[i]) - // try{ - // const someData = await fetch(`http://localhost:8080/stream/rgb?uri=${encodedURI}`) - // console.log('SOME DATA', someData) - // if(!someData.ok){ - // throw new Error('Image not found') - // } - // const myBlob = await someData.blob(); - // console.log('BLOB', myBlob) - // const objectURL = URL.createObjectURL(myBlob); - containerDiv.innerHTML += createCard() - // containerDiv.innerHTML += createCard(objectURL, i+4, encodedURI) - // }catch(err){ - // console.log("Couldn't create thumbnail"); - // console.log(err) - // } + for(var i=0; i<thumbnails.length; i++){ + const encodedURI = encodeURIComponent(thumbnails[i]) + console.log("THUMBNAIL[i]", thumbnails[i]) + try{ + const someData = await fetch(`http://localhost:8080/stream/rgb?uri=${encodedURI}`) + console.log('SOME DATA', someData) + if(!someData.ok){ + throw new Error('Image not found') + } + const myBlob = await someData.blob(); + console.log('BLOB', myBlob) + const objectURL = URL.createObjectURL(myBlob); + // containerDiv.innerHTML += createCard() + containerDiv.innerHTML += createCard(objectURL, i+4, encodedURI) + }catch(err){ + console.log("Couldn't create thumbnail"); + console.log(err) + } } } +// //FOR LAPTOP +// const renderThumbnails = async () => { +// const containerDiv = document.getElementById('container') +// containerDiv.innerHTML = ''; +// for(var i=0; i<2; i++){ +// containerDiv.innerHTML += createCard() +// } +// } + /** * Renders button that will redirect to google login */ @@ -101,23 +113,30 @@ const renderLogin = () => { </div>` } -// const createCard = (url, viewers, uri) => { -// return `<div class='ftlab-card-component' > -// <img src='${url}' class="thumbnail-img" alt="Hups"></img> -// <p>Viewers: ${viewers}</p> -// <button onclick="window.location.href='/stream/${uri}'">button</button> -// </div>` -// } - -const createCard = () => { - return `<div class='ftlab-card-component'> - <img src='https://via.placeholder.com/250x150' class="thumbnail-img" width="250px" alt="Hups"></img> - <p>Viewers: yes</p> - <button onclick="window.location.href='/stream/URI'">button</button> +//FOR DESKTOP +const createCard = (url, viewers, uri) => { + return `<div class='ftlab-card-component' > + <img src='${url}' class="thumbnail-img" alt="Hups" width="250px"></img> + <p>Viewers: ${viewers}</p> + <button onclick="current_uri=${uri}; window.location.href='/stream?uri=${uri}';">button</button> </div>` } +const connectToStream = () => { + let ws = new WebSocket('ws://localhost:8080/'); + ws.onopen = (e) => { + } +} + +//FOR LAPTOP +// const createCard = () => { +// return `<div class='ftlab-card-component'> +// <img src='https://via.placeholder.com/250x150' class="thumbnail-img" width="250px" alt="Hups"></img> +// <p>Viewers: yes</p> +// <button onclick="window.location.href='/stream?uri'">button</button> +// </div>` +// } + const cardLogic = () => { const cards = document.getElementsByClassName('ftlab-card-component'); - console.log("CARDS", cards) } \ No newline at end of file diff --git a/web-service/server/src/index.js b/web-service/server/src/index.js index a1c03df13bcbfa85d8a61a6fd3517678f2042635..6f94e8fa2beb9af458bff2f753e01d9ae15ca41e 100644 --- a/web-service/server/src/index.js +++ b/web-service/server/src/index.js @@ -10,7 +10,6 @@ const mongoose = require('mongoose') const config = require('./utils/config') const User = require('./models/users') const Configs = require('./models/generic') -const Disparity = require('./models/disparity') const bodyParser = require('body-parser') //const cors = require('cors') @@ -29,13 +28,13 @@ passport.deserializeUser((userDataFromCookie, done) => { done(null, userDataFromCookie); }) -mongoose.connect(config.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true }) - .then(() => { - console.log('Connected to MongoDB'); - }) - .catch((err) => { - console.log(err); - }) +// mongoose.connect(config.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true }) +// .then(() => { +// console.log('Connected to MongoDB'); +// }) +// .catch((err) => { +// console.log(err); +// }) let peer_by_id = {}; //let uri_to_peer = {}; @@ -242,7 +241,7 @@ app.get('/stream/config', async(req, res) => { const objects = response[0].data console.log(objects) - //Check that DB has atleast some data + //Check that DB has at least some data if(response.length){ const firstLayerObj = Object.entries(objects) const helpObj = {} @@ -269,57 +268,15 @@ app.get('/stream/config', async(req, res) => { } } } - 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 - // } + return res.status(200).json("Nothing found"); + }) app.get('/stream', (req, res) => { let uri = req.query.uri; + uri_data[uri] - - /** - * It should render a new html page that has it's own dedicated js-file - * The js-file should do everything related to the decoding of bitstream. - */ console.log(uri) }) @@ -403,10 +360,7 @@ function broadcastExcept(exc, name, ...args) { } } -/** - * Need to think about how to use these. - * Will it be in the '/' route or in the '/streams/<stream>' route - */ + app.ws('/', (ws, req) => { console.log("New web socket request");