mirror of
https://github.com/sexybiggetje/pixdisp.git
synced 2024-11-22 01:11:02 +01:00
Add basic camera support to UI. Fun times.
This commit is contained in:
parent
f9ad39ea01
commit
ba74bd2de2
3 changed files with 43 additions and 1 deletions
|
@ -9,4 +9,8 @@
|
||||||
height: 10%;
|
height: 10%;
|
||||||
float: left;
|
float: left;
|
||||||
margin: 0 1% 1% 0;
|
margin: 0 1% 1% 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#videoStream {
|
||||||
|
display: none;
|
||||||
}
|
}
|
|
@ -19,6 +19,7 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section class="section view">
|
<section class="section view">
|
||||||
|
<a class="button is-small" id="captureCamera">Camera</a>
|
||||||
<a class="button is-small is-success" id="submitImage">Submit</a>
|
<a class="button is-small is-success" id="submitImage">Submit</a>
|
||||||
<br /><br />
|
<br /><br />
|
||||||
<div class="columns">
|
<div class="columns">
|
||||||
|
@ -29,12 +30,13 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<video id="videoStream"></video>
|
||||||
</section>
|
</section>
|
||||||
<footer class="footer">
|
<footer class="footer">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="content has-text-centered">
|
<div class="content has-text-centered">
|
||||||
<p>
|
<p>
|
||||||
<strong>Pixel Display</strong> (pixdisp). The source code is licensed <a href="http://opensource.org/licenses/mit-license.php">MIT</a>. Fork, patch, contribute at Github.
|
<strong>Pixel Display</strong> (pixdisp). The source code is licensed <a href="http://opensource.org/licenses/mit-license.php" target="_blank">MIT</a>. <a href="https://github.com/sexybiggetje/pixdisp" target="_blank">Fork, patch, contribute at Github</a>.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -30,6 +30,7 @@ class App
|
||||||
|
|
||||||
canvas.addEventListener( 'click', this.handleCanvas );
|
canvas.addEventListener( 'click', this.handleCanvas );
|
||||||
document.getElementById( 'submitImage' ).addEventListener( 'click', this.submitCanvas );
|
document.getElementById( 'submitImage' ).addEventListener( 'click', this.submitCanvas );
|
||||||
|
document.getElementById( 'captureCamera' ).addEventListener( 'click', this.captureCamera );
|
||||||
|
|
||||||
this.canvas = canvas;
|
this.canvas = canvas;
|
||||||
this.context = canvas.getContext( '2d' );
|
this.context = canvas.getContext( '2d' );
|
||||||
|
@ -164,6 +165,41 @@ class App
|
||||||
|
|
||||||
obj = encodeURI( 'data=' + JSON.stringify( obj ) );
|
obj = encodeURI( 'data=' + JSON.stringify( obj ) );
|
||||||
request.send( obj );
|
request.send( obj );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
captureCamera( ev ) {
|
||||||
|
|
||||||
|
if ( ev.preventDefault ) {
|
||||||
|
ev.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
navigator.mediaDevices.getUserMedia( { video: true, audio: false } )
|
||||||
|
.then( function( stream ) {
|
||||||
|
let vs = document.getElementById( 'videoStream' );
|
||||||
|
vs.srcObject = stream;
|
||||||
|
vs.play();
|
||||||
|
|
||||||
|
app.drawVideoToCanvas();
|
||||||
|
} )
|
||||||
|
.catch( function( err ) {
|
||||||
|
console.warn( err );
|
||||||
|
} )
|
||||||
|
;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
drawVideoToCanvas() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
let vs = document.getElementById( 'videoStream' );
|
||||||
|
app.context.drawImage( vs, 0, 0, app.canvas.width, app.canvas.height );
|
||||||
|
|
||||||
|
} catch ( err ) { }
|
||||||
|
|
||||||
|
window.requestAnimationFrame( app.drawVideoToCanvas );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue