diff --git a/html/admin.js b/html/admin.js index 1b586f77a4..6f569e9833 100644 --- a/html/admin.js +++ b/html/admin.js @@ -15,8 +15,8 @@ var secret = ""; var session = null; // Selected session var handle = null; // Selected handle -var plugins = [], pluginsIndex = []; -var transports = [], transportsIndex = []; +var plugins = [], pluginsIndex = [], pluginRows = 0; +var transports = [], transportsIndex = [], transportRows = 0; var settings = {}; var currentHandle = null; @@ -46,8 +46,8 @@ function promptAccessDetails() { if(prompting) return; prompting = true; - var serverPlaceholder = "Insert the address of the Admin API backend"; - var secretPlaceholder = "Insert the Admin API secret"; + let serverPlaceholder = "Insert the address of the Admin API backend"; + let secretPlaceholder = "Insert the Admin API secret"; bootbox.alert({ message: "
" + " " + @@ -70,9 +70,9 @@ function promptAccessDetails() { // Helper method to create random identifiers (e.g., transaction) function randomString(len) { const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - var randomString = ''; + let randomString = ''; for (let i = 0; i < len; i++) { - var randomPoz = Math.floor(Math.random() * charSet.length); + let randomPoz = Math.floor(Math.random() * charSet.length); randomString += charSet.substring(randomPoz,randomPoz+1); } return randomString; @@ -104,8 +104,8 @@ function updateServerInfo() { console.log("Got server info:"); console.log(json); var pluginsJson = json.plugins; - var transportsJson = json.transports; - var eventsJson = json.events; + let transportsJson = json.transports; + let eventsJson = json.events; delete json.janus; delete json.transaction; delete json.plugins; @@ -162,8 +162,8 @@ function updateServerInfo() { ); $('#plugin-'+(pluginsIndex.length-1)).click(function(event) { event.preventDefault(); - var pi = parseInt($(this).attr('id').split('plugin-')[1]); - var plugin = pluginsIndex[pi]; + let pi = parseInt($(this).attr('id').split('plugin-')[1]); + let plugin = pluginsIndex[pi]; console.log("Selected plugin:", plugin); $('#plugins-list a').removeClass('active'); $('#plugin-'+pi).addClass('active'); @@ -194,8 +194,8 @@ function updateServerInfo() { ); $('#transport-'+(transportsIndex.length-1)).click(function(event) { event.preventDefault(); - var ti = parseInt($(this).attr('id').split('transport-')[1]); - var transport = transportsIndex[ti]; + let ti = parseInt($(this).attr('id').split('transport-')[1]); + let transport = transportsIndex[ti]; console.log("Selected transport:", transport); $('#transports-list a').removeClass('active'); $('#transport-'+ti).addClass('active'); @@ -279,7 +279,7 @@ function updateServerInfo() { // Settings function updateSettings() { $('#update-settings').unbind('click').addClass('fa-spin'); - var request = { "janus": "get_status", "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "get_status", "transaction": randomString(12), "admin_secret": secret }; $.ajax({ type: 'POST', url: server, @@ -289,7 +289,7 @@ function updateSettings() { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -410,7 +410,7 @@ function updateSettings() { .addClass(!settings[k] ? "btn-success" : "btn-danger") .html(!settings[k] ? "Enable locking debug" : "Disable locking debug"); $('#'+k + "_button").click(function() { - var text = (!settings["locking_debug"] ? + let text = (!settings["locking_debug"] ? "Are you sure you want to enable the locking debug?
This will print a line on the console any time a mutex is locked/unlocked" : "Are you sure you want to disable the locking debug?"); bootbox.confirm(text, function(result) { @@ -424,7 +424,7 @@ function updateSettings() { .addClass(!settings[k] ? "btn-success" : "btn-danger") .html(!settings[k] ? "Enable reference counters debug" : "Disable reference counters debug"); $('#'+k + "_button").click(function() { - var text = (!settings["refcount_debug"] ? + let text = (!settings["refcount_debug"] ? "Are you sure you want to enable the reference counters debug?
This will print a line on the console any time a reference counter is increased/decreased" : "Are you sure you want to disable the reference counters debug?"); bootbox.confirm(text, function(result) { @@ -438,7 +438,7 @@ function updateSettings() { .addClass(!settings[k] ? "btn-success" : "btn-danger") .html(!settings[k] ? "Enable log timestamps" : "Disable log timestamps"); $('#'+k + "_button").click(function() { - var text = (!settings["log_timestamps"] ? + let text = (!settings["log_timestamps"] ? "Are you sure you want to enable the log timestamps?
This will print the current date/time for each new line on the console" : "Are you sure you want to disable the log timestamps?"); bootbox.confirm(text, function(result) { @@ -452,7 +452,7 @@ function updateSettings() { .addClass(!settings[k] ? "btn-success" : "btn-danger") .html(!settings[k] ? "Enable log colors" : "Disable log colors"); $('#'+k + "_button").click(function() { - var text = (!settings["log_colors"] ? + let text = (!settings["log_colors"] ? "Are you sure you want to enable the log colors?
This will strip the colors from events like warnings, errors, etc. on the console" : "Are you sure you want to disable the log colors?"); bootbox.confirm(text, function(result) { @@ -466,7 +466,7 @@ function updateSettings() { .addClass(!settings[k] ? "btn-success" : "btn-danger") .html(!settings[k] ? "Enable libnice debug" : "Disable libnice debug"); $('#'+k + "_button").click(function() { - var text = (!settings["libnice_debug"] ? + let text = (!settings["libnice_debug"] ? "Are you sure you want to enable the libnice debug?
This will print the a very verbose debug of every libnice-related operation on the console" : "Are you sure you want to disable the libnice debug?"); bootbox.confirm(text, function(result) { @@ -493,52 +493,52 @@ function updateSettings() { } function setSessionTimeoutValue(timeout) { - var request = { "janus": "set_session_timeout", "timeout": timeout, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_session_timeout", "timeout": timeout, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setLogLevel(level) { - var request = { "janus": "set_log_level", "level": level, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_log_level", "level": level, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setLockingDebug(enable) { - var request = { "janus": "set_locking_debug", "debug": enable, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_locking_debug", "debug": enable, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setRefcountDebug(enable) { - var request = { "janus": "set_refcount_debug", "debug": enable, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_refcount_debug", "debug": enable, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setLogTimestamps(enable) { - var request = { "janus": "set_log_timestamps", "timestamps": enable, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_log_timestamps", "timestamps": enable, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setLogColors(enable) { - var request = { "janus": "set_log_colors", "colors": enable, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_log_colors", "colors": enable, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setLibniceDebug(enable) { - var request = { "janus": "set_libnice_debug", "debug": enable, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_libnice_debug", "debug": enable, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setMinNackQueue(queue) { - var request = { "janus": "set_min_nack_queue", "min_nack_queue": queue, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_min_nack_queue", "min_nack_queue": queue, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setNoMediaTimer(timer) { - var request = { "janus": "set_no_media_timer", "no_media_timer": timer, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_no_media_timer", "no_media_timer": timer, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } function setSlowlinkThreshold(packets) { - var request = { "janus": "set_slowlink_threshold", "slowlink_threshold": packets, "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "set_slowlink_threshold", "slowlink_threshold": packets, "transaction": randomString(12), "admin_secret": secret }; sendSettingsRequest(request); } @@ -553,7 +553,7 @@ function sendSettingsRequest(request) { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -584,6 +584,7 @@ function sendSettingsRequest(request) { // Plugins function resetPluginRequest() { + pluginRows = 0; $('#plugin-request').empty().append( '' + ' Name' + @@ -599,28 +600,31 @@ function resetPluginRequest() { ''); $('#addattr').click(addPluginMessageAttribute).click(); $('#sendmsg').click(function() { - var message = {}; - var num = $('.pm-property').length; - for(let i=0; i' + ' ' + @@ -654,14 +659,17 @@ function addPluginMessageAttribute() { ' ' + ' ' + ' ' + - ' ' + + ' ' + '' ); + $('#rmattr' + num).click(function() { + $(this).parent().parent().remove(); + }); } function sendPluginMessage(plugin, message) { console.log("Sending message to " + plugin + ":", message); - var request = { + let request = { janus: "message_plugin", transaction: randomString(12), admin_secret: secret, @@ -677,7 +685,7 @@ function sendPluginMessage(plugin, message) { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -707,6 +715,7 @@ function sendPluginMessage(plugin, message) { // Transports function resetTransportRequest() { + transportRows = 0; $('#transport-request').empty().append( '' + ' Name' + @@ -715,35 +724,38 @@ function resetTransportRequest() { ' ' + '' + '' + - ' ' + + ' ' + ' ' + ' ' + - ' ' + + ' ' + ''); - $('#addattr').click(addTransportMessageAttribute).click(); - $('#sendmsg').click(function() { - var message = {}; - var num = $('.pm-property').length; - for(let i=0; i' + - ' ' + - ' ' + + ' ' + + ' ' + ' ' + - ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + - ' ' + + ' ' + '' ); + $('#rmtrattr' + num).click(function() { + $(this).parent().parent().remove(); + }); } function sendTransportMessage(transport, message) { console.log("Sending message to " + transport + ":", message); - var request = { + let request = { janus: "query_transport", transaction: randomString(12), admin_secret: secret, @@ -800,7 +816,7 @@ function sendTransportMessage(transport, message) { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -834,7 +850,7 @@ function updateSessions() { $('#update-sessions').unbind('click').addClass('fa-spin'); $('#update-handles').unbind('click'); $('#update-handle').unbind('click'); - var request = { "janus": "list_sessions", "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "list_sessions", "transaction": randomString(12), "admin_secret": secret }; $.ajax({ type: 'POST', url: server, @@ -844,7 +860,7 @@ function updateSessions() { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -873,15 +889,15 @@ function updateSessions() { console.log("Got sessions:"); console.log(json); $('#sessions-list').empty(); - var sessions = json["sessions"]; + let sessions = json["sessions"]; $('#sessions-num').text(sessions.length); for(let i=0; i'+s+'' ); $('#session-'+s).click(function() { - var sh = $(this).text(); + let sh = $(this).text(); console.log("Getting session " + sh + " handles"); session = sh; $('#sessions-list a').removeClass('active'); @@ -950,7 +966,7 @@ function updateHandles() { $('#update-sessions').unbind('click'); $('#update-handles').unbind('click').addClass('fa-spin'); $('#update-handle').unbind('click'); - var request = { "janus": "list_handles", "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "list_handles", "transaction": randomString(12), "admin_secret": secret }; $.ajax({ type: 'POST', url: server + "/" + session, @@ -960,7 +976,7 @@ function updateHandles() { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -981,15 +997,15 @@ function updateHandles() { console.log("Got handles:"); console.log(json); $('#handles-list').empty(); - var handles = json["handles"]; + let handles = json["handles"]; $('#handles-num').text(handles.length); for(let i=0; i'+h+'' ); $('#handle-'+h).click(function() { - var hi = $(this).text(); + let hi = $(this).text(); console.log("Getting handle " + hi + " info"); handle = hi; if(handle === currentHandle) @@ -1045,13 +1061,13 @@ function updateHandleInfo(refresh) { return; // The self-refresh takes care of that currentHandle = handle; } - var updateHandle = currentHandle; + let updateHandle = currentHandle; $('#update-sessions').unbind('click'); $('#update-handles').unbind('click'); $('#update-handle').unbind('click').addClass('fa-spin'); $('#capture').removeAttr('checked'); $('#capturetext').html('Start capture'); - var request = { "janus": "handle_info", "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "handle_info", "transaction": randomString(12), "admin_secret": secret }; $.ajax({ type: 'POST', url: server + "/" + session + "/" + handle, @@ -1062,7 +1078,7 @@ function updateHandleInfo(refresh) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME if(refresh !== true) { - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -1142,7 +1158,7 @@ function prettyHandleInfo() { $('#handle-info').html('
'); $('#options').hide(); for(let k in handleInfo) { - var v = handleInfo[k]; + let v = handleInfo[k]; if(k === "plugin_specific") { $('#handle-info').append( '

Plugin specific details

' + @@ -1193,7 +1209,7 @@ function prettyHandleInfo() { ''); $('#' + kk).click(function(event) { event.preventDefault(); - var sdp = $(this).attr('id') === "local" ? localSdp : remoteSdp; + let sdp = $(this).attr('id') === "local" ? localSdp : remoteSdp; bootbox.dialog({ title: "SDP (" + $(this).attr('id') + ")", message: '
' + sdp.split("\r\n").join("
") + '
' @@ -1212,7 +1228,7 @@ function prettyHandleInfo() { let vv = v[kk]; console.log(vv); for(let sk in vv) { - var sv = vv[sk]; + let sv = vv[sk]; if(sk === "ssrc") { $('#stream' + kk).append( '' + @@ -1250,9 +1266,9 @@ function prettyHandleInfo() { '' + ''); for(let cssk in ssv) { - var cssv = ssv[cssk]; + let cssv = ssv[cssk]; if(cssk === "local-candidates" || cssk === "remote-candidates") { - var candidates = "
    "; + let candidates = "
      "; for(let c in cssv) candidates += "
    • " + cssv[c] + "
    • "; candidates += "
    "; @@ -1262,7 +1278,7 @@ function prettyHandleInfo() { ' ' + candidates + '' + ''); } else if(cssk === "dtls" || cssk === "in_stats" || cssk === "out_stats") { - var dtls = ''; + let dtls = '
    '; for(let d in cssv) { dtls += '' + @@ -1308,7 +1324,7 @@ function prettyHandleInfo() { // Tokens function updateTokens() { $('#update-tokens').unbind('click').addClass('fa-spin'); - var request = { "janus": "list_tokens", "transaction": randomString(12), "admin_secret": secret }; + let request = { "janus": "list_tokens", "transaction": randomString(12), "admin_secret": secret }; $.ajax({ type: 'POST', url: server, @@ -1318,7 +1334,7 @@ function updateTokens() { success: function(json) { if(json["janus"] !== "success") { console.log("Ooops: " + json["error"].code + " " + json["error"].reason); // FIXME - var authenticate = (json["error"].code === 403); + let authenticate = (json["error"].code === 403); if(!authenticate || (authenticate && !prompting && !alerted)) { if(authenticate) alerted = true; @@ -1346,8 +1362,8 @@ function updateTokens() { ' ' + ''); for(let index in json.data.tokens) { - var t = json.data.tokens[index]; - var tokenPlugins = t.allowed_plugins.toString().replace(/,/g,'
    '); + let t = json.data.tokens[index]; + let tokenPlugins = t.allowed_plugins.toString().replace(/,/g,'
    '); $('#auth-tokens').append( '' + ' ' + @@ -1355,7 +1371,7 @@ function updateTokens() { ' ' + ''); $('#'+t.token).click(function() { - var token = $(this).attr('id'); + let token = $(this).attr('id'); bootbox.confirm("Are you sure you want to remove token " + token + "?", function(result) { if(result) removeToken(token); @@ -1368,9 +1384,9 @@ function updateTokens() { ' ' + ' ' + ''); - var pluginsCheckboxes = ""; + let pluginsCheckboxes = ""; for(let i in plugins) { - var plugin = plugins[i]; + let plugin = plugins[i]; pluginsCheckboxes += '
    ' + '
    ' + t.token + '