This commit is contained in:
PTZOptics authored and GitHub committed 2018-11-02 15:24:39 -04:00
commit b799070fd1
29 files changed
+6054

No files matched your search

+166
View File
@@ -0,0 +1,166 @@
/*jshint esversion: 6 */
function focusTouchEvents() {
const opts = ['tele', 'wide'];
opts.forEach((opt) => {
const eleId = 'focus' + opt.charAt(0).toUpperCase() + opt.slice(1);
const ele = document.getElementById(eleId);
ele.addEventListener('mousedown', variableFocus);
ele.addEventListener('mouseup', stopFocus);
ele.addEventListener('touchstart', variableFocus);
ele.addEventListener('touchend', stopFocus);
});
zoomTouchEvents();
}
function zoomTouchEvents() {
const opts = ['tele', 'wide'];
opts.forEach((opt) => {
const eleId = 'zoom' + opt.charAt(0).toUpperCase() + opt.slice(1);
const ele = document.getElementById(eleId);
ele.addEventListener('mousedown', variableZoom);
ele.addEventListener('mouseup', stopZoom);
ele.addEventListener('touchstart', variableZoom);
ele.addEventListener('touchend', stopZoom);
});
}
function getFocusSpeed() {
return document.getElementById('focusSpeedInput').value;
}
function getZoomSpeed() {
return document.getElementById('zoomSpeedInput').value;
}
function stopFocus(e) {
e.preventDefault();
stdFocus('stop');
}
function stopZoom(e) {
e.preventDefault();
stdZoom('stop');
}
function variableFocus(e) {
e.preventDefault();
const opt = e.currentTarget.getAttribute('data-value');
const focusSpeed = getFocusSpeed();
const payload = {
"mode": "variable",
"option": opt,
"intensity": focusSpeed
};
sendCmd("/ptz/focus", "POST", payload)
.then(function(res) {
alertMsg("variableFocus res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function directFocus(focusPos) {
const payload = {
"mode": "direct",
"focusPos": focusPos
};
sendCmd("/ptz/focus", "POST", payload)
.then(function(res) {
alertMsg("directFocus res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function stdFocus(opt) {
const payload = {
"mode": "standard",
"option": opt
};
sendCmd("/ptz/focus", "POST", payload)
.then(function(res) {
alertMsg("stdFocus res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function focusMode() {
const payload = {
"mode": "focusmode",
"option": document.getElementById('focusModeSel').selectedOptions[0].value
};
sendCmd("/ptz/focus", "POST", payload)
.then(function(res) {
alertMsg("focusmode res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function afZone() {
const payload = {
"mode": "afzone",
"option": document.getElementById('afZoneSel').selectedOptions[0].value
};
sendCmd("/ptz/focus", "POST", payload)
.then(function(res) {
alertMsg("afzone res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
// **************************************** ZOOM *************************************
function variableZoom(e) {
e.preventDefault();
const opt = e.currentTarget.getAttribute('data-value');
const zoomSpeed = getZoomSpeed();
const payload = {
"mode": "variable",
"option": opt,
"intensity": zoomSpeed
};
sendCmd("/ptz/zoom", "POST", payload)
.then(function(res) {
alertMsg("variableZoom res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function stdZoom(opt) {
const payload = {
"mode": "standard",
"option": opt
};
sendCmd("/ptz/zoom", "POST", payload)
.then(function(res) {
alertMsg("stdZoom res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function directZoom(zoomPos) {
const payload = {
"mode": "direct",
"zoomPos": zoomPos
};
sendCmd("/ptz/zoom", "POST", payload)
.then(function(res) {
alertMsg("directZoom res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
+237
View File
@@ -0,0 +1,237 @@
/*jshint esversion: 6 */
function whiteBalance(mode) {
let id;
if (mode === 'wbmode') {
id = "wbModeSel";
} else {
id = "awbSel";
}
const payload = {
"mode": mode,
"option": document.getElementById(id).selectedOptions[0].value
};
sendCmd("/image/wb", "POST", payload)
.then((res) => {
alertMsg("white bal res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function autoExp() {
const payload = {
"option": document.getElementById("aeSel").selectedOptions[0].value
};
sendCmd("/image/ae", "POST", payload)
.then((res) => {
alertMsg("auto exp res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function rgain(mode, opt, pos) {
const payload = {
"mode": mode
};
if (mode === "direct") {
payload.pos = pos;
} else if (mode === "standard"){
payload.option = opt;
}
sendCmd("/image/rgain", "POST", payload)
.then((res) => {
alertMsg("rgain res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function bgain(mode, opt, pos) {
const payload = {
"mode": mode
};
if (mode === "direct") {
payload.pos = pos;
} else if (mode === "standard"){
payload.option = opt;
}
sendCmd("/image/bgain", "POST", payload)
.then((res) => {
alertMsg("bgain res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function shutter(mode, option) {
const payload = {
"mode": mode,
"option": option
};
sendCmd("/image/shutter", "POST", payload)
.then((res) => {
alertMsg("shutter res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function iris(mode, option) {
const payload = {
"mode": mode
};
if (mode === "direct") {
payload.pos = pos;
} else if (mode === "standard"){
payload.option = option;
}
sendCmd("/image/iris", "POST", payload)
.then((res) => {
alertMsg("iris res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function gain(mode, opt) {
const payload = {
"mode": mode,
"option": opt
};
sendCmd("/image/gain", "POST", payload)
.then((res) => {
alertMsg("gain res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function backlight(opt) {
const payload = {
"option": opt
};
sendCmd("/image/backlight", "POST", payload)
.then((res) => {
alertMsg("backlight res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function blackWhite(opt) {
const payload = {
"option": opt
};
sendCmd("/image/bw", "POST", payload)
.then((res) => {
alertMsg("blackwhite res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function flicker(opt) {
const payload = {
"option": opt
};
sendCmd("/image/flicker", "POST", payload)
.then((res) => {
alertMsg("flicker res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function imgFlip(mode) {
let opt;
if (document.getElementById(mode).checked) {
opt = 'on';
} else {
opt = 'off';
}
const payload = {
"option": opt,
"mode": mode
};
sendCmd("/image/imgFlip", "POST", payload)
.then((res) => {
alertMsg("image flip res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function changeInputLabel(setting) {
const input = document.getElementById(setting + 'Input');
const label = document.getElementById(setting + "InputLabel");
if (setting === 'bright') {
label.innerHTML = "Brightness: " + input.value;
} else {
label.innerHTML = setting.charAt(0).toUpperCase() + setting.slice(1) + ": " + input.value;
}
}
function colorHue() {
changeInputLabel('colorHue');
const payload = {
"pos": document.getElementById('colorHueInput').value
};
sendCmd("/image/colorHue", "POST", payload)
.then((res) => {
alertMsg("color hue res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function brightness() {
changeInputLabel('bright');
const payload = {
"pos": document.getElementById('brightInput').value
};
sendCmd("/image/bright", "POST", payload)
.then((res) => {
alertMsg("bright res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function contrast() {
changeInputLabel('contrast');
const payload = {
"pos": document.getElementById('contrastInput').value
};
sendCmd("/image/contrast", "POST", payload)
.then((res) => {
alertMsg("contrast res: " + res);
})
.catch((err) => {
alertMsg(err, true);
});
}
function saveSetting() {
sendCmd("/image/save", "POST", {});
}
+3
View File
@@ -0,0 +1,3 @@
var JSMpeg={Player:null,VideoElement:null,BitBuffer:null,Source:{},Demuxer:{},Decoder:{},Renderer:{},AudioOutput:{},Now:function(){return window.performance?window.performance.now()/1e3:Date.now()/1e3},CreateVideoElements:function(){var elements=document.querySelectorAll(".jsmpeg");for(var i=0;i<elements.length;i++){new JSMpeg.VideoElement(elements[i])}},Fill:function(array,value){if(array.fill){array.fill(value)}else{for(var i=0;i<array.length;i++){array[i]=value}}}};if(document.readyState==="complete"){JSMpeg.CreateVideoElements()}else{document.addEventListener("DOMContentLoaded",JSMpeg.CreateVideoElements)}JSMpeg.VideoElement=function(){"use strict";var VideoElement=function(element){var url=element.dataset.url;if(!url){throw"VideoElement has no `data-url` attribute"}var addStyles=function(element,styles){for(var name in styles){element.style[name]=styles[name]}};this.container=element;addStyles(this.container,{display:"inline-block",position:"relative",minWidth:"80px",minHeight:"80px"});this.canvas=document.createElement("canvas");this.canvas.width=960;this.canvas.height=540;addStyles(this.canvas,{display:"block",width:"100%"});this.container.appendChild(this.canvas);this.playButton=document.createElement("div");this.playButton.innerHTML=VideoElement.PLAY_BUTTON;addStyles(this.playButton,{zIndex:2,position:"absolute",top:"0",bottom:"0",left:"0",right:"0",maxWidth:"75px",maxHeight:"75px",margin:"auto",opacity:"0.7",cursor:"pointer"});this.container.appendChild(this.playButton);var options={canvas:this.canvas};for(var option in element.dataset){try{options[option]=JSON.parse(element.dataset[option])}catch(err){options[option]=element.dataset[option]}}this.player=new JSMpeg.Player(url,options);element.playerInstance=this.player;if(options.poster&&!options.autoplay&&!this.player.options.streaming){options.decodeFirstFrame=false;this.poster=new Image;this.poster.src=options.poster;this.poster.addEventListener("load",this.posterLoaded);addStyles(this.poster,{display:"block",zIndex:1,position:"absolute",top:0,left:0,bottom:0,right:0});this.container.appendChild(this.poster)}if(!this.player.options.streaming){this.container.addEventListener("click",this.onClick.bind(this))}if(options.autoplay||this.player.options.streaming){this.playButton.style.display="none"}if(this.player.audioOut&&!this.player.audioOut.unlocked){var unlockAudioElement=this.container;if(options.autoplay||this.player.options.streaming){this.unmuteButton=document.createElement("div");this.unmuteButton.innerHTML=VideoElement.UNMUTE_BUTTON;addStyles(this.unmuteButton,{zIndex:2,position:"absolute",bottom:"10px",right:"20px",width:"75px",height:"75px",margin:"auto",opacity:"0.7",cursor:"pointer"});this.container.appendChild(this.unmuteButton);unlockAudioElement=this.unmuteButton}this.unlockAudioBound=this.onUnlockAudio.bind(this,unlockAudioElement);unlockAudioElement.addEventListener("touchstart",this.unlockAudioBound,false);unlockAudioElement.addEventListener("click",this.unlockAudioBound,true)}};VideoElement.prototype.onUnlockAudio=function(element,ev){if(this.unmuteButton){ev.preventDefault();ev.stopPropagation()}this.player.audioOut.unlock(function(){if(this.unmuteButton){this.unmuteButton.style.display="none"}element.removeEventListener("touchstart",this.unlockAudioBound);element.removeEventListener("click",this.unlockAudioBound)}.bind(this))};VideoElement.prototype.onClick=function(ev){if(this.player.isPlaying){this.player.pause();this.playButton.style.display="block"}else{this.player.play();this.playButton.style.display="none";if(this.poster){this.poster.style.display="none"}}};VideoElement.PLAY_BUTTON='<svg style="max-width: 75px; max-height: 75px;" '+'viewBox="0 0 200 200" alt="Play video">'+'<circle cx="100" cy="100" r="90" fill="none" '+'stroke-width="15" stroke="#fff"/>'+'<polygon points="70, 55 70, 145 145, 100" fill="#fff"/>'+"</svg>";VideoElement.UNMUTE_BUTTON='<svg style="max-width: 75px; max-height: 75px;" viewBox="0 0 75 75">'+'<polygon class="audio-speaker" stroke="none" fill="#fff" '+'points="39,13 22,28 6,28 6,47 21,47 39,62 39,13"/>'+'<g stroke="#fff" stroke-width="5">'+'<path d="M 49,50 69,26"/>'+'<path d="M 69,50 49,26"/>'+"</g>"+"</svg>";return VideoElement}();JSMpeg.Player=function(){"use strict";var Player=function(url,options){this.options=options||{};if(options.source){this.source=new options.source(url,options);options.streaming=!!this.source.streaming}else if(url.match(/^wss?:\/\//)){this.source=new JSMpeg.Source.WebSocket(url,options);options.streaming=true}else if(options.progressive!==false){this.source=new JSMpeg.Source.AjaxProgressive(url,options);options.streaming=false}else{this.source=new JSMpeg.Source.Ajax(url,options);options.streaming=false}this.maxAudioLag=options.maxAudioLag||.25;this.loop=options.loop!==false;this.autoplay=!!options.autoplay||options.streaming;this.demuxer=new JSMpeg.Demuxer.TS(options);this.source.connect(this.demuxer);if(options.video!==false){this.video=new JSMpeg.Decoder.MPEG1VideoLine truncated
src++;y|=sY[src]<<16;src++;y|=sY[src]<<24;src++;dY[dest++]=y}dest+=scan>>2;src+=scan}}}width=this.halfWidth;scan=width-8;H=motionH/2>>1;V=motionV/2>>1;oddH=(motionH/2&1)===1;oddV=(motionV/2&1)===1;src=((this.mbRow<<3)+V)*width+(this.mbCol<<3)+H;dest=this.mbRow*width+this.mbCol<<1;last=dest+(width<<1);var cr1,cr2,cr,cb1,cb2,cb;if(oddH){if(oddV){while(dest<last){cr1=sCr[src]+sCr[src+width];cb1=sCb[src]+sCb[src+width];src++;for(x=0;x<2;x++){cr2=sCr[src]+sCr[src+width];cb2=sCb[src]+sCb[src+width];src++;cr=cr1+cr2+2>>2&255;cb=cb1+cb2+2>>2&255;cr1=sCr[src]+sCr[src+width];cb1=sCb[src]+sCb[src+width];src++;cr|=cr1+cr2+2<<6&65280;cb|=cb1+cb2+2<<6&65280;cr2=sCr[src]+sCr[src+width];cb2=sCb[src]+sCb[src+width];src++;cr|=cr1+cr2+2<<14&16711680;cb|=cb1+cb2+2<<14&16711680;cr1=sCr[src]+sCr[src+width];cb1=sCb[src]+sCb[src+width];src++;cr|=cr1+cr2+2<<22&4278190080;cb|=cb1+cb2+2<<22&4278190080;dCr[dest]=cr;dCb[dest]=cb;dest++}dest+=scan>>2;src+=scan-1}}else{while(dest<last){cr1=sCr[src];cb1=sCb[src];src++;for(x=0;x<2;x++){cr2=sCr[src];cb2=sCb[src++];cr=cr1+cr2+1>>1&255;cb=cb1+cb2+1>>1&255;cr1=sCr[src];cb1=sCb[src++];cr|=cr1+cr2+1<<7&65280;cb|=cb1+cb2+1<<7&65280;cr2=sCr[src];cb2=sCb[src++];cr|=cr1+cr2+1<<15&16711680;cb|=cb1+cb2+1<<15&16711680;cr1=sCr[src];cb1=sCb[src++];cr|=cr1+cr2+1<<23&4278190080;cb|=cb1+cb2+1<<23&4278190080;dCr[dest]=cr;dCb[dest]=cb;dest++}dest+=scan>>2;src+=scan-1}}}else{if(oddV){while(dest<last){for(x=0;x<2;x++){cr=sCr[src]+sCr[src+width]+1>>1&255;cb=sCb[src]+sCb[src+width]+1>>1&255;src++;cr|=sCr[src]+sCr[src+width]+1<<7&65280;cb|=sCb[src]+sCb[src+width]+1<<7&65280;src++;cr|=sCr[src]+sCr[src+width]+1<<15&16711680;cb|=sCb[src]+sCb[src+width]+1<<15&16711680;src++;cr|=sCr[src]+sCr[src+width]+1<<23&4278190080;cb|=sCb[src]+sCb[src+width]+1<<23&4278190080;src++;dCr[dest]=cr;dCb[dest]=cb;dest++}dest+=scan>>2;src+=scan}}else{while(dest<last){for(x=0;x<2;x++){cr=sCr[src];cb=sCb[src];src++;cr|=sCr[src]<<8;cb|=sCb[src]<<8;src++;cr|=sCr[src]<<16;cb|=sCb[src]<<16;src++;cr|=sCr[src]<<24;cb|=sCb[src]<<24;src++;dCr[dest]=cr;dCb[dest]=cb;dest++}dest+=scan>>2;src+=scan}}}};MPEG1.prototype.dcPredictorY=0;MPEG1.prototype.dcPredictorCr=0;MPEG1.prototype.dcPredictorCb=0;MPEG1.prototype.blockData=null;MPEG1.prototype.decodeBlock=function(block){var n=0,quantMatrix;if(this.macroblockIntra){var predictor,dctSize;if(block<4){predictor=this.dcPredictorY;dctSize=this.readHuffman(MPEG1.DCT_DC_SIZE_LUMINANCE)}else{predictor=block===4?this.dcPredictorCr:this.dcPredictorCb;dctSize=this.readHuffman(MPEG1.DCT_DC_SIZE_CHROMINANCE)}if(dctSize>0){var differential=this.bits.read(dctSize);if((differential&1<<dctSize-1)!==0){this.blockData[0]=predictor+differential}else{this.blockData[0]=predictor+(-1<<dctSize|differential+1)}}else{this.blockData[0]=predictor}if(block<4){this.dcPredictorY=this.blockData[0]}else if(block===4){this.dcPredictorCr=this.blockData[0]}else{this.dcPredictorCb=this.blockData[0]}this.blockData[0]<<=3+5;quantMatrix=this.intraQuantMatrix;n=1}else{quantMatrix=this.nonIntraQuantMatrix}var level=0;while(true){var run=0,coeff=this.readHuffman(MPEG1.DCT_COEFF);if(coeff===1&&n>0&&this.bits.read(1)===0){break}if(coeff===65535){run=this.bits.read(6);level=this.bits.read(8);if(level===0){level=this.bits.read(8)}else if(level===128){level=this.bits.read(8)-256}else if(level>128){level=level-256}}else{run=coeff>>8;level=coeff&255;if(this.bits.read(1)){level=-level}}n+=run;var dezigZagged=MPEG1.ZIG_ZAG[n];n++;level<<=1;if(!this.macroblockIntra){level+=level<0?-1:1}level=level*this.quantizerScale*quantMatrix[dezigZagged]>>4;if((level&1)===0){level-=level>0?1:-1}if(level>2047){level=2047}else if(level<-2048){level=-2048}this.blockData[dezigZagged]=level*MPEG1.PREMULTIPLIER_MATRIX[dezigZagged]}var destArray,destIndex,scan;if(block<4){destArray=this.currentY;scan=this.codedWidth-8;destIndex=this.mbRow*this.codedWidth+this.mbCol<<4;if((block&1)!==0){destIndex+=8}if((block&2)!==0){destIndex+=this.codedWidth<<3}}else{destArray=block===4?this.currentCb:this.currentCr;scan=(this.codedWidth>>1)-8;destIndex=(this.mbRow*this.codedWidth<<2)+(this.mbCol<<3)}if(this.macroblockIntra){if(n===1){MPEG1.CopyValueToDestination(this.blockData[0]+128>>8,destArray,destIndex,scan);this.blockData[0]=0}else{MPEG1.IDCT(this.blockData);MPEG1.CopyBlockToDestination(this.blockData,destArray,destIndex,scan);JSMpeg.Fill(this.blockData,0)}}else{if(n===1){MPEG1.AddValueToDestination(this.blockData[0]+128>>8,destArray,destIndex,scan);this.blockData[0]=0}else{MPEG1.IDCT(this.blockData);MPEG1.AddBlockToDestination(this.blockData,destArray,destIndex,scan);JSMpeg.Fill(this.blockData,0)}}n=0};MPEG1.CopyBlockToDestination=function(block,dest,index,scan){for(var n=0;n<64;n+=8,index+=scan+8){dest[index+0]=block[n+0];dest[index+1]=block[n+1];dest[index+2]=block[n+2];dest[index+3]=block[n+3];dest[index+4]=block[n+4];dest[index+5]=block[n+5];dest[index+6]=block[n+6];dest[index+7]=block[n+7]}};MPEG1.AddBlockToDestination=function(block,dest,index,scan){for(var n=0;n<64;n+=8,index+Line truncated
gl.uniform1i(gl.getUniformLocation(this.program,name),index);return texture};WebGLRenderer.prototype.createProgram=function(vsh,fsh){var gl=this.gl;var program=gl.createProgram();gl.attachShader(program,this.compileShader(gl.VERTEX_SHADER,vsh));gl.attachShader(program,this.compileShader(gl.FRAGMENT_SHADER,fsh));gl.linkProgram(program);gl.useProgram(program);return program};WebGLRenderer.prototype.compileShader=function(type,source){var gl=this.gl;var shader=gl.createShader(type);gl.shaderSource(shader,source);gl.compileShader(shader);if(!gl.getShaderParameter(shader,gl.COMPILE_STATUS)){throw new Error(gl.getShaderInfoLog(shader))}return shader};WebGLRenderer.prototype.allowsClampedTextureData=function(){var gl=this.gl;var texture=gl.createTexture();gl.bindTexture(gl.TEXTURE_2D,texture);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,1,1,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,new Uint8ClampedArray([0]));return gl.getError()===0};WebGLRenderer.prototype.renderProgress=function(progress){var gl=this.gl;gl.useProgram(this.loadingProgram);var loc=gl.getUniformLocation(this.loadingProgram,"progress");gl.uniform1f(loc,progress);gl.drawArrays(gl.TRIANGLE_STRIP,0,4)};WebGLRenderer.prototype.render=function(y,cb,cr){if(!this.enabled){return}var gl=this.gl;var w=this.width+15>>4<<4,h=this.height,w2=w>>1,h2=h>>1;if(this.shouldCreateUnclampedViews){y=new Uint8Array(y.buffer),cb=new Uint8Array(cb.buffer),cr=new Uint8Array(cr.buffer)}gl.useProgram(this.program);this.updateTexture(gl.TEXTURE0,this.textureY,w,h,y);this.updateTexture(gl.TEXTURE1,this.textureCb,w2,h2,cb);this.updateTexture(gl.TEXTURE2,this.textureCr,w2,h2,cr);gl.drawArrays(gl.TRIANGLE_STRIP,0,4)};WebGLRenderer.prototype.updateTexture=function(unit,texture,w,h,data){var gl=this.gl;gl.activeTexture(unit);gl.bindTexture(gl.TEXTURE_2D,texture);gl.texImage2D(gl.TEXTURE_2D,0,gl.LUMINANCE,w,h,0,gl.LUMINANCE,gl.UNSIGNED_BYTE,data)};WebGLRenderer.IsSupported=function(){try{if(!window.WebGLRenderingContext){return false}var canvas=document.createElement("canvas");return!!(canvas.getContext("webgl")||canvas.getContext("experimental-webgl"))}catch(err){return false}};WebGLRenderer.SHADER={FRAGMENT_YCRCB_TO_RGBA:["precision mediump float;","uniform sampler2D textureY;","uniform sampler2D textureCb;","uniform sampler2D textureCr;","varying vec2 texCoord;","mat4 rec601 = mat4(","1.16438, 0.00000, 1.59603, -0.87079,","1.16438, -0.39176, -0.81297, 0.52959,","1.16438, 2.01723, 0.00000, -1.08139,","0, 0, 0, 1",");","void main() {","float y = texture2D(textureY, texCoord).r;","float cb = texture2D(textureCb, texCoord).r;","float cr = texture2D(textureCr, texCoord).r;","gl_FragColor = vec4(y, cr, cb, 1.0) * rec601;","}"].join("\n"),FRAGMENT_LOADING:["precision mediump float;","uniform float progress;","varying vec2 texCoord;","void main() {","float c = ceil(progress-(1.0-texCoord.y));","gl_FragColor = vec4(c,c,c,1);","}"].join("\n"),VERTEX_IDENTITY:["attribute vec2 vertex;","varying vec2 texCoord;","void main() {","texCoord = vertex;","gl_Position = vec4((vertex * 2.0 - 1.0) * vec2(1, -1), 0.0, 1.0);","}"].join("\n")};return WebGLRenderer}();JSMpeg.Renderer.Canvas2D=function(){"use strict";var CanvasRenderer=function(options){this.canvas=options.canvas||document.createElement("canvas");this.width=this.canvas.width;this.height=this.canvas.height;this.enabled=true;this.context=this.canvas.getContext("2d")};CanvasRenderer.prototype.destroy=function(){};CanvasRenderer.prototype.resize=function(width,height){this.width=width|0;this.height=height|0;this.canvas.width=this.width;this.canvas.height=this.height;this.imageData=this.context.getImageData(0,0,this.width,this.height);JSMpeg.Fill(this.imageData.data,255)};CanvasRenderer.prototype.renderProgress=function(progress){var w=this.canvas.width,h=this.canvas.height,ctx=this.context;ctx.fillStyle="#222";ctx.fillRect(0,0,w,h);ctx.fillStyle="#fff";ctx.fillRect(0,h-h*progress,w,h*progress)};CanvasRenderer.prototype.render=function(y,cb,cr){this.YCbCrToRGBA(y,cb,cr,this.imageData.data);this.context.putImageData(this.imageData,0,0)};CanvasRenderer.prototype.YCbCrToRGBA=function(y,cb,cr,rgba){if(!this.enabled){return}var w=this.width+15>>4<<4,w2=w>>1;var yIndex1=0,yIndex2=w,yNext2Lines=w+(w-this.width);var cIndex=0,cNextLine=w2-(this.width>>1);var rgbaIndex1=0,rgbaIndex2=this.width*4,rgbaNext2Lines=this.width*4;var cols=this.width>>1,rows=this.height>>1;var ccb,ccr,r,g,b;for(var row=0;row<rows;row++){for(var col=0;col<cols;col++){ccb=cb[cIndex];ccr=cr[cIndex];cIndex++;r=ccb+(ccb*103>>8)-179;g=(ccr*88>>8)-44+(ccb*183>>8)-91;b=ccr+(ccr*198>>8)-227;var y1=y[yIndex1++];var y2=y[yIndex1++];rgba[rgbaIndex1]=y1+r;rgba[rgbaIndex1+1]=y1-g;rgba[rgbaIndex1+2]=y1+b;rgba[rgbaIndex1+4]=y2+r;rgba[rgbaIndex1+5]=y2-g;rgba[rgbaIndex1+6]=y2+b;rgbaIndex1+=8;var y3=y[yIndex2++];var y4=y[yIndex2++];rgba[rgbaIndex2]=y3+r;rgba[rgbaIndex2+1]=y3-g;rgba[rgbaIndex2+2]=y3+b;rgba[rgbaIndex2+4]=y4+r;rgba[rgbaIndex2+5]=y4-g;rgba[rgbaIndex2+6]=y4+b;rgbaIndex2+=8}yIndex1+=yNext2LineLine truncated
+149
View File
@@ -0,0 +1,149 @@
/*jshint esversion: 6 */
function sendCmd(path, method, payload = {}) {
const server = 'http://' + document.location.hostname + ':4000';
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open(method, server + path);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onload = function() {
if (this.status >= 200 && this.status < 300) {
resolve(xhr.response);
} else {
reject(xhr.response);
}
};
xhr.onerror = function() {
reject(xhr.response);
};
if (method !== "GET") {
payload.id = getCurrentCamera().value;
xhr.send(JSON.stringify(payload));
} else {
xhr.send();
}
});
}
function alertMsg(msg, err) {
const msgStage = document.getElementById('msgStage');
msgStage.style.display = "block";
if (err) {
msgStage.classList.add("errMsg");
setTimeout(() => {
msgStage.classList.remove("errMsg");
msgStage.style.display = "none";
}, 4000);
} else {
msgStage.classList.add("successMsg");
setTimeout(() => {
msgStage.classList.remove("successMsg");
msgStage.style.display = "none";
}, 4000);
}
msgStage.innerHTML = msg;
}
function getAllSavedCameras() {
return new Promise((resolve, reject) => {
resolve(sendCmd('/camera/cameras', 'GET', null));
});
}
function getCurrentCamera() {
const cameraSelectTag = document.getElementById('cameraList');
return cameraSelectTag.options[cameraSelectTag.selectedIndex];
}
function optionView(view) {
document.getElementById("options").querySelectorAll("a.active")[0].classList.remove("active", "highlight");
document.querySelectorAll("a[value=" + view + "]")[0].classList.add("active", "highlight");
const allOptionViews = document.getElementsByClassName('optionView');
Array.prototype.forEach.call(allOptionViews, function(view) {
view.style.display = "none";
});
document.getElementById(view).style.display = "block";
}
Array.prototype.forEach.call(document.getElementsByClassName('panTiltInput'), function(input) {
input.addEventListener('change', changeRangeInputLabel, false);
});
function changeRangeInputLabel(e) {
const identity = e.currentTarget.getAttribute('data-html');
document.getElementById(identity + "SpeedLabel").innerHTML = identity.charAt(0).toUpperCase() + identity.slice(1) + " Speed: " + e.currentTarget.value;
}
function addCamera() {
const payload = {
name: document.getElementById('cameraNickname').value,
ip: document.getElementById('cameraIpAddy').value,
port: document.getElementById('cameraPort').value,
rtsp: document.getElementById('cameraRtsp').value
};
sendCmd('/camera/create', 'POST', payload)
.then(function(res) {
const camera = JSON.parse(res);
addCameraTag(camera);
alertMsg("Camera Successfully Added");
})
.catch(err => {
alertMsg(err);
});
}
function toggleSideBar() {
const sidebar = document.getElementById('sidebar');
const content = document.getElementById('content');
if(sidebar.classList.contains('active')) {
sidebar.classList.remove('active');
content.classList.remove('active');
} else {
sidebar.classList.add('active');
content.classList.add('active');
}
}
function addCameraTag(camera, index = 1) {
const optTag = document.createElement("option");
const eleId = camera.name || camera.ip;
optTag.dataset.streamPort = camera.streamPort;
if (index === 0) {
optTag.setAttribute("selected", "selected");
}
optTag.appendChild(document.createTextNode(eleId));
optTag.setAttribute("value", camera._id);
document.getElementById('cameraList').appendChild(optTag);
}
function deleteCamera() {
const camera = getCurrentCamera();
if(confirm("Would you like to delete " + camera.innerHTML + "?")) {
sendCmd('/camera/', "DELETE")
.then(() => {
const cameraSelectTag = document.getElementById('cameraList');
cameraSelectTag.remove(cameraSelectTag.selectedIndex);
changeStream();
})
.catch((err) => {
console.log(err);
});
}
}
function reqFullScreen() {
const doc = window.document;
const docEl = doc.documentElement;
const requestFullScreen = docEl.requestFullscreen || docEl.mozRequestFullScreen || docEl.webkitRequestFullScreen || docEl.msRequestFullscreen;
const cancelFullScreen = doc.exitFullscreen || doc.mozCancelFullScreen || doc.webkitExitFullscreen || doc.msExitFullscreen;
if(!doc.fullscreenElement && !doc.mozFullScreenElement && !doc.webkitFullscreenElement && !doc.msFullscreenElement) {
requestFullScreen.call(docEl);
} else {
cancelFullScreen.call(doc);
}
}
+116
View File
@@ -0,0 +1,116 @@
/*jshint esversion: 6 */
function motionTouchEvents() {
const directions = ['right', 'left', 'up', 'down'];
directions.forEach((direction) => {
const eleId = 'motion' + direction.charAt(0).toUpperCase() + direction.slice(1);
const ele = document.getElementById(eleId);
ele.addEventListener('mousedown', stdMove);
ele.addEventListener('mouseup', stopMotion);
ele.addEventListener('touchstart', stdMove);
ele.addEventListener('touchend', stopMotion);
});
}
function moveHome() {
const payload = {mode: "home"};
sendCmd("/ptz/motion", "POST", payload)
.then(function(res) {
alertMsg("home res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function stopMotion(e) {
e.preventDefault();
const panTiltArr = getPanTiltSpeeds();
const payload = {
"mode": "standard",
"direction": "stop",
"panSpeed": panTiltArr[0],
"tiltSpeed": panTiltArr[1]
};
sendCmd("/ptz/motion", "POST", payload)
.then(function(res) {
alertMsg("continousMove_" + direction + " res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function stdMove(e) {
e.preventDefault();
const direction = e.target.getAttribute('data-value');
const panTiltArr = getPanTiltSpeeds();
const payload = {
"mode": "standard",
"direction": direction,
"panSpeed": panTiltArr[0],
"tiltSpeed": panTiltArr[1]
};
sendCmd("/ptz/motion", "POST", payload)
.then(function(res) {
alertMsg("continousMove_" + direction + " res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function getPanTiltSpeeds() {
return [document.getElementById('panSpeedInput').value, document.getElementById('tiltSpeedInput').value];
}
function moveAbsPos(pan, tilt) {
const panTiltArr = getPanTiltSpeeds();
const payload = {
"mode": "absolute",
"panSpeed": panTiltArr[0],
"tiltSpeed": panTiltArr[1],
"pan": pan,
"tilt": tilt
};
sendCmd("/ptz/motion", "POST", payload)
.then(function(res) {
alertMsg("moveAbsPos res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function moveRelPos(pan, tilt) {
const panTiltArr = getPanTiltSpeeds();
const payload = {
"mode": "relative",
"panSpeed": panTiltArr[0],
"tiltSpeed": panTiltArr[1],
"pan": pan,
"tilt": tilt
};
sendCmd("/ptz/motion", "POST", payload)
.then(function(res) {
alertMsg("moveRelPos res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
function presets(mode, memNum) {
const payload = {
"mode": mode,
"num": memNum
};
sendCmd("ptz/presets", "POST", payload)
.then(function(res) {
alertMsg("Preset res: " + res);
})
.catch(function(err) {
alertMsg(err, true);
});
}
+39
View File
@@ -0,0 +1,39 @@
/*jshint esversion: 6 */
function presetAction(action, eleId = 'presetInput') {
let payload = {
mode: action
};
if (action === 'speed') {
payload.speed = document.getElementById(eleId).value;
changePresetSpeedLabel(payload.speed);
} else {
animateActionBtn(action);
payload.memNum = document.getElementById(eleId).value;
}
sendCmd('/ptz/presets', 'POST', payload)
.then((res) => {
console.log(res);
if (action !== 'speed' && res === "Socket1 Cmd Done" || action !== 'speed' && res === "Socket2 Cmd Done") {
stopPresetBtnAnimate(action);
}
alertMsg("Preset Action res: " + res + " Payload: " + payload);
}).catch((err) => {
alertMsg(err, true);
});
}
function animateActionBtn(action) {
const btn = document.getElementById(action + 'PresetBtn');
btn.innerHTML = '<i class="fa fa-spinner fa-pulse"></i>';
}
function stopPresetBtnAnimate(action) {
const btn = document.getElementById(action + 'PresetBtn');
btn.innerHTML = action.charAt(0).toUpperCase() + action.slice(1);
}
function changePresetSpeedLabel(speed) {
document.getElementById("presetSpeedLabel").innerHTML = "Preset Recall Speed: " + speed;
}
+20
View File
@@ -0,0 +1,20 @@
/*jshint esversion: 6 */
let player;
function changeStream() {
player.destroy();
startStream();
}
function startStream() {
const canvas = document.getElementById('streamStage');
const payload = {
width: window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth,
height: window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
};
sendCmd('/camera/stream', 'POST', payload).then((camera) => {
const streamPort = JSON.parse(camera);
player = new JSMpeg.Player('ws://' + document.location.hostname + ':' + streamPort, {canvas:canvas});
});
}