Spaces:
Sleeping
Sleeping
File size: 4,716 Bytes
490b2ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
<body>
<h1 id="demo"></h1>
<div>
<img id="img16" class="refr" style="width:100;display:none;" src="getresource?r=atualli.png" >
<canvas title = "teste"
id="cvc16" class="refrc" alt="" style="width:100%" onclick="imgRedirect('zoom?n=1&m=1&p00')"></canvas>
</div>
<script async">
var resx = 1000;
var resy = 1000;
var to = 1; // 2; //3;
var first = 0;
var idx = 0;
var tamFila = 0;
var myFila = 0;
var onlyView = 0;
var lastDate = new Date();
var dataXhttp = [];
var slot = 0;
gogo();
function _arrayBufferToBase64( bytes ) {
var binary = '';
var len = bytes.byteLength;
// for (var i = 0; i < len; i++) {
// binary += String.fromCharCode( bytes[ i ] );
// }
var block= 65535;
var start = 0;
do {
var end = start+block;
if (end>=len) end=len;
var sub = bytes.slice(start, end)
binary += String.fromCharCode.apply(null,sub);
start+=block;
if(start>=len) break;
}while(1);
return window.btoa( binary );
}
function binaryToDataURL(inputArray){
let TYPED_ARRAY = new Uint8Array(inputArray);
let base64String = _arrayBufferToBase64(TYPED_ARRAY);
var uri = 'data:image/jpeg;base64,' + base64String;
return uri;
}
var canvasx=480;
var canvasy=240;
var canvasvx=720;
var canvasvy=480;
var fps=120;
var ext= ".jpeg";
var urlBase = '<?URL?>'
async function playframe(img,blob)
{
const ArrayBuffer = await blob.arrayBuffer();
const src = binaryToDataURL(ArrayBuffer);
img.src = src;
img.onload = function () {
var ids = this.id;
var cam = "cvc" + ids.substring(3, 5);
var c = document.getElementById(cam);
var ctx = c.getContext("2d");
var resx = canvasvx; //this.width
var resy = canvasvy; //this.height;
c.setAttribute('width', resx);
c.setAttribute('height', resy);
ctx.drawImage(this, 0, 0, resx, resy);
};
/*
// const ArrayBuffer = await blob.arrayBuffer();
// let TYPED_ARRAY = new Uint8Array(ArrayBuffer);
var fileReader = new FileReader();
fileReader.onload = function(event) {
ArrayBuffer = event.target.result;
let TYPED_ARRAY = new Uint8Array(ArrayBuffer);
// let TYPED_ARRAY = new Uint16Array(ArrayBuffer);
var ids = img.id;
var cam = "cvc" + ids.substring(3, 5);
var c = document.getElementById(cam);
var ctx = c.getContext("2d");
var resx = canvasx;
var resy = canvasy;
c.setAttribute('width', resx);
c.setAttribute('height', resy);
const imageData = ctx.createImageData(resx, resy);
// Iterate through every pixel
let j=0;
for (let i = 0; i < imageData.data.length; i += 4) {
// Modify pixel data
imageData.data[i + 0] = TYPED_ARRAY[j + 2]; // R value
imageData.data[i + 1] = TYPED_ARRAY[j + 1]; // G value
imageData.data[i + 2] = TYPED_ARRAY[j + 0]; // B value
imageData.data[i + 3] = 255; // A value
j+=3;
}
ctx.putImageData(imageData, 0, 0);
}
fileReader.readAsArrayBuffer(blob);
*/
}
async function playstream(img)
{
img.setAttribute("data-completed", 0);
var cam = img.id.substring(3, 5);
var newurl = "http://atualli.ddns.net:8188/getcamera?" + "c=" + cam + "&resx=" + canvasx + "&resy=" + canvasy + "&fps=" + fps + "&ext=" + ext;;
let wnewurl = newurl.replace("http","ws");
// wnewurl = wnewurl.replace("getcamera","stream");
wnewurl = wnewurl.replace("getcamera","getstream");
// wnewurl = wnewurl.replace("getcamera","getfullmosaico");
var ws = new WebSocket(wnewurl);
ws.onopen = function () {
console.log("Message to send");
img.setAttribute("data-completed", 0);
};
ws.onmessage = function (evt) {
/* var impl = function (img, blob)
{
playframe(img,blob);
}
impl(img,evt.data); */
playframe(img,evt.data);
};
ws.onclose = function () {
// websocket is closed.
console.log("Connection is closed...");
img.setAttribute("data-completed", -1);
};
}
function gogo() {
var pix = document.getElementsByClassName('refr');
for (var i = 0; i < pix.length; i++) {
var img = pix[i];
if (!img.hasAttribute("data-completed") || img.getAttribute("data-completed")<0)
{
playstream(img);
}
}
setTimeout(gogo, 5000);
}
</script>
</body>
|