mirror of
https://github.com/amark/gun.git
synced 2025-06-05 21:56:51 +00:00
cleaner & smaller video & upload
This commit is contained in:
parent
c45950a771
commit
47a841fbcd
@ -1,9 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<center>
|
||||
<video width="100%" controls="controls"></video>
|
||||
<video width="100%" controls autoplay></video>
|
||||
<audio width="100%" controls autoplay></audio>
|
||||
<img style="max-width: 100%;">
|
||||
<span id="up">Drag & drop video or image to upload!</span>
|
||||
<p>Drag & drop videos, songs, or images to upload!</p>
|
||||
</center>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
@ -22,11 +23,12 @@ $('html').upload(function resize(eve, up){
|
||||
})
|
||||
|
||||
gun.get('test').get('paste').on(function(data){
|
||||
$('video, img').css({display: 'none'})
|
||||
$('video, audio, img').css({display: 'none'})
|
||||
if(!data){ return }
|
||||
var type = data.split(';')[0], ui;
|
||||
if(type.indexOf('image') + 1){ ui = $("img") }
|
||||
if(type.indexOf('video') + 1){ ui = $('video') }
|
||||
if(type.indexOf('audio') + 1){ ui = $('audio') }
|
||||
($(ui).css({display: 'block'}).get(0)||{}).src = data;
|
||||
})
|
||||
</script>
|
@ -1,9 +1,8 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<video id="video" width="100%"></video>
|
||||
<video id="video" width="100%" controls autoplay></video>
|
||||
<center>
|
||||
<input id="pass" placeholder="password">
|
||||
<button id="play">Play</button>
|
||||
Record <button class="record">Camera</button> or <button class="record">Screen</button>
|
||||
</center>
|
||||
|
||||
@ -13,27 +12,36 @@
|
||||
|
||||
<script>
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
var record = {recorder: null, recording: false};
|
||||
|
||||
$('.record').on('click', function(){
|
||||
if(record.ing){ return }
|
||||
record.stream($(this).text());
|
||||
gun.get('test').get('video').on(async function(data){
|
||||
if($('#pass').val()){ data = await SEA.decrypt(data, $('#pass').val()) }
|
||||
$('#video').get(0).src = data;
|
||||
})
|
||||
|
||||
record.stream = function(type){
|
||||
$('.record').on('click', function(){
|
||||
if(record.ing){
|
||||
if(record.ing.stop){ record.ing.stop() }
|
||||
$(this).text(record.type);
|
||||
record.ing = false;
|
||||
return;
|
||||
}
|
||||
record(record.type = $(this).text());
|
||||
$(this).text("End");
|
||||
})
|
||||
|
||||
function record(type){
|
||||
if('Camera' === type){
|
||||
navigator.getMedia({ video: true, audio: true }, stream, error);
|
||||
navigator.getMedia({ video: true, audio: true }, load, error);
|
||||
}
|
||||
if('Screen' === type){
|
||||
navigator.mediaDevices.getDisplayMedia({ video: true, audio: true }).then(stream, error);
|
||||
navigator.mediaDevices.getDisplayMedia({ video: true, audio: true }).then(load, error);
|
||||
}
|
||||
function stream(stream){
|
||||
var chunks = []; // we have a stream, we can record it
|
||||
record.ing = new MediaRecorder(stream);
|
||||
record.ing.ondataavailable = eve => chunks.push(eve.data);
|
||||
record.ing.onstop = eve => record.save(new Blob(chunks));
|
||||
record.ing.start()
|
||||
$('#play').text("End");
|
||||
function load(media){
|
||||
var chunks = [];
|
||||
record.ing = new MediaRecorder(media);
|
||||
record.ing.ondataavailable = function(eve){ chunks.push(eve.data) }
|
||||
record.ing.onstop = function(eve){record.save(new Blob(chunks)) }
|
||||
record.ing.start();
|
||||
}
|
||||
function error(err){ console.log(err) }
|
||||
}
|
||||
@ -46,38 +54,9 @@ record.save = function(data){
|
||||
b64 = $('#video').get(0).src = "data:video/webm" + b64.slice(b64.indexOf(';'));
|
||||
if($('#pass').val()){ b64 = await SEA.encrypt(b64, $('#pass').val()) }
|
||||
gun.get('test').get('video').put(b64);
|
||||
$('#play').trigger('click');
|
||||
}
|
||||
}
|
||||
|
||||
$('#play').on('click', function(){
|
||||
if(record.ing){
|
||||
if(record.ing.stop){ record.ing.stop() }
|
||||
record.ing = false;
|
||||
return;
|
||||
}
|
||||
if(record.playing){
|
||||
$('#video').get(0).pause();
|
||||
$('#play').text("Play");
|
||||
record.playing = false;
|
||||
return;
|
||||
}
|
||||
if($('#video').get(0).src){
|
||||
$('#video').get(0).play();
|
||||
$('#play').text("Pause");
|
||||
record.playing = true;
|
||||
return;
|
||||
}
|
||||
$('#play').text("Loading");
|
||||
gun.get('test').get('video').once(async function(data){
|
||||
if($('#pass').val()){ data = await SEA.decrypt(data, $('#pass').val()) }
|
||||
try{ $('#video').get(0).src = data }catch(e){}
|
||||
$('#play').trigger('click');
|
||||
})
|
||||
})
|
||||
$('#video').on('ended', function(){ $('#play').trigger('click') })
|
||||
$('#video').on('error', function(){ $('#play').text("Failed"); })
|
||||
|
||||
navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia
|
||||
|| navigator.mozGetUserMedia || navigator.msGetUserMedia);
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user