Skip to content
Snippets Groups Projects
Commit 2c840ac5 authored by Sami Spets's avatar Sami Spets
Browse files

Minor progress

parent 2e0ff1e9
No related branches found
No related tags found
No related merge requests found
Pipeline #15882 passed
...@@ -44,7 +44,6 @@ body { ...@@ -44,7 +44,6 @@ body {
} }
#container { #container {
height: 100%;
padding: 0; padding: 0;
margin: 0; margin: 0;
display: -webkit-box; display: -webkit-box;
......
const checkIfLoggedIn = async () => { const checkIfLoggedIn = async () => {
const token = window.localStorage.getItem('token') // const token = window.localStorage.getItem('token')
console.log(token) // console.log(token)
if(!token){ // if(!token){
console.log("You need to login") // console.log("You need to login")
renderLogin() // renderLogin()
}else{ // }else{
//Check if the token is valid // //Check if the token is valid
const response = await fetch('http://localhost:8080/auth/validation', { // const response = await fetch('http://localhost:8080/auth/validation', {
method: 'POST', // method: 'POST',
headers: {'Authorization': token} // headers: {'Authorization': token}
}) // })
console.log('RESPONSE', response) // console.log('RESPONSE', response)
//Token is valid, show available streams // //Token is valid, show available streams
if(response.status === 200){ // if(response.status === 200){
console.log("SUCCESS") // console.log("SUCCESS")
renderThumbnails() renderThumbnails()
} // }
} // }
} }
//Redirects the user to google authentication //Redirects the user to google authentication
...@@ -26,6 +26,9 @@ const handleLogin = () => { ...@@ -26,6 +26,9 @@ const handleLogin = () => {
window.location.href="/google"; window.location.href="/google";
} }
let current_uri = '';
/** /**
* Returns a list of available streams * Returns a list of available streams
*/ */
...@@ -38,41 +41,50 @@ const getAvailableStreams = async () => { ...@@ -38,41 +41,50 @@ const getAvailableStreams = async () => {
const videoPlayer = () => { const videoPlayer = () => {
const containerDiv = document.getElementById('container'); const containerDiv = document.getElementById('container');
const asd = 'yeahboiii'
window.open(`http://localhost:8080/stream?uri=${asd}`) 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' * Creates thumbnail (image) for all available streams and adds them to div class='container'
*/ */
const renderThumbnails = async () => { const renderThumbnails = async () => {
// const thumbnails = await getAvailableStreams(); const thumbnails = await getAvailableStreams();
//console.log('THUMBNAILS', thumbnails) console.log('THUMBNAILS', thumbnails)
const containerDiv = document.getElementById('container') const containerDiv = document.getElementById('container')
containerDiv.innerHTML = ''; containerDiv.innerHTML = '';
console.log(containerDiv) console.log(containerDiv)
for(var i=0; i<2; i++){ for(var i=0; i<thumbnails.length; i++){
// const encodedURI = encodeURIComponent(thumbnails[i]) const encodedURI = encodeURIComponent(thumbnails[i])
// console.log("THUMBNAIL[i]", thumbnails[i]) console.log("THUMBNAIL[i]", thumbnails[i])
// try{ try{
// const someData = await fetch(`http://localhost:8080/stream/rgb?uri=${encodedURI}`) const someData = await fetch(`http://localhost:8080/stream/rgb?uri=${encodedURI}`)
// console.log('SOME DATA', someData) console.log('SOME DATA', someData)
// if(!someData.ok){ if(!someData.ok){
// throw new Error('Image not found') 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)
// }
} }
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 * Renders button that will redirect to google login
...@@ -101,23 +113,30 @@ const renderLogin = () => { ...@@ -101,23 +113,30 @@ const renderLogin = () => {
</div>` </div>`
} }
// const createCard = (url, viewers, uri) => { //FOR DESKTOP
// return `<div class='ftlab-card-component' > const createCard = (url, viewers, uri) => {
// <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' > return `<div class='ftlab-card-component' >
<img src='https://via.placeholder.com/250x150' class="thumbnail-img" width="250px" alt="Hups"></img> <img src='${url}' class="thumbnail-img" alt="Hups" width="250px"></img>
<p>Viewers: yes</p> <p>Viewers: ${viewers}</p>
<button onclick="window.location.href='/stream/URI'">button</button> <button onclick="current_uri=${uri}; window.location.href='/stream?uri=${uri}';">button</button>
</div>` </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 cardLogic = () => {
const cards = document.getElementsByClassName('ftlab-card-component'); const cards = document.getElementsByClassName('ftlab-card-component');
console.log("CARDS", cards)
} }
\ No newline at end of file
...@@ -10,7 +10,6 @@ const mongoose = require('mongoose') ...@@ -10,7 +10,6 @@ const mongoose = require('mongoose')
const config = require('./utils/config') 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 Disparity = require('./models/disparity')
const bodyParser = require('body-parser') const bodyParser = require('body-parser')
//const cors = require('cors') //const cors = require('cors')
...@@ -29,13 +28,13 @@ passport.deserializeUser((userDataFromCookie, done) => { ...@@ -29,13 +28,13 @@ passport.deserializeUser((userDataFromCookie, done) => {
done(null, userDataFromCookie); done(null, userDataFromCookie);
}) })
mongoose.connect(config.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true }) // mongoose.connect(config.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => { // .then(() => {
console.log('Connected to MongoDB'); // console.log('Connected to MongoDB');
}) // })
.catch((err) => { // .catch((err) => {
console.log(err); // console.log(err);
}) // })
let peer_by_id = {}; let peer_by_id = {};
//let uri_to_peer = {}; //let uri_to_peer = {};
...@@ -269,57 +268,15 @@ app.get('/stream/config', async(req, res) => { ...@@ -269,57 +268,15 @@ app.get('/stream/config', async(req, res) => {
} }
} }
} }
return res.status(200).json("kääkkääk"); return res.status(200).json("Nothing found");
//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
// }
}) })
app.get('/stream', (req, res) => { app.get('/stream', (req, res) => {
let uri = req.query.uri; 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) console.log(uri)
}) })
...@@ -403,10 +360,7 @@ function broadcastExcept(exc, name, ...args) { ...@@ -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) => { app.ws('/', (ws, req) => {
console.log("New web socket request"); console.log("New web socket request");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment