0

I'm trying to make a badge that says whether or not my Livestream channel is online or offline. I found some javascript that can do this for Twitch channels:

(function() {

  var user_name, twitch_widget;

  user_name = "nerdist";
  twitch_widget = $("#twitch-widget");

  twitch_widget.attr("href","http://twitch.tv/" + user_name + "/embed");

  $.getJSON('https://api.twitch.tv/kraken/streams/' + user_name + '?client_id=' + '&callback=?', function(data) {   
      if (data.stream) {
          twitch_widget.html("<span class='online'></span><strong> nerdist</strong></br><span class='live'>Online! Playing: " + data.stream.game + "</span>");
      } else {
          twitch_widget.html("<span class='offline'></span><strong> nerdist</strong></br><span class='notlive'>Offline</span>");
      }  
  });

})();

And I used that to make a functioning badge as seen here: http://codepen.io/EagleJow/pen/GpmGQe

That works great, but I would also like to do this with a Livestream channel and I'm not sure how to go about doing that. I can tell by looking at the javascript that it's able to identify if a channel is online or not by looking at a JSON file on the twitch.tv server.

I'm hoping someone can help me out by tweaking the code to work with a Livestream channel. I've already found out (from here: http://original.livestream.com/userguide/index.php?title=Main_Page&title=Channel_API#Channel_Live_Status) that you can find out a Livestream channel's live status through this xml page: xChannel Namex.api.channel.livestream.com/2.0/livestatus.xml

^Replace Channel Name with the name of the livestream channel.

If the channel is online it will say <ls:isLive>true</ls:isLive> and if it's offline it'll say <ls:isLive>false</ls:isLive>

My best guess would be something like this:

(function() {

  var livestream_widget;

  livestream_widget = $("#livestream-widget");

  livestream_widget.attr("href","[channel URL]");

  $.getXML('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.xml', function(data) {  
      if (data.stream) {
          livestream_widget.html("<span class='online'></span><strong> daytradingradio</strong></br><span class='live'>Online!</span>");
      } else {
          livestream_widget.html("<span class='offline'></span><strong> daytradingradio</strong></br><span class='notlive'>Offline</span>");
      }  
  });

})();

But I'm not sure what to put instead of "function(data)" and "if (data.stream)". Something like "if (isLive=true)" maybe?

Any help would be appreciated.

Eagle Jow
  • 37
  • 1
  • 8
  • Looking at this page: http://original.livestream.com/userguide/index.php?title=Main_Page&title=Channel_API#Channel_Live_Status I can see that it's possible to use JSON instead of XML. Not sure if that would work better or not. Also this thread seems very similar, but I'm still not sure how to implement it into the code I'm using: http://stackoverflow.com/questions/7020357/can-someone-help-me-with-using-livestreams-api-to-make-a-cross-domain-xml-reque – Eagle Jow Oct 07 '15 at 00:32

1 Answers1

0
(function() {

  var livestream_widget;

  livestream_widget = $("#livestream-widget");

  livestream_widget.attr("href","[channelurl]");
  $.getJSON('http://xdaytradingradiox.api.channel.livestream.com/2.0/livestatus.json?callback=?', function(data) {  

      if (data.channel.isLive === true) {

          livestream_widget.html("<span class='online'></span><strong> daytradingradio</strong></br><span class='live'>Online!</span>");
      } else {
          livestream_widget.html("<span class='offline'></span><strong> daytradingradio</strong></br><span class='notlive'>Offline</span>");
      }  
  });

})();
Eagle Jow
  • 37
  • 1
  • 8