2022-01-13 12:46:26 +08:00
|
|
|
var server;
|
|
|
|
var janus = null;
|
|
|
|
var streaming2;
|
2021-01-08 21:32:52 +08:00
|
|
|
var intervalId;
|
2021-01-03 06:57:23 +08:00
|
|
|
var pauseBtn = $j('#pauseBtn');
|
|
|
|
var playBtn = $j('#playBtn');
|
2019-03-05 02:35:40 +08:00
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function nextCycleView() {
|
2018-07-10 00:33:21 +08:00
|
|
|
window.location.replace('?view=cycle&mid='+nextMid+'&mode='+mode, cycleRefreshTimeout);
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-05 02:35:40 +08:00
|
|
|
function cyclePause() {
|
2021-01-08 21:32:52 +08:00
|
|
|
clearInterval(intervalId);
|
2021-01-03 06:57:23 +08:00
|
|
|
pauseBtn.prop('disabled', true);
|
|
|
|
playBtn.prop('disabled', false);
|
2019-03-05 02:35:40 +08:00
|
|
|
}
|
2020-07-04 07:18:05 +08:00
|
|
|
|
2019-03-05 02:35:40 +08:00
|
|
|
function cycleStart() {
|
2021-01-08 21:32:52 +08:00
|
|
|
intervalId = setInterval(nextCycleView, cycleRefreshTimeout);
|
2021-01-03 06:57:23 +08:00
|
|
|
pauseBtn.prop('disabled', false);
|
|
|
|
playBtn.prop('disabled', true);
|
2019-03-05 02:35:40 +08:00
|
|
|
}
|
2020-07-04 07:18:05 +08:00
|
|
|
|
2019-03-05 02:35:40 +08:00
|
|
|
function cycleNext() {
|
|
|
|
monIdx ++;
|
2019-03-06 00:01:58 +08:00
|
|
|
if ( monIdx >= monitorData.length ) {
|
2019-03-05 02:35:40 +08:00
|
|
|
monIdx = 0;
|
2019-03-06 00:01:58 +08:00
|
|
|
}
|
|
|
|
if ( !monitorData[monIdx] ) {
|
2020-07-04 07:18:05 +08:00
|
|
|
console.log('No monitorData for ' + monIdx);
|
2019-03-06 00:01:58 +08:00
|
|
|
}
|
2019-03-05 02:35:40 +08:00
|
|
|
|
|
|
|
window.location.replace('?view=cycle&mid='+monitorData[monIdx].id+'&mode='+mode, cycleRefreshTimeout);
|
|
|
|
}
|
2020-07-04 07:18:05 +08:00
|
|
|
|
2019-03-05 02:35:40 +08:00
|
|
|
function cyclePrev() {
|
2021-01-09 03:16:16 +08:00
|
|
|
monIdx --;
|
|
|
|
if ( monIdx < 0 ) {
|
2019-03-11 11:56:08 +08:00
|
|
|
monIdx = monitorData.length - 1;
|
|
|
|
}
|
2021-01-09 03:16:16 +08:00
|
|
|
if ( !monitorData[monIdx] ) {
|
|
|
|
console.log('No monitorData for ' + monIdx);
|
|
|
|
}
|
2019-03-05 02:35:40 +08:00
|
|
|
|
|
|
|
window.location.replace('?view=cycle&mid='+monitorData[monIdx].id+'&mode='+mode, cycleRefreshTimeout);
|
|
|
|
}
|
|
|
|
|
2017-05-19 01:50:56 +08:00
|
|
|
function initCycle() {
|
2021-01-08 21:32:52 +08:00
|
|
|
intervalId = setInterval(nextCycleView, cycleRefreshTimeout);
|
2020-10-20 02:28:02 +08:00
|
|
|
var scale = $j('#scale').val();
|
|
|
|
if ( scale == '0' || scale == 'auto' ) changeScale();
|
2022-01-13 12:46:26 +08:00
|
|
|
|
|
|
|
if (monitorData[monIdx].janusEnabled) {
|
|
|
|
server = "http://" + window.location.hostname + ":8088/janus";
|
|
|
|
opaqueId = "streamingtest-"+Janus.randomString(12);
|
|
|
|
Janus.init({debug: "all", callback: function() {
|
|
|
|
janus = new Janus({
|
|
|
|
server: server,
|
|
|
|
success: function() {
|
|
|
|
janus.attach({
|
|
|
|
plugin: "janus.plugin.streaming",
|
|
|
|
opaqueId: opaqueId,
|
|
|
|
success: function(pluginHandle) {
|
|
|
|
streaming2 = pluginHandle;
|
2022-01-15 05:43:59 +08:00
|
|
|
var body = {"request": "watch", "id": monitorData[monIdx].id};
|
2022-01-13 12:46:26 +08:00
|
|
|
streaming2.send({"message": body});
|
|
|
|
},
|
|
|
|
error: function(error) {
|
|
|
|
Janus.error(" -- Error attaching plugin... ", error);
|
|
|
|
},
|
|
|
|
onmessage: function(msg, jsep) {
|
|
|
|
Janus.debug(" ::: Got a message :::");
|
|
|
|
Janus.debug(msg);
|
|
|
|
var result = msg["result"];
|
2022-01-15 05:43:59 +08:00
|
|
|
if (result !== null && result !== undefined) {
|
|
|
|
if (result["status"] !== undefined && result["status"] !== null) {
|
|
|
|
const status = result["status"];
|
|
|
|
console.log(status);
|
2022-01-13 12:46:26 +08:00
|
|
|
}
|
2022-01-15 05:43:59 +08:00
|
|
|
} else if (msg["error"] !== undefined && msg["error"] !== null) {
|
2022-01-13 12:46:26 +08:00
|
|
|
Janus.debug(msg["error"]);
|
|
|
|
return;
|
|
|
|
}
|
2022-01-15 05:43:59 +08:00
|
|
|
if (jsep !== undefined && jsep !== null) {
|
2022-01-13 12:46:26 +08:00
|
|
|
Janus.debug("Handling SDP as well...");
|
|
|
|
Janus.debug(jsep);
|
|
|
|
// Offer from the plugin, let's answer
|
|
|
|
streaming2.createAnswer({
|
|
|
|
jsep: jsep,
|
|
|
|
// We want recvonly audio/video and, if negotiated, datachannels
|
2022-01-15 05:43:59 +08:00
|
|
|
media: {audioSend: false, videoSend: false, data: true},
|
2022-01-13 12:46:26 +08:00
|
|
|
success: function(jsep) {
|
|
|
|
Janus.debug("Got SDP!");
|
|
|
|
Janus.debug(jsep);
|
2022-01-15 05:43:59 +08:00
|
|
|
var body = {"request": "start"};
|
2022-01-13 12:46:26 +08:00
|
|
|
streaming2.send({"message": body, "jsep": jsep});
|
|
|
|
},
|
|
|
|
error: function(error) {
|
|
|
|
Janus.error("WebRTC error:", error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, //onmessage function
|
|
|
|
onremotestream: function(stream) {
|
|
|
|
Janus.debug(" ::: Got a remote track :::");
|
|
|
|
Janus.debug(stream);
|
|
|
|
Janus.attachMediaStream(document.getElementById("liveStream" + monitorData[monIdx].id), stream);
|
|
|
|
document.getElementById("liveStream" + monitorData[monIdx].id).play();
|
|
|
|
}
|
|
|
|
});// attach
|
|
|
|
} //Success functio
|
|
|
|
}); //new Janus
|
|
|
|
}}); //janus.init callback
|
|
|
|
} //if janus
|
2008-07-14 21:54:50 +08:00
|
|
|
}
|
|
|
|
|
2019-03-05 02:35:40 +08:00
|
|
|
function changeSize() {
|
2021-01-03 06:57:23 +08:00
|
|
|
var width = $j('#width').val();
|
|
|
|
var height = $j('#height').val();
|
2019-03-05 02:35:40 +08:00
|
|
|
|
|
|
|
// Scale the frame
|
|
|
|
monitor_frame = $j('#imageFeed');
|
|
|
|
if ( !monitor_frame ) {
|
2020-02-26 00:18:02 +08:00
|
|
|
console.log('Error finding frame');
|
2019-03-05 02:35:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( width ) {
|
|
|
|
monitor_frame.css('width', width);
|
|
|
|
}
|
|
|
|
if ( height ) {
|
|
|
|
monitor_frame.css('height', height);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Stream could be an applet so can't use moo tools */
|
2021-01-03 06:57:23 +08:00
|
|
|
var streamImg = document.getElementById('liveStream'+monitorData[monIdx].id);
|
2019-03-05 02:35:40 +08:00
|
|
|
if ( streamImg ) {
|
|
|
|
if ( streamImg.nodeName == 'IMG' ) {
|
|
|
|
var src = streamImg.src;
|
|
|
|
streamImg.src = '';
|
|
|
|
console.log(parseInt(width));
|
|
|
|
src = src.replace(/width=[\.\d]+/i, 'width='+parseInt(width));
|
|
|
|
src = src.replace(/height=[\.\d]+/i, 'height='+parseInt(height));
|
|
|
|
src = src.replace(/rand=\d+/i, 'rand='+Math.floor((Math.random() * 1000000) ));
|
|
|
|
streamImg.src = src;
|
|
|
|
}
|
|
|
|
streamImg.style.width = width ? width : null;
|
|
|
|
streamImg.style.height = height ? height : null;
|
|
|
|
} else {
|
2020-07-04 07:18:05 +08:00
|
|
|
console.log('Did not find liveStream'+monitorData[monIdx].id);
|
2019-03-05 02:35:40 +08:00
|
|
|
}
|
2021-01-03 06:57:23 +08:00
|
|
|
$j('#scale').val('');
|
2021-01-09 00:04:46 +08:00
|
|
|
setCookie('zmCycleScale', '', 3600);
|
|
|
|
setCookie('zmCycleWidth', width, 3600);
|
|
|
|
setCookie('zmCycleHeight', height, 3600);
|
2019-03-05 02:35:40 +08:00
|
|
|
} // end function changeSize()
|
|
|
|
|
|
|
|
function changeScale() {
|
2021-01-03 06:57:23 +08:00
|
|
|
var scale = $j('#scale').val();
|
|
|
|
$j('#width').val('auto');
|
|
|
|
$j('#height').val('auto');
|
2021-01-09 00:04:46 +08:00
|
|
|
setCookie('zmCycleScale', scale, 3600);
|
|
|
|
setCookie('zmCycleWidth', 'auto', 3600);
|
|
|
|
setCookie('zmCycleHeight', 'auto', 3600);
|
2019-03-05 02:35:40 +08:00
|
|
|
var newWidth = ( monitorData[monIdx].width * scale ) / SCALE_BASE;
|
|
|
|
var newHeight = ( monitorData[monIdx].height * scale ) / SCALE_BASE;
|
|
|
|
|
|
|
|
// Scale the frame
|
|
|
|
monitor_frame = $j('#imageFeed');
|
|
|
|
if ( !monitor_frame ) {
|
2020-02-26 00:18:02 +08:00
|
|
|
console.log('Error finding frame');
|
2019-03-05 02:35:40 +08:00
|
|
|
return;
|
|
|
|
}
|
2020-02-26 00:18:02 +08:00
|
|
|
|
2020-07-04 07:18:05 +08:00
|
|
|
if ( scale != '0' && scale != '' && scale != 'auto' ) {
|
2020-10-20 02:28:02 +08:00
|
|
|
var newWidth = ( monitorData[monIdx].width * scale ) / SCALE_BASE;
|
|
|
|
var newHeight = ( monitorData[monIdx].height * scale ) / SCALE_BASE;
|
2020-02-26 00:18:02 +08:00
|
|
|
if ( newWidth ) {
|
|
|
|
monitor_frame.css('width', newWidth+'px');
|
|
|
|
}
|
|
|
|
if ( newHeight ) {
|
|
|
|
monitor_frame.css('height', newHeight+'px');
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-20 02:28:02 +08:00
|
|
|
//var bottomEl = streamMode == 'stills' ? $j('#eventImageNav') : $j('#replayStatus');
|
|
|
|
var newSize = scaleToFit(monitorData[monIdx].width, monitorData[monIdx].height, monitor_frame, $j('#buttons'));
|
|
|
|
newWidth = newSize.width;
|
|
|
|
newHeight = newSize.height;
|
|
|
|
autoScale = newSize.autoScale;
|
|
|
|
monitor_frame.width(newWidth);
|
|
|
|
monitor_frame.height(newHeight);
|
2019-03-05 02:35:40 +08:00
|
|
|
}
|
2020-07-04 07:18:05 +08:00
|
|
|
|
2019-03-05 02:35:40 +08:00
|
|
|
/*Stream could be an applet so can't use moo tools*/
|
|
|
|
var streamImg = $j('#liveStream'+monitorData[monIdx].id)[0];
|
2020-07-04 07:18:05 +08:00
|
|
|
if ( !streamImg ) {
|
|
|
|
console.log("Did not find liveStream"+monitorData[monIdx].id);
|
|
|
|
return;
|
|
|
|
}
|
2019-03-05 02:35:40 +08:00
|
|
|
|
2020-07-04 07:18:05 +08:00
|
|
|
if ( streamImg.nodeName == 'IMG' ) {
|
|
|
|
var src = streamImg.src;
|
|
|
|
streamImg.src = '';
|
|
|
|
|
|
|
|
//src = src.replace(/rand=\d+/i,'rand='+Math.floor((Math.random() * 1000000) ));
|
|
|
|
src = src.replace(/scale=[\.\d]+/i, 'scale='+scale);
|
2020-10-20 02:28:02 +08:00
|
|
|
// zms doesn't actually use width&height
|
2020-07-04 07:18:05 +08:00
|
|
|
if ( scale != '0' && scale != '' && scale != 'auto' ) {
|
|
|
|
src = src.replace(/width=[\.\d]+/i, 'width='+newWidth);
|
|
|
|
src = src.replace(/height=[\.\d]+/i, 'height='+newHeight);
|
2020-02-26 00:18:02 +08:00
|
|
|
} else {
|
2020-07-04 07:18:05 +08:00
|
|
|
src = src.replace(/width=[\.\d]+/i, 'width='+monitorData[monIdx].width);
|
|
|
|
src = src.replace(/height=[\.\d]+/i, 'height='+monitorData[monIdx].height);
|
2020-02-26 00:18:02 +08:00
|
|
|
}
|
2020-07-04 07:18:05 +08:00
|
|
|
streamImg.src = src;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( scale != '0' && scale != '' && scale != 'auto' ) {
|
|
|
|
streamImg.style.width = newWidth+'px';
|
|
|
|
streamImg.style.height = newHeight+'px';
|
2019-03-05 02:35:40 +08:00
|
|
|
} else {
|
2020-07-04 07:18:05 +08:00
|
|
|
streamImg.style.width = '100%';
|
|
|
|
streamImg.style.height = 'auto';
|
2019-03-05 02:35:40 +08:00
|
|
|
}
|
|
|
|
} // end function changeScale()
|
|
|
|
|
2021-01-03 06:57:23 +08:00
|
|
|
$j(document).ready(initCycle);
|