Janus cleanup, adds support to the "watch" view

This commit is contained in:
Jonathan Bennett 2022-01-11 21:19:58 -06:00
parent 2729e1de22
commit 50c824f3bb
9 changed files with 164 additions and 77 deletions

50
misc/janus.jcfg Normal file
View File

@ -0,0 +1,50 @@
general: {
configs_folder = "/usr/local/etc/janus" # Configuration files folder
plugins_folder = "/usr/local/lib/janus/plugins" # Plugins folder
transports_folder = "/usr/local/lib/janus/transports" # Transports folder
events_folder = "/usr/local/lib/janus/events" # Event handlers folder
loggers_folder = "/usr/local/lib/janus/loggers" # External loggers folder
debug_level = 4 # Debug/logging level, valid values are 0-7
admin_secret = "janusoverlord" # String that all Janus requests must contain
protected_folders = [
"/bin",
"/boot",
"/dev",
"/etc",
"/initrd",
"/lib",
"/lib32",
"/lib64",
"/proc",
"/sbin",
"/sys",
"/usr",
"/var",
"/opt/janus/bin",
"/opt/janus/etc",
"/opt/janus/include",
"/opt/janus/lib",
"/opt/janus/lib32",
"/opt/janus/lib64",
"/opt/janus/sbin"
]
}
media: {
#ipv6 = true
#ipv6_linklocal = true
rtp_port_range = "20000-40000"
}
nat: {
nice_debug = false
ignore_mdns = true
keep_private_host = true
ice_ignore_list = "vmnet"
}
plugins: {
disable = "libjanus_audiobridge.so,libjanus_echotest.so,libjanus_recordplay.so,libjanus_sip.so,libjanus_textroom.so,libjanus_videocall.so,libjanus_videoroom.so,libjanus_voicemail.so,
libjanus_nosip.so"
}
transports: {
disable = "libjanus_rabbitmq.so, libjanus_pfunix.so,libjanus_websockets.so"
}

View File

@ -0,0 +1,4 @@
general: {
admin_key = "supersecret"
rtp_port_range = "20000-40000"
}

View File

@ -0,0 +1,25 @@
general: {
json = "indented" # Whether the JSON messages should be indented (default),
base_path = "/janus" # Base path to bind to in the web server (plain HTTP only)
http = true # Whether to enable the plain HTTP interface
port = 8088 # Web server HTTP port
https = false # Whether to enable HTTPS (default=false)
}
# Janus can also expose an admin/monitor endpoint, to allow you to check
# which sessions are up, which handles they're managing, their current
# status and so on. This provides a useful aid when debugging potential
# issues in Janus. The configuration is pretty much the same as the one
# already presented above for the webserver stuff, as the API is very
# similar: choose the base bath for the admin/monitor endpoint (/admin
# by default), ports, etc. Besides, you can specify
# a secret that must be provided in all requests as a crude form of
# authorization mechanism, and partial or full source IPs if you want to
# limit access basing on IP addresses. For security reasons, this
# endpoint is disabled by default, enable it by setting admin_http=true.
admin: {
admin_base_path = "/admin" # Base path to bind to in the admin/monitor web server (plain HTTP only)
admin_http = false # Whether to enable the plain HTTP interface
admin_port = 7088 # Admin/monitor web server HTTP port
admin_https = false # Whether to enable HTTPS (default=false)
}

View File

@ -5,7 +5,6 @@ function MonitorStream(monitorData) {
this.auth_relay = auth_relay;
this.auth_hash = auth_hash;
this.url = monitorData.url;
this.janusEnabled = monitorData.janusEnabled;
this.url_to_zms = monitorData.url_to_zms;
this.width = monitorData.width;
this.height = monitorData.height;
@ -87,71 +86,6 @@ function MonitorStream(monitorData) {
console.log(stream);
return;
}
if (this.janusEnabled) {
var id = parseInt(this.id);
var opaqueId = "streamingtest-"+Janus.randomString(12);
var server = "http://zm-dev:8088/janus";
Janus.init({debug: "all", callback: function() {
janus = new Janus({
server: server,
success: function() {
janus.attach({
plugin: "janus.plugin.streaming",
opaqueId: opaqueId,
success: function(pluginHandle) {
streaming = pluginHandle;
var body = { "request": "watch", "id": id };
streaming.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) {
alert(msg["error"]);
stopStream();
return;
}
if(jsep !== undefined && jsep !== null) {
Janus.debug("Handling SDP as well...");
Janus.debug(jsep);
// Offer from the plugin, let's answer
streaming.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"};
streaming.send({"message": body, "jsep": jsep});
},
error: function(error) {
Janus.error("WebRTC error:", error);
alert("WebRTC error... " + JSON.stringify(error));
}
});
}
}, //onmessage function
onremotestream: function(ourstream) {
Janus.debug(" ::: Got a remote track :::");
Janus.debug(ourstream);
Janus.attachMediaStream(stream, ourstream);
stream.play()
}
});// attach
} //Success functio
}); //new Janus
}}); //janus.init callback
return;
}
src = stream.src.replace(/mode=single/i, 'mode=jpeg');
if ( -1 == src.search('connkey') ) {
src += '&connkey='+this.connKey;

1
web/js/adapter.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -315,7 +315,7 @@ function initPage() {
}
}
if (initJanus) {
server = "http://zm-dev:8088/janus";
server = "http://" + window.location.hostname + ":8088/janus";
opaqueId = "streamingtest-"+Janus.randomString(12);
Janus.init({debug: "all", callback: function() {
janus = new Janus({

View File

@ -9,6 +9,10 @@ var forceAlmBtn = $j('#forceAlmBtn');
var table = $j('#eventList');
var filterQuery = '&filter[Query][terms][0][attr]=MonitorId&filter[Query][terms][0][op]=%3d&filter[Query][terms][0][val]='+monitorId;
var server;
var janus = null;
var opaqueId;
var streaming2;
/*
This is the format of the json object sent by bootstrap-table
@ -897,15 +901,78 @@ function initPage() {
}
if (monitorType != 'WebSite') {
if (streamMode == 'single') {
statusCmdTimer = setTimeout(statusCmdQuery, 200);
setInterval(watchdogCheck, statusRefreshTimeout*2, 'status');
} else {
streamCmdTimer = setTimeout(streamCmdQuery, 200);
setInterval(watchdogCheck, statusRefreshTimeout*2, 'stream');
if (streamMode != 'janus') {
if (streamMode == 'single') {
statusCmdTimer = setTimeout(statusCmdQuery, 200);
setInterval(watchdogCheck, statusRefreshTimeout*2, 'status');
} else {
streamCmdTimer = setTimeout(streamCmdQuery, 200);
setInterval(watchdogCheck, statusRefreshTimeout*2, 'stream');
}
}
if (canStreamNative || (streamMode == 'single')) {
if (streamMode == 'janus') {
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":monitorId };
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) {
alert(msg["error"]);
stopStream();
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);
alert("WebRTC error... " + JSON.stringify(error));
}
});
}
}, //onmessage function
onremotestream: function(stream) {
Janus.debug(" ::: Got a remote track :::");
Janus.debug(stream);
Janus.attachMediaStream(document.getElementById("liveStream" + monitorId), stream);
document.getElementById("liveStream" + monitorId).play();
}
});// attach
} //Success functio
}); //new Janus
}}); //janus.init callback
} else if (canStreamNative || (streamMode == 'single')) {
var streamImg = $j('#imageFeed img');
if (!streamImg) streamImg = $j('#imageFeed object');
if (!streamImg) {

View File

@ -325,7 +325,7 @@ foreach (array_reverse($zones) as $zone) {
</div>
</div>
</div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/8.1.0/adapter.min.js"></script>
<script src="<?php echo cache_bust('js/adapter.min.js') ?>"></script>
<script src="<?php echo cache_bust('js/janus.js') ?>"></script>
<script src="<?php echo cache_bust('js/MonitorStream.js') ?>"></script>
<?php xhtmlFooter() ?>

View File

@ -135,7 +135,11 @@ if (isset($_REQUEST['height'])) {
}
$connkey = generateConnKey();
$streamMode = getStreamMode();
if ( $monitor->JanusEnabled() ) {
$streamMode = 'janus';
} else {
$streamMode = getStreamMode();
}
noCacheHeaders();
xhtmlHeaders(__FILE__, $monitor->Name().' - '.translate('Feed'));
@ -407,4 +411,6 @@ if ( ZM_WEB_SOUND_ON_ALARM ) {
?>
</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() ?>