Created
October 13, 2019 16:01
-
-
Save evansalter/694487c86f6c6d79892e418840ad6c9a to your computer and use it in GitHub Desktop.
Photo Booth Software
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
<div v-if="!cam.connected"> | |
Waiting for camera... | |
</div> | |
<div v-if="cam.connected"> | |
<div class="pics"> | |
<img class="pic" v-for="pic in pictures" :key="pic" :src="pic"/> | |
</div> | |
<div class="button-div" v-if="!active || countdown !== 0"> | |
<button class="button" @click="startPics" :disabled="active"> | |
<span v-if="countdown === 0">📸</span> | |
<span v-if="countdown !== 0">{{ countdown }}</span> | |
</button> | |
</div> | |
</div> | |
</div> | |
</template> | |
<script> | |
import SonyCamera from 'sony-camera' | |
export default { | |
name: 'App', | |
components: {}, | |
data: function () { | |
return { | |
cam: new SonyCamera('localhost', 3000), | |
liveViewFrame: '', | |
pictures: [], | |
countdown: 0, | |
active: false | |
} | |
}, | |
methods: { | |
startPics: function (event) { | |
this.active = true | |
this.countdown = 3 | |
var countID = setInterval(function () { | |
this.countdown -= 1 | |
if (this.countdown !== 0) { | |
return | |
} | |
clearInterval(countID) | |
this.capture(4) | |
}.bind(this), 1000) | |
}, | |
capture: function (numToTake) { | |
this.cam.capture(true, function (x, name, imageData) { | |
if (name) { | |
console.log(name) | |
this.pictures.push(`http://localhost:3000/postview/${name}`) | |
if (numToTake > 1) { | |
setTimeout(function () { this.capture(numToTake - 1) }.bind(this), 2000) | |
} else { | |
setTimeout(function () { | |
this.pictures = [] | |
this.active = false | |
}.bind(this), 10000) | |
} | |
} | |
}.bind(this)) | |
} | |
}, | |
mounted: function () { | |
this.cam.connect(console.log) | |
} | |
} | |
</script> | |
<style> | |
body { | |
margin: 0; | |
} | |
#app { | |
font-family: 'Avenir', Helvetica, Arial, sans-serif; | |
-webkit-font-smoothing: antialiased; | |
-moz-osx-font-smoothing: grayscale; | |
text-align: center; | |
color: #2c3e50; | |
display: flex; | |
justify-content: center; | |
} | |
.pics { | |
display: grid; | |
grid-template-columns: 50% 50%; | |
grid-template-rows: 50% 50%; | |
max-width: 1100px; | |
} | |
.pic { | |
width: 100%; | |
} | |
.button-div { | |
position: absolute; | |
bottom: 0; | |
width: 100%; | |
margin-bottom: 10px; | |
left: 0; | |
} | |
.button { | |
height: 100px; | |
width: 100px; | |
border-radius: 90px; | |
background: red; | |
font-size: 45px; | |
color: white; | |
} | |
.button-hidden { | |
bottom: -150px; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'); | |
http.createServer(onRequest).listen(3000); | |
function onRequest(client_req, client_res) { | |
console.log('serve: ' + client_req.url); | |
var options = { | |
hostname: '192.168.122.1', | |
port: 8080, | |
path: client_req.url, | |
method: client_req.method, | |
headers: client_req.headers | |
}; | |
var proxy = http.request(options, function (res) { | |
res.headers['access-control-allow-origin'] = '*' | |
client_res.writeHead(res.statusCode, res.headers) | |
res.pipe(client_res, { | |
end: true | |
}).on('error', console.log); | |
}); | |
client_req.pipe(proxy, { | |
end: true | |
}).on('error', console.log); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment