Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var stream = "https://wind-bow.glitch.me/twitch-api/streams/";
- var streamList = ['freecodecamp', 'ESL_SC2', 'test_channel'];
- var count = 0;
- //build stream URL and populate HTML elements with stream data.
- function statusCheck(count) {
- stream = "https://wind-bow.glitch.me/twitch-api/streams/";
- stream = stream + streamList[count];
- //check to see if stream is live
- $.getJSON(stream, function(data) {
- var status;
- if(data.stream === null) {
- populate(status);
- } else if(data.stream !== null){
- status = 'live';
- populate(status);
- }
- });
- }
- //pass the status to this function to populate the HTML
- function populate(status) {
- //if the channel is not live, retrieve the data from the users URL then populate
- if(status === undefined) {
- stream = "https://wind-bow.glitch.me/twitch-api/users/";
- stream = stream + streamList[count];
- $.getJSON(stream, function(data) {
- var streamName = data.display_name;
- var div = document.createElement('div');
- var mainDiv = document.getElementById('main');
- div.setAttribute('class', 'stream');
- div.innerHTML = "<img class='logo' src = '" + data.logo + "'>" + streamName + ' Offline';
- mainDiv.appendChild(div);
- });
- count++
- console.log(status);
- //if the channel is live, populate the HTML with the stream URL
- } else {
- stream = "https://wind-bow.glitch.me/twitch-api/streams/";
- stream = stream + streamList[count];
- $.getJSON(stream, function(data) {
- status = data.stream.stream_type;
- var streamName = data.display_name;
- var div = document.createElement('div');
- var mainDiv = document.getElementById('main');
- div.setAttribute('class', 'stream');
- div.innerHTML = "<img class='logo' src = '" + data.logo + "'>" + streamName;
- mainDiv.appendChild(div);
- });
- count++
- }
- }
- //increment count to proceed to next stream
- statusCheck();
- statusCheck();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement