Created
January 14, 2017 12:34
-
-
Save escottalexander/202e8691b64f04a3779a5508a03e637a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Commonly streaming list | |
var streamers = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"]; | |
//Now to begin with the coding | |
//This function tests to see if a stream is active | |
//This is where the bug is, I think... | |
var pullJSON; | |
function viewAllStreams() { | |
for (i = 0; i < streamers.length; i++) { | |
pullJSON = function(streamer) { | |
$(document).ready(function() { | |
//var labelActivity = isActiveTest(streamName); | |
$.getJSON('https://wind-bow.gomix.me/twitch-api/channels/' + streamer + '?callback=?', function(data) { | |
function isActiveTest(streamer) { | |
$.getJSON('https://wind-bow.gomix.me/twitch-api/streams/' + streamer + '?callback=?', function(json) { | |
console.log(json); | |
var isActive = (json.stream !== null); | |
console.log(isActive); | |
//console reads false so... | |
if (isActive === true) { | |
var url = data.url; | |
var name = data.display_name; | |
var logo = data.logo; | |
var status = data.status; | |
var labelActivity = "<span class='label label-success'>Active</span>"; | |
$("body").append('<div class="well col-xs-4 col-xs-offset-4"><p><img class ="img-responsive img-rounded" style="float: left; margin: 0px 15px 15px 0px;" width="25%" src=' + logo + '><a href=' + url + '>' + name + " " + labelActivity + '</p></a><p>' + status + '</p></div>'); | |
} else { | |
var url = data.url; | |
var name = data.display_name; | |
var logo = data.logo; | |
var status = data.status; | |
var labelActivty = "<span class='label label-default'>Inactive</span>"; | |
$("body").append('<div class="well col-xs-4 col-xs-offset-4"><p><img class ="img-responsive img-rounded" style="float: left; margin: 0px 15px 15px 0px;" width="25%" src=' + logo + '><a href=' + url + '>' + name + " " + labelActivity + '</p></a><p>' + status + '</p></div>'); | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
} | |
}; | |
//This is the function that every stream's data will run through | |
viewAllStreams() | |
//one way could be.. nest those 2 getJSON.. and inside the inner callback append data to ur html | |
//$.getJSON( '...', function(data1){ | |
//$.getJSON( '...', function(data2){ | |
//add data to ur html mixing data1 + data2 values | |
// }) | |
//}) | |
//or using promises |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment