Add Janus to Cycle view. Remove debug Alert() messages

This commit is contained in:
Jonathan Bennett 2022-01-12 22:46:26 -06:00
parent aeefc512ab
commit 2beffeb1b4
6 changed files with 75 additions and 9 deletions

View File

@ -1117,12 +1117,13 @@ bool Monitor::connect() {
//End ONVIF Setup
#endif
//janus setup.
#if HAVE_LIBCURL //janus setup. Depends on libcurl.
if (janus_enabled && (path.find("rtsp://") != std::string::npos)) {
if (add_to_janus() != 0) {
Warning("Failed to add monitor stream to Janus!");
}
}
#endif
} else if (!shared_data->valid) {
Error("Shared data not initialised by capture daemon for monitor %s", name.c_str());
@ -3206,10 +3207,11 @@ int Monitor::Close() {
soap = nullptr;
} //End ONVIF
#endif
//Janus Teardown
#if HAVE_LIBCURL //Janus Teardown
if (janus_enabled && (purpose == CAPTURE)) {
remove_from_janus();
}
#endif
packetqueue.clear();
if (audio_fifo) {

View File

@ -192,4 +192,6 @@ xhtmlHeaders(__FILE__, translate('CycleWatch'));
</div>
</div>
</div>
<script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script>
<script src="<?php echo cache_bust('js/janus.js') ?>"></script>
<?php xhtmlFooter() ?>

View File

@ -1,3 +1,6 @@
var server;
var janus = null;
var streaming2;
var intervalId;
var pauseBtn = $j('#pauseBtn');
var playBtn = $j('#playBtn');
@ -46,6 +49,68 @@ function initCycle() {
intervalId = setInterval(nextCycleView, cycleRefreshTimeout);
var scale = $j('#scale').val();
if ( scale == '0' || scale == 'auto' ) changeScale();
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;
var body = { "request": "watch", "id":monitorData[monIdx].id };
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"];
if(result !== null && result !== undefined) {
if(result["status"] !== undefined && result["status"] !== null) {
var status = result["status"];
}
} else if(msg["error"] !== undefined && msg["error"] !== null) {
Janus.debug(msg["error"]);
return;
}
if(jsep !== undefined && jsep !== null) {
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
media: { audioSend: false, videoSend: false, data: true },
success: function(jsep) {
Janus.debug("Got SDP!");
Janus.debug(jsep);
var body = { "request": "start"};
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
}
function changeSize() {

View File

@ -20,7 +20,8 @@ monitorData[monitorData.length] = {
'url': '<?php echo $monitor->UrlToIndex() ?>',
'onclick': function(){window.location.assign( '?view=watch&mid=<?php echo $monitor->Id() ?>' );},
'type': '<?php echo $monitor->Type() ?>',
'refresh': '<?php echo $monitor->Refresh() ?>'
'refresh': '<?php echo $monitor->Refresh() ?>',
'janusEnabled': <?php echo $monitor->JanusEnabled() ?>
};
<?php
} // end foreach monitor

View File

@ -373,8 +373,7 @@ function attachVideo(janus, i) {
var status = result["status"];
}
} else if(msg["error"] !== undefined && msg["error"] !== null) {
alert(msg["error"]);
stopStream();
Janus.error(msg["error"]);
return;
}
if(jsep !== undefined && jsep !== null) {
@ -393,7 +392,6 @@ function attachVideo(janus, i) {
},
error: function(error) {
Janus.error("WebRTC error:", error);
alert("WebRTC error... " + JSON.stringify(error));
}
});
}

View File

@ -937,8 +937,7 @@ function initPage() {
var status = result["status"];
}
} else if(msg["error"] !== undefined && msg["error"] !== null) {
alert(msg["error"]);
stopStream();
Janus.error(msg["error"]);
return;
}
if(jsep !== undefined && jsep !== null) {
@ -957,7 +956,6 @@ function initPage() {
},
error: function(error) {
Janus.error("WebRTC error:", error);
alert("WebRTC error... " + JSON.stringify(error));
}
});
}