{"action":"created","comment":{"url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/comments/123246745","pull_request_review_id":45427334,"id":123246745,"diff_hunk":"@@ -31,4 +32,203 @@ Site = {\n   },\n };\n \n-Site.init();\n\\ No newline at end of file\n+Site.StreamChecker = {\n+  statusUrl: 'https://public.radio.co/stations/s0b5e9c02c/status',\n+  statusCheckInterval: 5000,\n+  streamData: null,\n+  init: function() {\n+    var _this = this;\n+\n+    _this.startChecker();\n+  },\n+\n+  startChecker: function() {\n+    var _this = this;\n+\n+\n+    _this.checkStreamStatus();\n+\n+    // Start checker on an interval\n+    setInterval(function() {\n+      _this.checkStreamStatus();\n+    }, _this.statusCheckInterval);\n+  },\n+\n+  // Check the stream status thru ajax and change the player accordingly\n+  checkStreamStatus: function() {\n+    var _this = this;\n+\n+    // Make the ajax request\n+    $.getJSON(_this.statusUrl, function(data) {\n+\n+      // Save data in a cache var, just in case\n+      _this.streamData = data.status;\n+\n+      // Check if the stream is offline\n+      if(data.status == 'offline') {\n+\n+        // Trigger the event\n+        _this.triggerEvent('streamoffline', data);\n+\n+      } else if(data.status === 'online')  {  // else  (stream is online)\n+\n+        // Trigger the event\n+        _this.triggerEvent('streamonline', data);\n+      }\n+    });\n+\n+  },\n+\n+  triggerEvent: function(eventName, detail) {\n+    var _this =  this;\n+\n+    console.log('event triggered: ', eventName);\n+\n+    var customEvent = new CustomEvent(eventName, {\n+      detail: detail,\n+    });\n+\n+    document.dispatchEvent(customEvent);\n+  },\n+\n+};\n+\n+Site.Player = {\n+  neverPlayed: true,\n+  fadeTime:  2000,\n+  streamUrl: 'http://streaming.radio.co/s0b5e9c02c/listen',\n+  init: function() {\n+    var _this = this;\n+\n+    // Player DOM elements\n+    _this.playerContainer =  document.getElementById('player-container');\n+    _this.playerElement =  document.getElementById('player');\n+    _this.playerSrc =  document.getElementById('player-src');\n+    _this.playButton =  document.getElementById('play-btn');\n+    _this.pauseButton =  document.getElementById('pause-btn');\n+    _this.streamStatusText =  document.getElementById('stream-status');\n+    _this.nowPlayingText =  document.getElementById('now-playing');\n+\n+    // Bind event handlers\n+    _this.handleOnlineStream = _this.handleOnlineStream.bind(_this);\n+    _this.handleCanPlay = _this.handleCanPlay.bind(_this);\n+    _this.handleOfflineStream = _this.handleOfflineStream.bind(_this);\n+\n+    // Subscribe to stream events\n+    document.addEventListener('streamonline', _this.handleOnlineStream);\n+    document.addEventListener('streamoffline', _this.handleOfflineStream);\n+\n+    // Subscribe to clic on player controls\n+    _this.playButton.addEventListener('click', _this.play.bind(_this));\n+    _this.pauseButton.addEventListener('click', _this.pause.bind(_this));\n+\n+  },\n+\n+  handleOnlineStream: function(event) {\n+    var _this = this;\n+\n+    var data = event.detail;\n+\n+    // Add class `online` to the player container\n+    _this.playerContainer.classList.add('online');\n+\n+    // Check if player src is empty\n+    if (_this.playerSrc.src === '' || _this.playerElement.paused) {\n+      // Add src\n+      _this.playerSrc.src =  _this.streamUrl;\n+\n+      // Load src\n+      _this.playerElement.load();\n+    }\n+\n+    // Update marquee status\n+    _this.streamStatusText.innerHTML = 'Ahora: ';\n+\n+    // Update Now playing\n+    _this.nowPlayingText.innerHTML = data.current_track.title;\n+\n+    // If the player has never started playing\n+    if (_this.neverPlayed) {\n+      // We subscribe to the `canplay` event from the player\n+      _this.playerElement.addEventListener('canplay', _this.handleCanPlay);\n+    }\n+  },\n+\n+  handleCanPlay: function(event) {\n+    var _this = this;\n+\n+    // Play the audio element\n+    _this.play();\n+\n+    // Remove listener cuz it's only needed once\n+    event.target.removeEventListener(event.type, _this.handleCanPlay);\n+\n+  },\n+\n+  handleOfflineStream: function() {\n+    var _this = this;\n+\n+    // Remove `online` class from the player container\n+    _this.playerContainer.classList.remove('online');\n+\n+    // Update marquee status\n+    _this.streamStatusText.innerHTML = 'Siguiente: ';\n+\n+    // Update the marquee text\n+    _this.nowPlayingText.innerHTML = 'the upcoming show that has to be requested thru ajax';\n+\n+    // Pause the audio element\n+    _this.pause();\n+  },\n+\n+  play: function() {\n+    var _this = this;\n+\n+    if( _this.playerElement.networkState !== 3) {\n+\n+      // Reset volume\n+      _this.playerElement.volume = 0;\n+\n+      // Play audio element\n+      _this.playerElement.play();\n+\n+      // Add `playing` class to player container\n+      _this.playerContainer.classList.add('playing');\n+\n+\n+      _this.neverPlayed = false;\n+\n+      // Calculate the volume increment\n+      var volumeIncrement = 1 / (_this.fadeTime / 50);\n+\n+      // Fade in the volume\n+      var fadeInterval = setInterval( function() {\n+        var newVolume = _this.playerElement.volume + volumeIncrement;","path":"src/js/main.js","position":187,"original_position":187,"commit_id":"a6ea0ad1b1131edcc7aa024fc6cb2d90fe6c2e6a","original_commit_id":"a6ea0ad1b1131edcc7aa024fc6cb2d90fe6c2e6a","user":{"login":"varffs","id":845186,"avatar_url":"https://avatars1.githubusercontent.com/u/845186?v=3","gravatar_id":"","url":"https://api.github.com/users/varffs","html_url":"https://github.com/varffs","followers_url":"https://api.github.com/users/varffs/followers","following_url":"https://api.github.com/users/varffs/following{/other_user}","gists_url":"https://api.github.com/users/varffs/gists{/gist_id}","starred_url":"https://api.github.com/users/varffs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/varffs/subscriptions","organizations_url":"https://api.github.com/users/varffs/orgs","repos_url":"https://api.github.com/users/varffs/repos","events_url":"https://api.github.com/users/varffs/events{/privacy}","received_events_url":"https://api.github.com/users/varffs/received_events","type":"User","site_admin":false},"body":"Is `volumeIncrement` in the right scope here? Should you save it on the object on init and reference from there?","created_at":"2017-06-21T13:25:06Z","updated_at":"2017-06-21T13:29:06Z","html_url":"https://github.com/interglobalvision/ondamundial-net/pull/5#discussion_r123246745","pull_request_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/comments/123246745"},"html":{"href":"https://github.com/interglobalvision/ondamundial-net/pull/5#discussion_r123246745"},"pull_request":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5","id":126680317,"html_url":"https://github.com/interglobalvision/ondamundial-net/pull/5","diff_url":"https://github.com/interglobalvision/ondamundial-net/pull/5.diff","patch_url":"https://github.com/interglobalvision/ondamundial-net/pull/5.patch","issue_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/5","number":5,"state":"open","locked":false,"title":"Scaffold player","user":{"login":"mixcas","id":1994425,"avatar_url":"https://avatars3.githubusercontent.com/u/1994425?v=3","gravatar_id":"","url":"https://api.github.com/users/mixcas","html_url":"https://github.com/mixcas","followers_url":"https://api.github.com/users/mixcas/followers","following_url":"https://api.github.com/users/mixcas/following{/other_user}","gists_url":"https://api.github.com/users/mixcas/gists{/gist_id}","starred_url":"https://api.github.com/users/mixcas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mixcas/subscriptions","organizations_url":"https://api.github.com/users/mixcas/orgs","repos_url":"https://api.github.com/users/mixcas/repos","events_url":"https://api.github.com/users/mixcas/events{/privacy}","received_events_url":"https://api.github.com/users/mixcas/received_events","type":"User","site_admin":false},"body":"This adds the basic scaffolding for the player and functionality.\r\n\r\nMainly two parts in the script. \r\n\r\n1. A stream status checker, that checks every x seconds the status of the stream and triggers events `offlinestream` and `onlinestream` accordingly.\r\n2. The player which is in charge of:\r\n  - adding the src to the audio element\r\n  - loading the src at the right times\r\n  - handle the stream status change\r\n  - displaying the controls and the link for the schedule accordingly to the combinations of the `online` and `playing` classes (state)\r\n\r\nThe player fades in the audio when `play()` is called.","created_at":"2017-06-21T05:08:17Z","updated_at":"2017-06-21T13:29:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5/commits","review_comments_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5/comments","review_comment_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/comments{/number}","comments_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/5/comments","statuses_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/statuses/a6ea0ad1b1131edcc7aa024fc6cb2d90fe6c2e6a","head":{"label":"interglobalvision:scaffold-player","ref":"scaffold-player","sha":"a6ea0ad1b1131edcc7aa024fc6cb2d90fe6c2e6a","user":{"login":"interglobalvision","id":6844994,"avatar_url":"https://avatars2.githubusercontent.com/u/6844994?v=3","gravatar_id":"","url":"https://api.github.com/users/interglobalvision","html_url":"https://github.com/interglobalvision","followers_url":"https://api.github.com/users/interglobalvision/followers","following_url":"https://api.github.com/users/interglobalvision/following{/other_user}","gists_url":"https://api.github.com/users/interglobalvision/gists{/gist_id}","starred_url":"https://api.github.com/users/interglobalvision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interglobalvision/subscriptions","organizations_url":"https://api.github.com/users/interglobalvision/orgs","repos_url":"https://api.github.com/users/interglobalvision/repos","events_url":"https://api.github.com/users/interglobalvision/events{/privacy}","received_events_url":"https://api.github.com/users/interglobalvision/received_events","type":"Organization","site_admin":false},"repo":{"id":94918788,"name":"ondamundial-net","full_name":"interglobalvision/ondamundial-net","owner":{"login":"interglobalvision","id":6844994,"avatar_url":"https://avatars2.githubusercontent.com/u/6844994?v=3","gravatar_id":"","url":"https://api.github.com/users/interglobalvision","html_url":"https://github.com/interglobalvision","followers_url":"https://api.github.com/users/interglobalvision/followers","following_url":"https://api.github.com/users/interglobalvision/following{/other_user}","gists_url":"https://api.github.com/users/interglobalvision/gists{/gist_id}","starred_url":"https://api.github.com/users/interglobalvision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interglobalvision/subscriptions","organizations_url":"https://api.github.com/users/interglobalvision/orgs","repos_url":"https://api.github.com/users/interglobalvision/repos","events_url":"https://api.github.com/users/interglobalvision/events{/privacy}","received_events_url":"https://api.github.com/users/interglobalvision/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/interglobalvision/ondamundial-net","description":null,"fork":false,"url":"https://api.github.com/repos/interglobalvision/ondamundial-net","forks_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/forks","keys_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/teams","hooks_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/hooks","issue_events_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/events{/number}","events_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/events","assignees_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/assignees{/user}","branches_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/branches{/branch}","tags_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/tags","blobs_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/refs{/sha}","trees_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/statuses/{sha}","languages_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/languages","stargazers_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/stargazers","contributors_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/contributors","subscribers_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/subscribers","subscription_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/subscription","commits_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/commits{/sha}","git_commits_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/commits{/sha}","comments_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/comments{/number}","issue_comment_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/comments{/number}","contents_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/contents/{+path}","compare_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/merges","archive_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/downloads","issues_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues{/number}","pulls_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls{/number}","milestones_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/milestones{/number}","notifications_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/labels{/name}","releases_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/releases{/id}","deployments_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/deployments","created_at":"2017-06-20T17:42:11Z","updated_at":"2017-06-20T17:45:48Z","pushed_at":"2017-06-21T05:08:17Z","git_url":"git://github.com/interglobalvision/ondamundial-net.git","ssh_url":"git@github.com:interglobalvision/ondamundial-net.git","clone_url":"https://github.com/interglobalvision/ondamundial-net.git","svn_url":"https://github.com/interglobalvision/ondamundial-net","homepage":null,"size":1067,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"interglobalvision:master","ref":"master","sha":"22ace9ede9964c887d34e7d24965140b39d43d80","user":{"login":"interglobalvision","id":6844994,"avatar_url":"https://avatars2.githubusercontent.com/u/6844994?v=3","gravatar_id":"","url":"https://api.github.com/users/interglobalvision","html_url":"https://github.com/interglobalvision","followers_url":"https://api.github.com/users/interglobalvision/followers","following_url":"https://api.github.com/users/interglobalvision/following{/other_user}","gists_url":"https://api.github.com/users/interglobalvision/gists{/gist_id}","starred_url":"https://api.github.com/users/interglobalvision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interglobalvision/subscriptions","organizations_url":"https://api.github.com/users/interglobalvision/orgs","repos_url":"https://api.github.com/users/interglobalvision/repos","events_url":"https://api.github.com/users/interglobalvision/events{/privacy}","received_events_url":"https://api.github.com/users/interglobalvision/received_events","type":"Organization","site_admin":false},"repo":{"id":94918788,"name":"ondamundial-net","full_name":"interglobalvision/ondamundial-net","owner":{"login":"interglobalvision","id":6844994,"avatar_url":"https://avatars2.githubusercontent.com/u/6844994?v=3","gravatar_id":"","url":"https://api.github.com/users/interglobalvision","html_url":"https://github.com/interglobalvision","followers_url":"https://api.github.com/users/interglobalvision/followers","following_url":"https://api.github.com/users/interglobalvision/following{/other_user}","gists_url":"https://api.github.com/users/interglobalvision/gists{/gist_id}","starred_url":"https://api.github.com/users/interglobalvision/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/interglobalvision/subscriptions","organizations_url":"https://api.github.com/users/interglobalvision/orgs","repos_url":"https://api.github.com/users/interglobalvision/repos","events_url":"https://api.github.com/users/interglobalvision/events{/privacy}","received_events_url":"https://api.github.com/users/interglobalvision/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/interglobalvision/ondamundial-net","description":null,"fork":false,"url":"https://api.github.com/repos/interglobalvision/ondamundial-net","forks_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/forks","keys_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/keys{/key_id}","collaborators_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/teams","hooks_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/hooks","issue_events_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/events{/number}","events_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/events","assignees_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/assignees{/user}","branches_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/branches{/branch}","tags_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/tags","blobs_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/refs{/sha}","trees_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/trees{/sha}","statuses_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/statuses/{sha}","languages_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/languages","stargazers_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/stargazers","contributors_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/contributors","subscribers_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/subscribers","subscription_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/subscription","commits_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/commits{/sha}","git_commits_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/git/commits{/sha}","comments_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/comments{/number}","issue_comment_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/comments{/number}","contents_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/contents/{+path}","compare_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/compare/{base}...{head}","merges_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/merges","archive_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/downloads","issues_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues{/number}","pulls_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls{/number}","milestones_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/milestones{/number}","notifications_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/labels{/name}","releases_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/releases{/id}","deployments_url":"https://api.github.com/repos/interglobalvision/ondamundial-net/deployments","created_at":"2017-06-20T17:42:11Z","updated_at":"2017-06-20T17:45:48Z","pushed_at":"2017-06-21T05:08:17Z","git_url":"git://github.com/interglobalvision/ondamundial-net.git","ssh_url":"git@github.com:interglobalvision/ondamundial-net.git","clone_url":"https://github.com/interglobalvision/ondamundial-net.git","svn_url":"https://github.com/interglobalvision/ondamundial-net","homepage":null,"size":1067,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5"},"html":{"href":"https://github.com/interglobalvision/ondamundial-net/pull/5"},"issue":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/5"},"comments":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/interglobalvision/ondamundial-net/statuses/a6ea0ad1b1131edcc7aa024fc6cb2d90fe6c2e6a"}}}}
{"actor":{"display_login":"varffs"}}