sak1b

mvr.js

Jul 26th, 2021
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // We make use of this 'server' variable to provide the address of the
  2. // REST Janus API. By default, in this example we assume that Janus is
  3. // co-located with the web server hosting the HTML pages but listening
  4. // on a different port (8088, the default for HTTP in Janus), which is
  5. // why we make use of the 'window.location.hostname' base address. Since
  6. // Janus can also do HTTPS, and considering we don't really want to make
  7. // use of HTTP for Janus if your demos are served on HTTPS, we also rely
  8. // on the 'window.location.protocol' prefix to build the variable, in
  9. // particular to also change the port used to contact Janus (8088 for
  10. // HTTP and 8089 for HTTPS, if enabled).
  11. // In case you place Janus behind an Apache frontend (as we did on the
  12. // online demos at http://janus.conf.meetecho.com) you can just use a
  13. // relative path for the variable, e.g.:
  14. //
  15. //      var server = "/janus";
  16. //
  17. // which will take care of this on its own.
  18. //
  19. //
  20. // If you want to use the WebSockets frontend to Janus, instead, you'll
  21. // have to pass a different kind of address, e.g.:
  22. //
  23. //      var server = "ws://" + window.location.hostname + ":8188";
  24. //
  25. // Of course this assumes that support for WebSockets has been built in
  26. // when compiling the server. WebSockets support has not been tested
  27. // as much as the REST API, so handle with care!
  28. //
  29. //
  30. // If you have multiple options available, and want to let the library
  31. // autodetect the best way to contact your server (or pool of servers),
  32. // you can also pass an array of servers, e.g., to provide alternative
  33. // means of access (e.g., try WebSockets first and, if that fails, fall
  34. // back to plain HTTP) or just have failover servers:
  35. //
  36. //      var server = [
  37. //          "ws://" + window.location.hostname + ":8188",
  38. //          "/janus"
  39. //      ];
  40. //
  41. // This will tell the library to try connecting to each of the servers
  42. // in the presented order. The first working server will be used for
  43. // the whole session.
  44. //
  45. var server = null;
  46. if(window.location.protocol === 'http:')
  47.     server = "http://" + window.location.hostname + ":8088/janus";
  48. else
  49.     server = "https://" + window.location.hostname + ":8089/janus";
  50. server = "wss://" + window.location.hostname + "/ws";
  51.  
  52. var janus = null;
  53. var sfutest = null;
  54. var opaqueId = "videoroomtest-"+Janus.randomString(12);
  55.  
  56. var myroom = 1234;  // Demo room
  57. if(getQueryStringValue("room") !== "")
  58.     myroom = parseInt(getQueryStringValue("room"));
  59. var myusername = null;
  60. var myid = null;
  61. var mystream = null;
  62. // We use this other ID just to map our subscriptions to us
  63. var mypvtid = null;
  64.  
  65. var remoteFeed = null;
  66. var feeds = {}, feedStreams = {}, subStreams = {}, slots = {}, mids = {}, subscriptions = {};
  67. var localTracks = {}, localVideos = 0, remoteTracks = {};
  68. var bitrateTimer = [], simulcastStarted = {};
  69.  
  70. var doSimulcast = (getQueryStringValue("simulcast") === "yes" || getQueryStringValue("simulcast") === "true");
  71. var doSimulcast2 = (getQueryStringValue("simulcast2") === "yes" || getQueryStringValue("simulcast2") === "true");
  72. var acodec = (getQueryStringValue("acodec") !== "" ? getQueryStringValue("acodec") : null);
  73. var vcodec = (getQueryStringValue("vcodec") !== "" ? getQueryStringValue("vcodec") : null);
  74. var subscriber_mode = (getQueryStringValue("subscriber-mode") === "yes" || getQueryStringValue("subscriber-mode") === "true");
  75.  
  76. $(document).ready(function() {
  77.     // Initialize the library (all console debuggers enabled)
  78.     Janus.init({debug: "all", callback: function() {
  79.         // Use a button to start the demo
  80.         $('#start').one('click', function() {
  81.             $(this).attr('disabled', true).unbind('click');
  82.             // Make sure the browser supports WebRTC
  83.             if(!Janus.isWebrtcSupported()) {
  84.                 bootbox.alert("No WebRTC support... ");
  85.                 return;
  86.             }
  87.             // Create session
  88.             janus = new Janus(
  89.                 {
  90.                     server: server,
  91.                     success: function() {
  92.                         // Attach to video room test plugin
  93.                         janus.attach(
  94.                             {
  95.                                 plugin: "janus.plugin.videoroom",
  96.                                 opaqueId: opaqueId,
  97.                                 success: function(pluginHandle) {
  98.                                     $('#details').remove();
  99.                                     sfutest = pluginHandle;
  100.                                     Janus.log("Plugin attached! (" + sfutest.getPlugin() + ", id=" + sfutest.getId() + ")");
  101.                                     Janus.log("  -- This is a publisher/manager");
  102.                                     // Prepare the username registration
  103.                                     $('#videojoin').removeClass('hide').show();
  104.                                     $('#registernow').removeClass('hide').show();
  105.                                     $('#register').click(registerUsername);
  106.                                     $('#username').focus();
  107.                                     $('#start').removeAttr('disabled').html("Stop")
  108.                                         .click(function() {
  109.                                             $(this).attr('disabled', true);
  110.                                             janus.destroy();
  111.                                         });
  112.                                 },
  113.                                 error: function(error) {
  114.                                     Janus.error("  -- Error attaching plugin...", error);
  115.                                     bootbox.alert("Error attaching plugin... " + error);
  116.                                 },
  117.                                 consentDialog: function(on) {
  118.                                     Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now");
  119.                                     if(on) {
  120.                                         // Darken screen and show hint
  121.                                         $.blockUI({
  122.                                             message: '<div><img src="up_arrow.png"/></div>',
  123.                                             css: {
  124.                                                 border: 'none',
  125.                                                 padding: '15px',
  126.                                                 backgroundColor: 'transparent',
  127.                                                 color: '#aaa',
  128.                                                 top: '10px',
  129.                                                 left: (navigator.mozGetUserMedia ? '-100px' : '300px')
  130.                                             } });
  131.                                     } else {
  132.                                         // Restore screen
  133.                                         $.unblockUI();
  134.                                     }
  135.                                 },
  136.                                 iceState: function(state) {
  137.                                     Janus.log("ICE state changed to " + state);
  138.                                 },
  139.                                 mediaState: function(medium, on, mid) {
  140.                                     Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium + " (mid=" + mid + ")");
  141.                                 },
  142.                                 webrtcState: function(on) {
  143.                                     Janus.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
  144.                                     $("#videolocal").parent().parent().unblock();
  145.                                     if(!on)
  146.                                         return;
  147.                                     $('#publish').remove();
  148.                                     // This controls allows us to override the global room bitrate cap
  149.                                     $('#bitrate').parent().parent().removeClass('hide').show();
  150.                                     $('#bitrate a').click(function() {
  151.                                         var id = $(this).attr("id");
  152.                                         var bitrate = parseInt(id)*1000;
  153.                                         if(bitrate === 0) {
  154.                                             Janus.log("Not limiting bandwidth via REMB");
  155.                                         } else {
  156.                                             Janus.log("Capping bandwidth to " + bitrate + " via REMB");
  157.                                         }
  158.                                         $('#bitrateset').html($(this).html() + '<span class="caret"></span>').parent().removeClass('open');
  159.                                         sfutest.send({ message: { request: "configure", bitrate: bitrate }});
  160.                                         return false;
  161.                                     });
  162.                                 },
  163.                                 slowLink: function(uplink, lost, mid) {
  164.                                     Janus.warn("Janus reports problems " + (uplink ? "sending" : "receiving") +
  165.                                         " packets on mid " + mid + " (" + lost + " lost packets)");
  166.                                 },
  167.                                 onmessage: function(msg, jsep) {
  168.                                     Janus.debug(" ::: Got a message (publisher) :::", msg);
  169.                                     var event = msg["videoroom"];
  170.                                     Janus.debug("Event: " + event);
  171.                                     if(event != undefined && event != null) {
  172.                                         if(event === "joined") {
  173.                                             // Publisher/manager created, negotiate WebRTC and attach to existing feeds, if any
  174.                                             myid = msg["id"];
  175.                                             mypvtid = msg["private_id"];
  176.                                             Janus.log("Successfully joined room " + msg["room"] + " with ID " + myid);
  177.                                             if(subscriber_mode) {
  178.                                                 $('#videojoin').hide();
  179.                                                 $('#videos').removeClass('hide').show();
  180.                                             } else {
  181.                                                 publishOwnFeed(true);
  182.                                             }
  183.                                             // Any new feed to attach to?
  184.                                             if(msg["publishers"]) {
  185.                                                 var list = msg["publishers"];
  186.                                                 Janus.debug("Got a list of available publishers/feeds:", list);
  187.                                                 var sources = null;
  188.                                                 for(var f in list) {
  189.                                                     var id = list[f]["id"];
  190.                                                     var display = list[f]["display"];
  191.                                                     var streams = list[f]["streams"];
  192.                                                     for(var i in streams) {
  193.                                                         var stream = streams[i];
  194.                                                         stream["id"] = id;
  195.                                                         stream["display"] = display;
  196.                                                     }
  197.                                                     feedStreams[id] = {
  198.                                                         id: id,
  199.                                                         display: display,
  200.                                                         streams: streams
  201.                                                     }
  202.                                                     Janus.debug("  >> [" + id + "] " + display + ":", streams);
  203.                                                     if(!sources)
  204.                                                         sources = [];
  205.                                                     sources.push(streams);
  206.                                                 }
  207.                                                 if(sources)
  208.                                                     subscribeTo(sources);
  209.                                             }
  210.                                         } else if(event === "destroyed") {
  211.                                             // The room has been destroyed
  212.                                             Janus.warn("The room has been destroyed!");
  213.                                             bootbox.alert("The room has been destroyed", function() {
  214.                                                 window.location.reload();
  215.                                             });
  216.                                         } else if(event === "event") {
  217.                                             // Any info on our streams or a new feed to attach to?
  218.                                             if(msg["streams"]) {
  219.                                                 var streams = msg["streams"];
  220.                                                 for(var i in streams) {
  221.                                                     var stream = streams[i];
  222.                                                     stream["id"] = myid;
  223.                                                     stream["display"] = myusername;
  224.                                                 }
  225.                                                 feedStreams[myid] = {
  226.                                                     id: myid,
  227.                                                     display: myusername,
  228.                                                     streams: streams
  229.                                                 }
  230.                                             } else if(msg["publishers"]) {
  231.                                                 var list = msg["publishers"];
  232.                                                 Janus.debug("Got a list of available publishers/feeds:", list);
  233.                                                 var sources = null;
  234.                                                 for(var f in list) {
  235.                                                     var id = list[f]["id"];
  236.                                                     var display = list[f]["display"];
  237.                                                     var streams = list[f]["streams"];
  238.                                                     for(var i in streams) {
  239.                                                         var stream = streams[i];
  240.                                                         stream["id"] = id;
  241.                                                         stream["display"] = display;
  242.                                                     }
  243.                                                     feedStreams[id] = {
  244.                                                         id: id,
  245.                                                         display: display,
  246.                                                         streams: streams
  247.                                                     }
  248.                                                     Janus.debug("  >> [" + id + "] " + display + ":", streams);
  249.                                                     if(!sources)
  250.                                                         sources = [];
  251.                                                     sources.push(streams);
  252.                                                 }
  253.                                                 if(sources)
  254.                                                     subscribeTo(sources);
  255.                                             } else if(msg["leaving"]) {
  256.                                                 // One of the publishers has gone away?
  257.                                                 var leaving = msg["leaving"];
  258.                                                 Janus.log("Publisher left: " + leaving);
  259.                                                 unsubscribeFrom(leaving);
  260.                                             } else if(msg["unpublished"]) {
  261.                                                 // One of the publishers has unpublished?
  262.                                                 var unpublished = msg["unpublished"];
  263.                                                 Janus.log("Publisher left: " + unpublished);
  264.                                                 if(unpublished === 'ok') {
  265.                                                     // That's us
  266.                                                     sfutest.hangup();
  267.                                                     return;
  268.                                                 }
  269.                                                 unsubscribeFrom(unpublished);
  270.                                             } else if(msg["error"]) {
  271.                                                 if(msg["error_code"] === 426) {
  272.                                                     // This is a "no such room" error: give a more meaningful description
  273.                                                     bootbox.alert(
  274.                                                         "<p>Apparently room <code>" + myroom + "</code> (the one this demo uses as a test room) " +
  275.                                                         "does not exist...</p><p>Do you have an updated <code>janus.plugin.videoroom.cfg</code> " +
  276.                                                         "configuration file? If not, make sure you copy the details of room <code>" + myroom + "</code> " +
  277.                                                         "from that sample in your current configuration file, then restart Janus and try again."
  278.                                                     );
  279.                                                 } else {
  280.                                                     bootbox.alert(msg["error"]);
  281.                                                 }
  282.                                             }
  283.                                         }
  284.                                     }
  285.                                     if(jsep) {
  286.                                         Janus.debug("Handling SDP as well...", jsep);
  287.                                         sfutest.handleRemoteJsep({ jsep: jsep });
  288.                                         // Check if any of the media we wanted to publish has
  289.                                         // been rejected (e.g., wrong or unsupported codec)
  290.                                         var audio = msg["audio_codec"];
  291.                                         if(mystream && mystream.getAudioTracks() && mystream.getAudioTracks().length > 0 && !audio) {
  292.                                             // Audio has been rejected
  293.                                             toastr.warning("Our audio stream has been rejected, viewers won't hear us");
  294.                                         }
  295.                                         var video = msg["video_codec"];
  296.                                         if(mystream && mystream.getVideoTracks() && mystream.getVideoTracks().length > 0 && !video) {
  297.                                             // Video has been rejected
  298.                                             toastr.warning("Our video stream has been rejected, viewers won't see us");
  299.                                             // Hide the webcam video
  300.                                             $('#myvideo').hide();
  301.                                             $('#videolocal').append(
  302.                                                 '<div class="no-video-container">' +
  303.                                                     '<i class="fa fa-video-camera fa-5 no-video-icon" style="height: 100%;"></i>' +
  304.                                                     '<span class="no-video-text" style="font-size: 16px;">Video rejected, no webcam</span>' +
  305.                                                 '</div>');
  306.                                         }
  307.                                     }
  308.                                 },
  309.                                 onlocaltrack: function(track, on) {
  310.                                     Janus.debug(" ::: Got a local track event :::");
  311.                                     Janus.debug("Local track " + (on ? "added" : "removed") + ":", track);
  312.                                     // We use the track ID as name of the element, but it may contain invalid characters
  313.                                     var trackId = track.id.replace(/[{}]/g, "");
  314.                                     if(!on) {
  315.                                         // Track removed, get rid of the stream and the rendering
  316.                                         var stream = localTracks[trackId];
  317.                                         if(stream) {
  318.                                             try {
  319.                                                 var tracks = stream.getTracks();
  320.                                                 for(var i in tracks) {
  321.                                                     var mst = tracks[i];
  322.                                                     if(mst)
  323.                                                         mst.stop();
  324.                                                 }
  325.                                             } catch(e) {}
  326.                                         }
  327.                                         if(track.kind === "video") {
  328.                                             $('#myvideo' + trackId).remove();
  329.                                             localVideos--;
  330.                                             if(localVideos === 0) {
  331.                                                 // No video, at least for now: show a placeholder
  332.                                                 if($('#videolocal .no-video-container').length === 0) {
  333.                                                     $('#videolocal').append(
  334.                                                         '<div class="no-video-container">' +
  335.                                                             '<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
  336.                                                             '<span class="no-video-text">No webcam available</span>' +
  337.                                                         '</div>');
  338.                                                 }
  339.                                             }
  340.                                         }
  341.                                         delete localTracks[trackId];
  342.                                         return;
  343.                                     }
  344.                                     // If we're here, a new track was added
  345.                                     var stream = localTracks[trackId];
  346.                                     if(stream) {
  347.                                         // We've been here already
  348.                                         return;
  349.                                     }
  350.                                     $('#videos').removeClass('hide').show();
  351.                                     if($('#mute').length === 0) {
  352.                                         // Add a 'mute' button
  353.                                         $('#videolocal').append('<button class="btn btn-warning btn-xs" id="mute" style="position: absolute; bottom: 0px; left: 0px; margin: 15px;">Mute</button>');
  354.                                         $('#mute').click(toggleMute);
  355.                                         // Add an 'unpublish' button
  356.                                         $('#videolocal').append('<button class="btn btn-warning btn-xs" id="unpublish" style="position: absolute; bottom: 0px; right: 0px; margin: 15px;">Unpublish</button>');
  357.                                         $('#unpublish').click(unpublishOwnFeed);
  358.                                     }
  359.                                     if(track.kind === "audio") {
  360.                                         // We ignore local audio tracks, they'd generate echo anyway
  361.                                         if(localVideos === 0) {
  362.                                             // No video, at least for now: show a placeholder
  363.                                             if($('#videolocal .no-video-container').length === 0) {
  364.                                                 $('#videolocal').append(
  365.                                                     '<div class="no-video-container">' +
  366.                                                         '<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
  367.                                                         '<span class="no-video-text">No webcam available</span>' +
  368.                                                     '</div>');
  369.                                             }
  370.                                         }
  371.                                     } else {
  372.                                         // New video track: create a stream out of it
  373.                                         localVideos++;
  374.                                         $('#videolocal .no-video-container').remove();
  375.                                         stream = new MediaStream();
  376.                                         stream.addTrack(track.clone());
  377.                                         localTracks[trackId] = stream;
  378.                                         Janus.log("Created local stream:", stream);
  379.                                         Janus.log(stream.getTracks());
  380.                                         Janus.log(stream.getVideoTracks());
  381.                                         $('#videolocal').append('<video class="rounded centered" id="myvideo' + trackId + '" width=100% autoplay playsinline muted="muted"/>');
  382.                                         Janus.attachMediaStream($('#myvideo' + trackId).get(0), stream);
  383.                                     }
  384.                                     if(sfutest.webrtcStuff.pc.iceConnectionState !== "completed" &&
  385.                                             sfutest.webrtcStuff.pc.iceConnectionState !== "connected") {
  386.                                         $("#videolocal").parent().parent().block({
  387.                                             message: '<b>Publishing...</b>',
  388.                                             css: {
  389.                                                 border: 'none',
  390.                                                 backgroundColor: 'transparent',
  391.                                                 color: 'white'
  392.                                             }
  393.                                         });
  394.                                     }
  395.                                 },
  396.                                 onremotetrack: function(track, mid, on) {
  397.                                     // The publisher stream is sendonly, we don't expect anything here
  398.                                 },
  399.                                 oncleanup: function() {
  400.                                     Janus.log(" ::: Got a cleanup notification: we are unpublished now :::");
  401.                                     mystream = null;
  402.                                     delete feedStreams[myid];
  403.                                     $('#videolocal').html('<button id="publish" class="btn btn-primary">Publish</button>');
  404.                                     $('#publish').click(function() { publishOwnFeed(true); });
  405.                                     $("#videolocal").parent().parent().unblock();
  406.                                     $('#bitrate').parent().parent().addClass('hide');
  407.                                     $('#bitrate a').unbind('click');
  408.                                     localTracks = {};
  409.                                     localVideos = 0;
  410.                                 }
  411.                             });
  412.                     },
  413.                     error: function(error) {
  414.                         Janus.error(error);
  415.                         bootbox.alert(error, function() {
  416.                             window.location.reload();
  417.                         });
  418.                     },
  419.                     destroyed: function() {
  420.                         window.location.reload();
  421.                     }
  422.                 });
  423.         });
  424.     }});
  425. });
  426.  
  427. function checkEnter(field, event) {
  428.     var theCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  429.     if(theCode == 13) {
  430.         registerUsername();
  431.         return false;
  432.     } else {
  433.         return true;
  434.     }
  435. }
  436.  
  437. function registerUsername() {
  438.     if($('#username').length === 0) {
  439.         // Create fields to register
  440.         $('#register').click(registerUsername);
  441.         $('#username').focus();
  442.     } else {
  443.         // Try a registration
  444.         $('#username').attr('disabled', true);
  445.         $('#register').attr('disabled', true).unbind('click');
  446.         var username = $('#username').val();
  447.         if(username === "") {
  448.             $('#you')
  449.                 .removeClass().addClass('label label-warning')
  450.                 .html("Insert your display name (e.g., pippo)");
  451.             $('#username').removeAttr('disabled');
  452.             $('#register').removeAttr('disabled').click(registerUsername);
  453.             return;
  454.         }
  455.         if(/[^a-zA-Z0-9]/.test(username)) {
  456.             $('#you')
  457.                 .removeClass().addClass('label label-warning')
  458.                 .html('Input is not alphanumeric');
  459.             $('#username').removeAttr('disabled').val("");
  460.             $('#register').removeAttr('disabled').click(registerUsername);
  461.             return;
  462.         }
  463.         var register = {
  464.             request: "join",
  465.             room: myroom,
  466.             ptype: "publisher",
  467.             display: username
  468.         };
  469.         myusername = username;
  470.         sfutest.send({ message: register });
  471.     }
  472. }
  473.  
  474. function publishOwnFeed(useAudio) {
  475.     // Publish our stream
  476.     $('#publish').attr('disabled', true).unbind('click');
  477.     sfutest.createOffer(
  478.         {
  479.             // Add data:true here if you want to publish datachannels as well
  480.             media: { audioRecv: false, videoRecv: false, audioSend: useAudio, videoSend: true },    // Publishers are sendonly
  481.             // If you want to test simulcasting (Chrome and Firefox only), then
  482.             // pass a ?simulcast=true when opening this demo page: it will turn
  483.             // the following 'simulcast' property to pass to janus.js to true
  484.             simulcast: doSimulcast,
  485.             simulcast2: doSimulcast2,
  486.             success: function(jsep) {
  487.                 Janus.debug("Got publisher SDP!");
  488.                 Janus.debug(jsep);
  489.                 var publish = { request: "configure", audio: useAudio, video: true };
  490.                 // You can force a specific codec to use when publishing by using the
  491.                 // audiocodec and videocodec properties, for instance:
  492.                 //      publish["audiocodec"] = "opus"
  493.                 // to force Opus as the audio codec to use, or:
  494.                 //      publish["videocodec"] = "vp9"
  495.                 // to force VP9 as the videocodec to use. In both case, though, forcing
  496.                 // a codec will only work if: (1) the codec is actually in the SDP (and
  497.                 // so the browser supports it), and (2) the codec is in the list of
  498.                 // allowed codecs in a room. With respect to the point (2) above,
  499.                 // refer to the text in janus.plugin.videoroom.cfg for more details
  500.                 if(acodec)
  501.                     publish["audiocodec"] = acodec;
  502.                 if(vcodec)
  503.                     publish["videocodec"] = vcodec;
  504.                 sfutest.send({ message: publish, jsep: jsep });
  505.             },
  506.             error: function(error) {
  507.                 Janus.error("WebRTC error:", error);
  508.                 if (useAudio) {
  509.                      publishOwnFeed(false);
  510.                 } else {
  511.                     bootbox.alert("WebRTC error... " + error.message);
  512.                     $('#publish').removeAttr('disabled').click(function() { publishOwnFeed(true); });
  513.                 }
  514.             }
  515.         });
  516. }
  517.  
  518. function toggleMute() {
  519.     var muted = sfutest.isAudioMuted();
  520.     Janus.log((muted ? "Unmuting" : "Muting") + " local stream...");
  521.     if(muted)
  522.         sfutest.unmuteAudio();
  523.     else
  524.         sfutest.muteAudio();
  525.     muted = sfutest.isAudioMuted();
  526.     $('#mute').html(muted ? "Unmute" : "Mute");
  527. }
  528.  
  529. function unpublishOwnFeed() {
  530.     // Unpublish our stream
  531.     $('#unpublish').attr('disabled', true).unbind('click');
  532.     var unpublish = { request: "unpublish" };
  533.     sfutest.send({ message: unpublish });
  534. }
  535.  
  536. var creatingFeed = false;
  537. function subscribeTo(sources) {
  538.     // New feeds are available, do we need create a new plugin handle first?
  539.     if(remoteFeed) {
  540.         // Prepare the streams to subscribe to, as an array: we have the list of
  541.         // streams the feeds are publishing, so we can choose what to pick or skip
  542.         var subscription = [];
  543.         for(var s in sources) {
  544.             var streams = sources[s];
  545.             for(var i in streams) {
  546.                 var stream = streams[i];
  547.                 // If the publisher is VP8/VP9 and this is an older Safari, let's avoid video
  548.                 if(stream.type === "video" && Janus.webRTCAdapter.browserDetails.browser === "safari" &&
  549.                         (stream.codec === "vp9" || (stream.codec === "vp8" && !Janus.safariVp8))) {
  550.                     toastr.warning("Publisher is using " + stream.codec.toUpperCase +
  551.                         ", but Safari doesn't support it: disabling video stream #" + stream.mindex);
  552.                     continue;
  553.                 }
  554.                 if(stream.disabled) {
  555.                     Janus.log("Disabled stream:", stream);
  556.                     // TODO Skipping for now, we should unsubscribe
  557.                     continue;
  558.                 }
  559.                 if(subscriptions[stream.id] && subscriptions[stream.id][stream.mid]) {
  560.                     Janus.log("Already subscribed to stream, skipping:", stream);
  561.                     continue;
  562.                 }
  563.                 // Find an empty slot in the UI for each new source
  564.                 if(!feedStreams[stream.id].slot) {
  565.                     var slot;
  566.                     for(var i=1;i<6;i++) {
  567.                         if(!feeds[i]) {
  568.                             slot = i;
  569.                             feeds[slot] = stream.id;
  570.                             feedStreams[stream.id].slot = slot;
  571.                             feedStreams[stream.id].remoteVideos = 0;
  572.                             $('#remote' + slot).removeClass('hide').html(stream.display).show();
  573.                             break;
  574.                         }
  575.                     }
  576.                 }
  577.                 subscription.push({
  578.                     feed: stream.id,    // This is mandatory
  579.                     mid: stream.mid     // This is optional (all streams, if missing)
  580.                 });
  581.                 if(!subscriptions[stream.id])
  582.                     subscriptions[stream.id] = {};
  583.                 subscriptions[stream.id][stream.mid] = true;
  584.             }
  585.         }
  586.         if(subscription.length === 0) {
  587.             // Nothing to do
  588.             return;
  589.         }
  590.         remoteFeed.send({ message: {
  591.             request: "subscribe",
  592.             streams: subscription
  593.         }});
  594.         return;
  595.     }
  596.     // We don't have a handle yet, but we may be creating one already
  597.     if(creatingFeed) {
  598.         // Still working on the handle
  599.         setTimeout(function() {
  600.             subscribeTo(sources);
  601.         }, 500);
  602.         return;
  603.     }
  604.     creatingFeed = true;
  605.     janus.attach(
  606.         {
  607.             plugin: "janus.plugin.videoroom",
  608.             opaqueId: opaqueId,
  609.             success: function(pluginHandle) {
  610.                 remoteFeed = pluginHandle;
  611.                 remoteTracks = {};
  612.                 Janus.log("Plugin attached! (" + remoteFeed.getPlugin() + ", id=" + remoteFeed.getId() + ")");
  613.                 Janus.log("  -- This is a multistream subscriber");
  614.                 // Prepare the streams to subscribe to, as an array: we have the list of
  615.                 // streams the feed is publishing, so we can choose what to pick or skip
  616.                 var subscription = [];
  617.                 for(var s in sources) {
  618.                     var streams = sources[s];
  619.                     for(var i in streams) {
  620.                         var stream = streams[i];
  621.                         // If the publisher is VP8/VP9 and this is an older Safari, let's avoid video
  622.                         if(stream.type === "video" && Janus.webRTCAdapter.browserDetails.browser === "safari" &&
  623.                                 (stream.codec === "vp9" || (stream.codec === "vp8" && !Janus.safariVp8))) {
  624.                             toastr.warning("Publisher is using " + stream.codec.toUpperCase +
  625.                                 ", but Safari doesn't support it: disabling video stream #" + stream.mindex);
  626.                             continue;
  627.                         }
  628.                         if(stream.disabled) {
  629.                             Janus.log("Disabled stream:", stream);
  630.                             // TODO Skipping for now, we should unsubscribe
  631.                             continue;
  632.                         }
  633.                         Janus.log("Subscribed to " + stream.id + "/" + stream.mid + "?", subscriptions);
  634.                         if(subscriptions[stream.id] && subscriptions[stream.id][stream.mid]) {
  635.                             Janus.log("Already subscribed to stream, skipping:", stream);
  636.                             continue;
  637.                         }
  638.                         // Find an empty slot in the UI for each new source
  639.                         if(!feedStreams[stream.id].slot) {
  640.                             var slot;
  641.                             for(var i=1;i<6;i++) {
  642.                                 if(!feeds[i]) {
  643.                                     slot = i;
  644.                                     feeds[slot] = stream.id;
  645.                                     feedStreams[stream.id].slot = slot;
  646.                                     feedStreams[stream.id].remoteVideos = 0;
  647.                                     $('#remote' + slot).removeClass('hide').html(stream.display).show();
  648.                                     break;
  649.                                 }
  650.                             }
  651.                         }
  652.                         subscription.push({
  653.                             feed: stream.id,    // This is mandatory
  654.                             mid: stream.mid     // This is optional (all streams, if missing)
  655.                         });
  656.                         if(!subscriptions[stream.id])
  657.                             subscriptions[stream.id] = {};
  658.                         subscriptions[stream.id][stream.mid] = true;
  659.                     }
  660.                 }
  661.                 // We wait for the plugin to send us an offer
  662.                 var subscribe = {
  663.                     request: "join",
  664.                     room: myroom,
  665.                     ptype: "subscriber",
  666.                     streams: subscription,
  667.                     private_id: mypvtid
  668.                 };
  669.                 remoteFeed.send({ message: subscribe });
  670.             },
  671.             error: function(error) {
  672.                 Janus.error("  -- Error attaching plugin...", error);
  673.                 bootbox.alert("Error attaching plugin... " + error);
  674.             },
  675.             iceState: function(state) {
  676.                 Janus.log("ICE state (remote feed) changed to " + state);
  677.             },
  678.             webrtcState: function(on) {
  679.                 Janus.log("Janus says this WebRTC PeerConnection (remote feed) is " + (on ? "up" : "down") + " now");
  680.             },
  681.             slowLink: function(uplink, lost, mid) {
  682.                 Janus.warn("Janus reports problems " + (uplink ? "sending" : "receiving") +
  683.                     " packets on mid " + mid + " (" + lost + " lost packets)");
  684.             },
  685.             onmessage: function(msg, jsep) {
  686.                 Janus.debug(" ::: Got a message (subscriber) :::", msg);
  687.                 var event = msg["videoroom"];
  688.                 Janus.debug("Event: " + event);
  689.                 if(msg["error"]) {
  690.                     bootbox.alert(msg["error"]);
  691.                 } else if(event) {
  692.                     if(event === "attached") {
  693.                         creatingFeed = false;
  694.                         Janus.log("Successfully attached to feed in room " + msg["room"]);
  695.                     } else if(event === "event") {
  696.                         // Check if we got an event on a simulcast-related event from this publisher
  697.                         var mid = msg["mid"];
  698.                         var substream = msg["substream"];
  699.                         var temporal = msg["temporal"];
  700.                         if((substream !== null && substream !== undefined) || (temporal !== null && temporal !== undefined)) {
  701.                             // Check which this feed this refers to
  702.                             var sub = subStreams[mid];
  703.                             var feed = feedStreams[sub.feed_id];
  704.                             var slot = slots[mid];
  705.                             if(!simulcastStarted[slot]) {
  706.                                 simulcastStarted[slot] = true;
  707.                                 // Add some new buttons
  708.                                 addSimulcastButtons(slot, true);
  709.                             }
  710.                             // We just received notice that there's been a switch, update the buttons
  711.                             updateSimulcastButtons(slot, substream, temporal);
  712.                         }
  713.                     } else {
  714.                         // What has just happened?
  715.                     }
  716.                 }
  717.                 if(msg["streams"]) {
  718.                     // Update map of subscriptions by mid
  719.                     for(var i in msg["streams"]) {
  720.                         var mid = msg["streams"][i]["mid"];
  721.                         subStreams[mid] = msg["streams"][i];
  722.                         var feed = feedStreams[msg["streams"][i]["feed_id"]];
  723.                         if(feed && feed.slot) {
  724.                             slots[mid] = feed.slot;
  725.                             mids[feed.slot] = mid;
  726.                         }
  727.                     }
  728.                 }
  729.                 if(jsep) {
  730.                     Janus.debug("Handling SDP as well...", jsep);
  731.                     // Answer and attach
  732.                     remoteFeed.createAnswer(
  733.                         {
  734.                             jsep: jsep,
  735.                             // Add data:true here if you want to subscribe to datachannels as well
  736.                             // (obviously only works if the publisher offered them in the first place)
  737.                             media: { audioSend: false, videoSend: false },  // We want recvonly audio/video
  738.                             success: function(jsep) {
  739.                                 Janus.debug("Got SDP!");
  740.                                 Janus.debug(jsep);
  741.                                 var body = { request: "start", room: myroom };
  742.                                 remoteFeed.send({ message: body, jsep: jsep });
  743.                             },
  744.                             error: function(error) {
  745.                                 Janus.error("WebRTC error:", error);
  746.                                 bootbox.alert("WebRTC error... " + error.message);
  747.                             }
  748.                         });
  749.                 }
  750.             },
  751.             onlocaltrack: function(track, on) {
  752.                 // The subscriber stream is recvonly, we don't expect anything here
  753.             },
  754.             onremotetrack: function(track, mid, on) {
  755.                 Janus.debug("Remote track (mid=" + mid + ") " + (on ? "added" : "removed") + ":", track);
  756.                 // Which publisher are we getting on this mid?
  757.                 var sub = subStreams[mid];
  758.                 var feed = feedStreams[sub.feed_id];
  759.                 Janus.debug(" >> This track is coming from feed " + sub.feed_id + ":", feed);
  760.                 var slot = slots[mid];
  761.                 if(feed && !slot) {
  762.                     slot = feed.slot;
  763.                     slots[mid] = feed.slot;
  764.                     mids[feed.slot] = mid;
  765.                 }
  766.                 Janus.debug(" >> mid " + mid + " is in slot " + slot);
  767.                 if(!on) {
  768.                     // Track removed, get rid of the stream and the rendering
  769.                     var stream = remoteTracks[mid];
  770.                     if(stream) {
  771.                         try {
  772.                             var tracks = stream.getTracks();
  773.                             for(var i in tracks) {
  774.                                 var mst = tracks[i];
  775.                                 if(mst)
  776.                                     mst.stop();
  777.                             }
  778.                         } catch(e) {}
  779.                     }
  780.                     $('#remotevideo' + slot + '-' + mid).remove();
  781.                     if(track.kind === "video" && feed) {
  782.                         feed.remoteVideos--;
  783.                         if(feed.remoteVideos === 0) {
  784.                             // No video, at least for now: show a placeholder
  785.                             if($('#videoremote' + slot + ' .no-video-container').length === 0) {
  786.                                 $('#videoremote' + slot).append(
  787.                                     '<div class="no-video-container">' +
  788.                                         '<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
  789.                                         '<span class="no-video-text">No remote video available</span>' +
  790.                                     '</div>');
  791.                             }
  792.                         }
  793.                     }
  794.                     delete remoteTracks[mid];
  795.                     delete slots[mid];
  796.                     delete mids[slot];
  797.                     return;
  798.                 }
  799.                 // If we're here, a new track was added
  800.                 if(feed.spinner) {
  801.                     feed.spinner.stop();
  802.                     feed.spinner = null;
  803.                 }
  804.                 if($('#remotevideo' + slot + '-' + mid).length > 0)
  805.                     return;
  806.                 if(track.kind === "audio") {
  807.                     // New audio track: create a stream out of it, and use a hidden <audio> element
  808.                     stream = new MediaStream();
  809.                     stream.addTrack(track.clone());
  810.                     remoteTracks[mid] = stream;
  811.                     Janus.log("Created remote audio stream:", stream);
  812.                     $('#videoremote' + slot).append('<audio class="hide" id="remotevideo' + slot + '-' + mid + '" autoplay playsinline/>');
  813.                     Janus.attachMediaStream($('#remotevideo' + slot + '-' + mid).get(0), stream);
  814.                     if(feed.remoteVideos === 0) {
  815.                         // No video, at least for now: show a placeholder
  816.                         if($('#videoremote' + slot + ' .no-video-container').length === 0) {
  817.                             $('#videoremote' + slot).append(
  818.                                 '<div class="no-video-container">' +
  819.                                     '<i class="fa fa-video-camera fa-5 no-video-icon"></i>' +
  820.                                     '<span class="no-video-text">No remote video available</span>' +
  821.                                 '</div>');
  822.                         }
  823.                     }
  824.                 } else {
  825.                     // New video track: create a stream out of it
  826.                     feed.remoteVideos++;
  827.                     $('#videoremote' + slot + ' .no-video-container').remove();
  828.                     stream = new MediaStream();
  829.                     stream.addTrack(track.clone());
  830.                     remoteTracks[mid] = stream;
  831.                     Janus.log("Created remote video stream:", stream);
  832.                     $('#videoremote' + slot).append('<video class="rounded centered" id="remotevideo' + slot + '-' + mid + '" width=100% autoplay playsinline/>');
  833.                     $('#videoremote' + slot).append(
  834.                         '<span class="label label-primary hide" id="curres'+slot+'" style="position: absolute; bottom: 0px; left: 0px; margin: 15px;"></span>' +
  835.                         '<span class="label label-info hide" id="curbitrate'+slot+'" style="position: absolute; bottom: 0px; right: 0px; margin: 15px;"></span>');
  836.                     Janus.attachMediaStream($('#remotevideo' + slot + '-' + mid).get(0), stream);
  837.                     // Note: we'll need this for additional videos too
  838.                     if(!bitrateTimer[slot]) {
  839.                         $('#curbitrate' + slot).removeClass('hide').show();
  840.                         bitrateTimer[slot] = setInterval(function() {
  841.                             if(!$("#videoremote" + slot + ' video').get(0))
  842.                                 return;
  843.                             // Display updated bitrate, if supported
  844.                             var bitrate = remoteFeed.getBitrate(mid);
  845.                             $('#curbitrate' + slot).text(bitrate);
  846.                             // Check if the resolution changed too
  847.                             var width = $("#videoremote" + slot + ' video').get(0).videoWidth;
  848.                             var height = $("#videoremote" + slot + ' video').get(0).videoHeight;
  849.                             if(width > 0 && height > 0)
  850.                                 $('#curres' + slot).removeClass('hide').text(width+'x'+height).show();
  851.                         }, 1000);
  852.                     }
  853.                 }
  854.             },
  855.             oncleanup: function() {
  856.                 Janus.log(" ::: Got a cleanup notification (remote feed) :::");
  857.                 for(var i=1;i<6;i++) {
  858.                     $('#remotevideo'+i).remove();
  859.                     $('#waitingvideo'+i).remove();
  860.                     $('#novideo'+i).remove();
  861.                     $('#curbitrate'+i).remove();
  862.                     $('#curres'+i).remove();
  863.                     if(bitrateTimer[i])
  864.                         clearInterval(bitrateTimer[i]);
  865.                     bitrateTimer[i] = null;
  866.                     feedStreams[i].simulcastStarted = false;
  867.                     feedStreams[i].remoteVideos = 0;
  868.                     $('#simulcast'+i).remove();
  869.                 }
  870.                 remoteTracks = {};
  871.             }
  872.         });
  873. }
  874.  
  875. function unsubscribeFrom(id) {
  876.     // Unsubscribe from this publisher
  877.     var feed = feedStreams[id];
  878.     if(!feed)
  879.         return;
  880.     Janus.debug("Feed " + id + " (" + feed.display + ") has left the room, detaching");
  881.     if(bitrateTimer[feed.slot])
  882.         clearInterval(bitrateTimer[feed.slot]);
  883.     bitrateTimer[feed.slot] = null;
  884.     $('#remote' + feed.slot).empty().hide();
  885.     $('#videoremote' + feed.slot).empty();
  886.     delete simulcastStarted[feed.slot];
  887.     $('#simulcast' + feed.slot).remove();
  888.     delete feeds[feed.slot];
  889.     feeds.slot = 0;
  890.     delete feedStreams[id];
  891.     // Send an unsubscribe request
  892.     var unsubscribe = {
  893.         request: "unsubscribe",
  894.         streams: [{ feed: id }]
  895.     };
  896.     if(remoteFeed != null)
  897.         remoteFeed.send({ message: unsubscribe });
  898.     delete subscriptions[id];
  899. }
  900.  
  901. // Helper to parse query string
  902. function getQueryStringValue(name) {
  903.     name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
  904.     var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
  905.         results = regex.exec(location.search);
  906.     return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  907. }
  908.  
  909. // Helpers to create Simulcast-related UI, if enabled
  910. function addSimulcastButtons(feed, temporal) {
  911.     var index = feed;
  912.     $('#remote'+index).parent().append(
  913.         '<div id="simulcast'+index+'" class="btn-group-vertical btn-group-vertical-xs pull-right">' +
  914.         '   <div class"row">' +
  915.         '       <div class="btn-group btn-group-xs" style="width: 100%">' +
  916.         '           <button id="sl'+index+'-2" type="button" class="btn btn-primary" data-toggle="tooltip" title="Switch to higher quality" style="width: 33%">SL 2</button>' +
  917.         '           <button id="sl'+index+'-1" type="button" class="btn btn-primary" data-toggle="tooltip" title="Switch to normal quality" style="width: 33%">SL 1</button>' +
  918.         '           <button id="sl'+index+'-0" type="button" class="btn btn-primary" data-toggle="tooltip" title="Switch to lower quality" style="width: 34%">SL 0</button>' +
  919.         '       </div>' +
  920.         '   </div>' +
  921.         '   <div class"row">' +
  922.         '       <div class="btn-group btn-group-xs hide" style="width: 100%">' +
  923.         '           <button id="tl'+index+'-2" type="button" class="btn btn-primary" data-toggle="tooltip" title="Cap to temporal layer 2" style="width: 34%">TL 2</button>' +
  924.         '           <button id="tl'+index+'-1" type="button" class="btn btn-primary" data-toggle="tooltip" title="Cap to temporal layer 1" style="width: 33%">TL 1</button>' +
  925.         '           <button id="tl'+index+'-0" type="button" class="btn btn-primary" data-toggle="tooltip" title="Cap to temporal layer 0" style="width: 33%">TL 0</button>' +
  926.         '       </div>' +
  927.         '   </div>' +
  928.         '</div>'
  929.     );
  930.     // Enable the simulcast selection buttons
  931.     $('#sl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary')
  932.         .unbind('click').click(function() {
  933.             var index = $(this).attr('id').split('sl')[1].split('-')[0];
  934.             toastr.info("Switching simulcast substream (mid=" + mids[index] + "), wait for it... (lower quality)", null, {timeOut: 2000});
  935.             if(!$('#sl' + index + '-2').hasClass('btn-success'))
  936.                 $('#sl' + index + '-2').removeClass('btn-primary btn-info').addClass('btn-primary');
  937.             if(!$('#sl' + index + '-1').hasClass('btn-success'))
  938.                 $('#sl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
  939.             $('#sl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
  940.             remoteFeed.send({ message: { request: "configure", mid: mids[index], substream: 0 }});
  941.         });
  942.     $('#sl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary')
  943.         .unbind('click').click(function() {
  944.             var index = $(this).attr('id').split('sl')[1].split('-')[0];
  945.             toastr.info("Switching simulcast substream (mid=" + mids[index] + "), wait for it... (normal quality)", null, {timeOut: 2000});
  946.             if(!$('#sl' + index + '-2').hasClass('btn-success'))
  947.                 $('#sl' + index + '-2').removeClass('btn-primary btn-info').addClass('btn-primary');
  948.             $('#sl' + index + '-1').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
  949.             if(!$('#sl' + index + '-0').hasClass('btn-success'))
  950.                 $('#sl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
  951.             remoteFeed.send({ message: { request: "configure", mid: mids[index], substream: 1 }});
  952.         });
  953.     $('#sl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary')
  954.         .unbind('click').click(function() {
  955.             var index = $(this).attr('id').split('sl')[1].split('-')[0];
  956.             toastr.info("Switching simulcast substream (mid=" + mids[index] + "), wait for it... (higher quality)", null, {timeOut: 2000});
  957.             $('#sl' + index + '-2').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
  958.             if(!$('#sl' + index + '-1').hasClass('btn-success'))
  959.                 $('#sl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
  960.             if(!$('#sl' + index + '-0').hasClass('btn-success'))
  961.                 $('#sl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
  962.             remoteFeed.send({ message: { request: "configure", mid: mids[index], substream: 2 }});
  963.         });
  964.     if(!temporal)   // No temporal layer support
  965.         return;
  966.     $('#tl' + index + '-0').parent().removeClass('hide');
  967.     $('#tl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary')
  968.         .unbind('click').click(function() {
  969.             var index = $(this).attr('id').split('tl')[1].split('-')[0];
  970.             toastr.info("Capping simulcast temporal layer (mid=" + mids[index] + "), wait for it... (lowest FPS)", null, {timeOut: 2000});
  971.             if(!$('#tl' + index + '-2').hasClass('btn-success'))
  972.                 $('#tl' + index + '-2').removeClass('btn-primary btn-info').addClass('btn-primary');
  973.             if(!$('#tl' + index + '-1').hasClass('btn-success'))
  974.                 $('#tl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
  975.             $('#tl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
  976.             remoteFeed.send({ message: { request: "configure", mid: mids[index], temporal: 0 }});
  977.         });
  978.     $('#tl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary')
  979.         .unbind('click').click(function() {
  980.             var index = $(this).attr('id').split('tl')[1].split('-')[0];
  981.             toastr.info("Capping simulcast temporal layer (mid=" + mids[index] + "), wait for it... (medium FPS)", null, {timeOut: 2000});
  982.             if(!$('#tl' + index + '-2').hasClass('btn-success'))
  983.                 $('#tl' + index + '-2').removeClass('btn-primary btn-info').addClass('btn-primary');
  984.             $('#tl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-info');
  985.             if(!$('#tl' + index + '-0').hasClass('btn-success'))
  986.                 $('#tl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
  987.             remoteFeed.send({ message: { request: "configure", mid: mids[index], temporal: 1 }});
  988.         });
  989.     $('#tl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary')
  990.         .unbind('click').click(function() {
  991.             var index = $(this).attr('id').split('tl')[1].split('-')[0];
  992.             toastr.info("Capping simulcast temporal layer (mid=" + mids[index] + "), wait for it... (highest FPS)", null, {timeOut: 2000});
  993.             $('#tl' + index + '-2').removeClass('btn-primary btn-info btn-success').addClass('btn-info');
  994.             if(!$('#tl' + index + '-1').hasClass('btn-success'))
  995.                 $('#tl' + index + '-1').removeClass('btn-primary btn-info').addClass('btn-primary');
  996.             if(!$('#tl' + index + '-0').hasClass('btn-success'))
  997.                 $('#tl' + index + '-0').removeClass('btn-primary btn-info').addClass('btn-primary');
  998.             remoteFeed.send({ message: { request: "configure", mid: mids[index], temporal: 2 }});
  999.         });
  1000. }
  1001.  
  1002. function updateSimulcastButtons(feed, substream, temporal) {
  1003.     // Check the substream
  1004.     var index = feed;
  1005.     if(substream === 0) {
  1006.         toastr.success("Switched simulcast substream! (lower quality)", null, {timeOut: 2000});
  1007.         $('#sl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary');
  1008.         $('#sl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
  1009.         $('#sl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
  1010.     } else if(substream === 1) {
  1011.         toastr.success("Switched simulcast substream! (normal quality)", null, {timeOut: 2000});
  1012.         $('#sl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary');
  1013.         $('#sl' + index + '-1').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
  1014.         $('#sl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
  1015.     } else if(substream === 2) {
  1016.         toastr.success("Switched simulcast substream! (higher quality)", null, {timeOut: 2000});
  1017.         $('#sl' + index + '-2').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
  1018.         $('#sl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
  1019.         $('#sl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
  1020.     }
  1021.     // Check the temporal layer
  1022.     if(temporal === 0) {
  1023.         toastr.success("Capped simulcast temporal layer! (lowest FPS)", null, {timeOut: 2000});
  1024.         $('#tl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary');
  1025.         $('#tl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
  1026.         $('#tl' + index + '-0').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
  1027.     } else if(temporal === 1) {
  1028.         toastr.success("Capped simulcast temporal layer! (medium FPS)", null, {timeOut: 2000});
  1029.         $('#tl' + index + '-2').removeClass('btn-primary btn-success').addClass('btn-primary');
  1030.         $('#tl' + index + '-1').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
  1031.         $('#tl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
  1032.     } else if(temporal === 2) {
  1033.         toastr.success("Capped simulcast temporal layer! (highest FPS)", null, {timeOut: 2000});
  1034.         $('#tl' + index + '-2').removeClass('btn-primary btn-info btn-success').addClass('btn-success');
  1035.         $('#tl' + index + '-1').removeClass('btn-primary btn-success').addClass('btn-primary');
  1036.         $('#tl' + index + '-0').removeClass('btn-primary btn-success').addClass('btn-primary');
  1037.     }
  1038. }
  1039.  
Add Comment
Please, Sign In to add comment