update dashcam (streamer v2) code
parent
977089dced
commit
a47cefe033
|
|
@ -23,11 +23,16 @@ requires https or firefox
|
|||
<script src="libs/js/socket.io.js"></script>
|
||||
<script src="libs/js/menu.js"></script>
|
||||
<script>
|
||||
$.ccio={};$.ls=localStorage;
|
||||
$.ccio.ws=io(location.origin);
|
||||
$.ccio = {}
|
||||
$.ls = localStorage
|
||||
$.ccio.ws = io(location.origin)
|
||||
$.ccio.ws.on('connect',function (d){
|
||||
$(document).ready(function(e){
|
||||
$.ccio.cx=function(x){if(!x.ke){x.ke=$user.ke;};if(!x.uid){x.uid=$user.uid;};return $.ccio.ws.emit('r',x)}
|
||||
$.ccio.cx=function(x){
|
||||
if(!x.ke){x.ke=$user.ke;}
|
||||
if(!x.uid){x.uid=$user.uid;}
|
||||
return $.ccio.ws.emit('r',x)
|
||||
}
|
||||
console.log($user)
|
||||
$.ccio.cx({f:'init',ke:$user.ke,auth:$user.auth_token,uid:$user.uid})
|
||||
})
|
||||
|
|
@ -52,69 +57,73 @@ function _base64ToArrayBuffer(base64) {
|
|||
}
|
||||
return bytes.buffer;
|
||||
}
|
||||
|
||||
$.ccio.framerate=2;
|
||||
|
||||
$.ccio.stopSending=function(){
|
||||
$.ls.setItem('Shinobi_Dashcam_Started','0')
|
||||
$('#main').removeClass('recording');
|
||||
clearInterval($.ccio.cutChunk);
|
||||
if(mediaRecorder.stop){
|
||||
mediaRecorder.stop()
|
||||
}
|
||||
$('[record]').unbind('click').click($.ccio.startSending)
|
||||
}
|
||||
$.ccio.firstFrame = null
|
||||
$.ccio.startSending=function(){
|
||||
$.ls.setItem('Shinobi_Dashcam_Started',1)
|
||||
if($.ccio.selected===null){return false;}
|
||||
$('#main').addClass('recording');
|
||||
if (typeof MediaRecorder.isTypeSupported == 'function'){
|
||||
/*
|
||||
MediaRecorder.isTypeSupported is a function announced in https://developers.google.com/web/updates/2016/01/mediarecorder and later introduced in the MediaRecorder API spec http://www.w3.org/TR/mediastream-recording/
|
||||
*/
|
||||
var options = {
|
||||
audioBitsPerSecond : 128000,
|
||||
videoBitsPerSecond : 2500000,
|
||||
}
|
||||
if (MediaRecorder.isTypeSupported('video/webm;codecs=vp9')) {
|
||||
var options = {mimeType: 'video/webm;codecs=vp9'};
|
||||
options.mimeType = 'video/webm;codecs=vp9'
|
||||
} else if (MediaRecorder.isTypeSupported('video/webm;codecs=h264')) {
|
||||
var options = {mimeType: 'video/webm;codecs=h264'};
|
||||
options.mimeType = 'video/webm;codecs=h264'
|
||||
} else if (MediaRecorder.isTypeSupported('video/webm;codecs=vp8')) {
|
||||
var options = {mimeType: 'video/webm;codecs=vp8'};
|
||||
options.mimeType = 'video/webm;codecs=vp8'
|
||||
}
|
||||
log('Using '+options.mimeType);
|
||||
console.log('Using '+options.mimeType);
|
||||
mediaRecorder = new MediaRecorder($.ccio.vid.stream, options);
|
||||
}else{
|
||||
log('Using default codecs for browser');
|
||||
console.log('Using default codecs for browser');
|
||||
mediaRecorder = new MediaRecorder($.ccio.vid.stream);
|
||||
}
|
||||
|
||||
mediaRecorder.start(10);
|
||||
mediaRecorder.start(10)
|
||||
|
||||
$.ccio.chunker = function(){
|
||||
clearInterval($.ccio.cutChunk)
|
||||
$.ccio.cutChunk=setInterval(function(){
|
||||
mediaRecorder.stop()
|
||||
mediaRecorder.start()
|
||||
},5000)
|
||||
var blob = new Blob(chunks, {type: "video/webm"});
|
||||
$.ccio.cx({f:'monitor_chunk',chunk:blob,mid:$.ccio.selected});
|
||||
chunks = [];
|
||||
},1000/$.ccio.framerate)
|
||||
}
|
||||
mediaRecorder.ondataavailable = function(e) {
|
||||
//log('Data available...');
|
||||
//console.log(e.data);
|
||||
//console.log(e.data.type);
|
||||
//console.log(e);
|
||||
chunks.push(e.data);
|
||||
};
|
||||
var noFirstFrame = function(e){
|
||||
$.ccio.firstFrame = e.data
|
||||
chunks.push(e.data);
|
||||
mediaRecorder.ondataavailable = function(e) {
|
||||
chunks.push(e.data);
|
||||
}
|
||||
}
|
||||
mediaRecorder.ondataavailable = noFirstFrame
|
||||
|
||||
mediaRecorder.onerror = function(e){
|
||||
clearInterval($.ccio.cutChunk)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
mediaRecorder.onstart = function(){
|
||||
if($.ccio.firstFrame){
|
||||
var blob = new Blob([$.ccio.firstFrame], {type: "video/webm"});
|
||||
$.ccio.cx({f:'monitor_chunk',chunk:blob,mid:$.ccio.selected});
|
||||
}
|
||||
$.ccio.chunker()
|
||||
};
|
||||
|
||||
mediaRecorder.onstop = function(){
|
||||
var blob = new Blob(chunks, {type: "video/webm"});
|
||||
$.ccio.cx({f:'monitor_chunk',chunk:blob,mid:$.ccio.selected});
|
||||
// var reader = new FileReader();
|
||||
// reader.addEventListener("loadend", function() {
|
||||
// console.log(reader.result)
|
||||
// });
|
||||
// reader.readAsArrayBuffer(blob);
|
||||
chunks = [];
|
||||
};
|
||||
}
|
||||
|
||||
mediaRecorder.onpause = function(){
|
||||
clearInterval($.ccio.cutChunk)
|
||||
|
|
@ -126,7 +135,7 @@ $.ccio.startSending=function(){
|
|||
|
||||
mediaRecorder.onwarning = function(e){
|
||||
clearInterval($.ccio.cutChunk)
|
||||
};
|
||||
}
|
||||
$('[record]').unbind('click').click($.ccio.stopSending)
|
||||
};
|
||||
function log(message){
|
||||
|
|
@ -151,6 +160,15 @@ $.ccio.vid.element.controls = false;
|
|||
navigator.getUserMedia(constraints,function(stream,fn) {
|
||||
$.ccio.vid.stream=stream;
|
||||
$('[record]').click($.ccio.startSending)
|
||||
////////
|
||||
if($user.mons.length>0&&$.ls.getItem('Shinobi_Dashcam')){
|
||||
$('[monitor="'+$.ls.getItem('Shinobi_Dashcam')+'"]').click()
|
||||
if($.ls.getItem('Shinobi_Dashcam_Started') === 1){
|
||||
$('[record]').click()
|
||||
}
|
||||
}else{
|
||||
$.ccio.selected = null;
|
||||
}
|
||||
}, function(err){console.error('getUserMedia',err)});
|
||||
|
||||
|
||||
|
|
@ -187,8 +205,6 @@ navigator.getUserMedia(constraints,function(stream,fn) {
|
|||
})
|
||||
|
||||
|
||||
if($user.mons.length>0&&$.ls.getItem('Shinobi_Dashcam')){$('[monitor="'+$.ls.getItem('Shinobi_Dashcam')+'"]').click()}else{$.ccio.selected=null;}
|
||||
|
||||
$('body')
|
||||
.on('click','.logout',function(e){
|
||||
localStorage.removeItem('ShinobiLogin_'+location.host);location.href='/';
|
||||
|
|
|
|||
Loading…
Reference in New Issue