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

Added comments

parent f6a0b74c
Branches
Tags
No related merge requests found
Pipeline #14854 passed
This diff is collapsed.
...@@ -35,7 +35,6 @@ body { ...@@ -35,7 +35,6 @@ body {
display: inline-block; display: inline-block;
} }
.div { img {
vertical-align: center; padding: 25px;
text-align: center
} }
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html onload="checkIfLoggedIn()"> <html>
<head> <head>
<title>FTL web-service</title> <title>FTL web-service</title>
<link rel="stylesheet" href="./css/index.css">
</head> </head>
<body onload="checkIfLoggedIn()"> <body onload="checkIfLoggedIn()">
<div id="container" style="padding-top: 150px; text-align: center"> <div id="container" style="padding-top: 150px; text-align: center">
...@@ -27,4 +28,5 @@ ...@@ -27,4 +28,5 @@
</div> </div>
</body> </body>
<script src='./js/index.js'></script> <script src='./js/index.js'></script>
<script src='./js/lib/libde265.min.js'></script>
</html> </html>
\ No newline at end of file
...@@ -2,20 +2,65 @@ ...@@ -2,20 +2,65 @@
const checkIfLoggedIn = async () => { const checkIfLoggedIn = async () => {
const token = window.localStorage.getItem('token') const token = window.localStorage.getItem('token')
if(!token){ if(!token){
console.log("FAIL") console.log("You need to login")
return "" //User has a token saved in the browser
}else{ }else{
//validate that token
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)
//Token is valid
if(response.status === 200){ if(response.status === 200){
console.log("SUCCESS") console.log("SUCCESS")
/*
Most likely it will render a new HTML file
*/
document.getElementById('container').innerHTML = "<p>Salainen sivu</p>" document.getElementById('container').innerHTML = "<p>Salainen sivu</p>"
} }
} }
} }
//Redirects the user to google authentication
const handleLogin = () => { const handleLogin = () => {
window.location.href="/google"; window.location.href="/google";
} }
/**
* Returns a list of available streams
*/
const getAvailableStreams = async () => {
const streamsInJson = await fetch('http://localhost:8080/streams');
const streams = await streamsInJson.json();
return streams;
}
//Creates thumbnail (image) for all available streams and adds them to div class='container'
const renderThumbnails = async () => {
// const thumbnails = 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])
// 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();
// const objectURL = URL.createObjectURL(myBlob);
// containerDiv.innerHTML += `<img src='${objectURL}' alt="Hups" width='500px'></img>`
containerDiv.innerHTML += `<img src='https://via.placeholder.com/350x150' alt="Hups" width='350px'></img>`
// }catch(err){
// console.log("Couldn't create thumbnail");
// return
// }
}
}
\ No newline at end of file
...@@ -116,6 +116,7 @@ RGBDStream.prototype.subscribe = function() { ...@@ -116,6 +116,7 @@ RGBDStream.prototype.subscribe = function() {
} }
RGBDStream.prototype.pushFrames = function(latency, spacket, packet) { RGBDStream.prototype.pushFrames = function(latency, spacket, packet) {
//Checks that the type is jpg
if (packet[0] === 0){ if (packet[0] === 0){
if (spacket[1] & 0x1) this.depth = packet[4]; if (spacket[1] & 0x1) this.depth = packet[4];
else this.rgb = packet[4]; else this.rgb = packet[4];
...@@ -143,12 +144,10 @@ app.get('/', (req, res) => { ...@@ -143,12 +144,10 @@ app.get('/', (req, res) => {
}); });
app.post('/auth/validation', (req, res) => { app.post('/auth/validation', (req, res) => {
const token = req.headers.authorization const token = req.headers.authorization.split(" ")
const parts = token.split(" ") const decoded = jwt.verify(token[1], keys.jwt.secret)
const decoded = jwt.verify(parts[1], keys.jwt.secret) return res.status(200)
console.log(decoded)
return res.status(200).json("Piipppiip")
}) })
// app.get('/login/google', (req, res) => { // app.get('/login/google', (req, res) => {
// }) // })
...@@ -158,6 +157,12 @@ app.get('/streams', (req, res) => { ...@@ -158,6 +157,12 @@ app.get('/streams', (req, res) => {
res.json(Object.keys(uri_data)); res.json(Object.keys(uri_data));
}); });
/**
* A list that has Object.keys(uri_data) values and also the image that is
* binded to that
* Joku lista missä on Object.keys(uri_datan) arvot ja niihin bindattu
* se
*/
app.get('/stream/rgb', (req, res) => { app.get('/stream/rgb', (req, res) => {
let uri = req.query.uri; let uri = req.query.uri;
if (uri_data.hasOwnProperty(uri)) { if (uri_data.hasOwnProperty(uri)) {
...@@ -186,9 +191,9 @@ app.get('/google', passport.authenticate('google', { ...@@ -186,9 +191,9 @@ app.get('/google', passport.authenticate('google', {
scope: ['profile'] scope: ['profile']
})) }))
/* /**
* Google authentication API callback route. * Google authentication API callback route.
* Sets the JWT to clients browser and redirects the user back to front page (now has thumbnails). * Sets the JWT to clients browser and redirects the user back to front page.
*/ */
app.get('/auth/google/redirect', passport.authenticate('google'), (req, res) => { app.get('/auth/google/redirect', passport.authenticate('google'), (req, res) => {
console.log(req.user) console.log(req.user)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment