var websocket_server = null; if(window.location.protocol === 'http:') websocket_server = "ws://" + window.location.hostname + "/janus-ws/janus"; else websocket_server = "wss://" + window.location.hostname + "/janus-ws/janus"; var janus = null; var streaming = null; var mixertest = null; var opaqueId = "streamingwithfeedback-"+Janus.randomString(12); var bitrateTimer = null; var spinner = null; var simulcastStarted = false, svcStarted = false; var selectedStream = null; var myroom = null; var myusername = null; var myid = null; var webrtcUp = false; var audioenabled = false; $(document).ready(function() { // Initialize the library (all console debuggers enabled) Janus.init({debug: "all", callback: function() { // Use a button to start the demo $('#start').one('click', function() { $(this).attr('disabled', true).unbind('click'); // Make sure the browser supports WebRTC if(!Janus.isWebrtcSupported()) { bootbox.alert("No WebRTC support... "); return; } // Create session janus = new Janus( { server: [websocket_server, "/janus"], iceServers: [{urls: "turn:morla.jones.dk", username: "myturn", credential: "notsecure"}, {urls: "turn:jawa.homebase.dk", username: "myturn", credential: "notsecure"}], success: function() { // Attach to streaming plugin janus.attach( { plugin: "janus.plugin.streaming", opaqueId: opaqueId, success: function(pluginHandle) { $('#details').remove(); streaming = pluginHandle; Janus.log("Plugin attached! (" + streaming.getPlugin() + ", id=" + streaming.getId() + ")"); // Setup streaming session $('#update-streams').click(updateStreamsList); updateStreamsList(); $('#start').removeAttr('disabled').html("Stop") .click(function() { $(this).attr('disabled', true); clearInterval(bitrateTimer); janus.destroy(); $('#streamslist').attr('disabled', true); $('#watch').attr('disabled', true).unbind('click'); $('#start').attr('disabled', true).html("Bye").unbind('click'); }); }, error: function(error) { Janus.error(" -- Error attaching plugin... ", error); bootbox.alert("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"]; if(status === 'starting') $('#status').removeClass('hide').text("Starting, please wait...").show(); else if(status === 'started') $('#status').removeClass('hide').text("Started").show(); else if(status === 'stopped') stopStream(); } else if(msg["streaming"] === "event") { // Is simulcast in place? var substream = result["substream"]; var temporal = result["temporal"]; if((substream !== null && substream !== undefined) || (temporal !== null && temporal !== undefined)) { if(!simulcastStarted) { simulcastStarted = true; addSimulcastButtons(temporal !== null && temporal !== undefined); } // We just received notice that there's been a switch, update the buttons updateSimulcastButtons(substream, temporal); } // Is VP9/SVC in place? var spatial = result["spatial_layer"]; temporal = result["temporal_layer"]; if((spatial !== null && spatial !== undefined) || (temporal !== null && temporal !== undefined)) { if(!svcStarted) { svcStarted = true; addSvcButtons(); } // We just received notice that there's been a switch, update the buttons updateSvcButtons(spatial, temporal); } } } else if(msg["error"] !== undefined && msg["error"] !== null) { bootbox.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}); $('#watch').html("Stop").removeAttr('disabled').click(stopStream); }, error: function(error) { Janus.error("WebRTC error:", error); bootbox.alert("WebRTC error... " + JSON.stringify(error)); } }); } }, onremotestream: function(stream) { Janus.debug(" ::: Got a remote stream :::"); Janus.debug(stream); var addButtons = false; if($('#remotevideo').length === 0) { addButtons = true; $('#stream').append('