{"action":"created","comment":{"url":"https://api.github.com/repos/sharktank/ft-frontend/pulls/comments/35731426","id":35731426,"diff_hunk":"@@ -0,0 +1,144 @@\n+var clientID = \"451c998c1c9daf78a255d0900d35000f\"\n+var SC = require(\"./SCSDK\")\n+var Widget = require(\"./playerAPI\")\n+\n+var randomStr = function(){\n+  return btoa((Math.random()+\"\").substr(2));\n+}\n+\n+// A function to make streams for us\n+var StreamMaker = function(){\n+  var registeredListeners = [];\n+  return {\n+    // Have an observe function, so\n+    // people who are interested can\n+    // get notified when there is an update\n+    observe: function(callback){\n+      registeredListeners.push(callback)\n+    },\n+\n+    // Add a value to this stream\n+    // Once added, will notify all\n+    // interested parties\n+    update: function(value){\n+      registeredListeners.forEach(function(cb){\n+        cb(value);\n+      })\n+    }\n+  }\n+}\n+\n+var randomStr = function(){\n+  return btoa((Math.random()+\"\").substr(2));\n+}\n+\n+var playerToMeta = function(player){\n+  var data = player.getVideoData();\n+  var meta = {};\n+  meta.name = data.title;\n+  meta.artist = data.author;\n+  meta.album = player.getVideoUrl();\n+  meta.duration = player.getDuration();\n+  return meta;\n+}\n+\n+var SongControllerMaker = function(songURL, resolve, reject){\n+  var updateStream = StreamMaker();\n+\n+  var playerContainer = document.createElement(\"iframe\");\n+  var domID = randomStr();\n+  playerContainer.id = domID;\n+  playerContainer.src = \"https://w.soundcloud.com/player/?url=\"+songURL;\n+  document.body.appendChild(playerContainer);\n+  playerContainer.style.display = \"none\";\n+  var player = SC.Widget(domID);\n+\n+  // update while song is playing\n+  var timeUpdates = setInterval(function(){\n+    player.isPaused(function(isPaused){\n+      player.getPosition(function(positionInMillis){\n+        if (!isPaused){\n+          updateStream.update({\n+            type:\"SongPlaying\",\n+            time:positionInMillis/1000\n+          });\n+        }\n+      })\n+    })\n+  }, 1e3);\n+\n+  player.bind(SC.Widget.Events.PLAY_PROGRESS, function(playProgress){\n+    updateStream.update({\n+      type:\"SongPlaying\",\n+      time:playProgress.currentPosition/1000\n+    });\n+  })\n+  resolve({\n+    play: function(){\n+      player.play();\n+      updateStream.update({type:\"SongPlayed\"});\n+    },\n+    pause: function(){\n+      player.pause();\n+      updateStream.update({type:\"SongPaused\"});\n+    },\n+    jumpTo: function(timeInSeconds){\n+      player.seekTo(timeInSeconds*1000);\n+      updateStream.update({\n+        type:\"SongPlaying\",\n+        time:timeInSeconds\n+      });\n+    },\n+    getId: function(){\n+      return \"soundcloud:\"+songURL;\n+    },\n+    getMeta: function(){\n+      // TODO\n+      return playerToMeta(player);\n+    },\n+    getPlayer: function(){\n+      return player;\n+    },\n+    onPlayUpdate: function(cb){\n+      updateStream.observe(cb);\n+    },\n+    cleanUp: function(){\n+      document.body.removeChild(audio);\n+      clearInterval(timeUpdates);\n+    },\n+  });\n+}\n+\n+var MusicSource = {\n+  playSong: function(id){\n+    return new Promise(function(resolve, reject){\n+      var songURL = id.substr(id.indexOf(\":\")+1)","path":"plugins/soundcloud/src/index.js","position":115,"original_position":115,"commit_id":"7f4e2e4dbe103d1c0c21a87b765395354d070ab9","original_commit_id":"7f4e2e4dbe103d1c0c21a87b765395354d070ab9","user":{"login":"akenn","id":405000,"avatar_url":"https://avatars.githubusercontent.com/u/405000?v=3","gravatar_id":"","url":"https://api.github.com/users/akenn","html_url":"https://github.com/akenn","followers_url":"https://api.github.com/users/akenn/followers","following_url":"https://api.github.com/users/akenn/following{/other_user}","gists_url":"https://api.github.com/users/akenn/gists{/gist_id}","starred_url":"https://api.github.com/users/akenn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akenn/subscriptions","organizations_url":"https://api.github.com/users/akenn/orgs","repos_url":"https://api.github.com/users/akenn/repos","events_url":"https://api.github.com/users/akenn/events{/privacy}","received_events_url":"https://api.github.com/users/akenn/received_events","type":"User","site_admin":false},"body":"This is a little difficult to read. Add a constant for the plugin identifier (`soundcloud` in this case) and do something similar to:\r\n\r\n```js\r\nvar pluginID = 'soundcloud';\r\nvar songURL = id.replace(pluginID + ':', '');\r\n```\r\n\r\nI don't like the `:` being concatenated at the end though. Something similar to above would be nice because it's more apparent that you are grabbing everything after the plugin id and delimiter.","created_at":"2015-07-29T06:40:00Z","updated_at":"2015-07-29T06:40:00Z","html_url":"https://github.com/sharktank/ft-frontend/pull/2#discussion_r35731426","pull_request_url":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/sharktank/ft-frontend/pulls/comments/35731426"},"html":{"href":"https://github.com/sharktank/ft-frontend/pull/2#discussion_r35731426"},"pull_request":{"href":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2","id":40977262,"html_url":"https://github.com/sharktank/ft-frontend/pull/2","diff_url":"https://github.com/sharktank/ft-frontend/pull/2.diff","patch_url":"https://github.com/sharktank/ft-frontend/pull/2.patch","issue_url":"https://api.github.com/repos/sharktank/ft-frontend/issues/2","number":2,"state":"open","locked":false,"title":"Add Soundcloud Plugin","user":{"login":"MarcoPolo","id":594035,"avatar_url":"https://avatars.githubusercontent.com/u/594035?v=3","gravatar_id":"","url":"https://api.github.com/users/MarcoPolo","html_url":"https://github.com/MarcoPolo","followers_url":"https://api.github.com/users/MarcoPolo/followers","following_url":"https://api.github.com/users/MarcoPolo/following{/other_user}","gists_url":"https://api.github.com/users/MarcoPolo/gists{/gist_id}","starred_url":"https://api.github.com/users/MarcoPolo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MarcoPolo/subscriptions","organizations_url":"https://api.github.com/users/MarcoPolo/orgs","repos_url":"https://api.github.com/users/MarcoPolo/repos","events_url":"https://api.github.com/users/MarcoPolo/events{/privacy}","received_events_url":"https://api.github.com/users/MarcoPolo/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-28T05:47:39Z","updated_at":"2015-07-29T06:40:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f976170ff547350642cfe5b6d7f0406e2e295768","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2/commits","review_comments_url":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2/comments","review_comment_url":"https://api.github.com/repos/sharktank/ft-frontend/pulls/comments{/number}","comments_url":"https://api.github.com/repos/sharktank/ft-frontend/issues/2/comments","statuses_url":"https://api.github.com/repos/sharktank/ft-frontend/statuses/7f4e2e4dbe103d1c0c21a87b765395354d070ab9","head":{"label":"sharktank:soundcloud","ref":"soundcloud","sha":"7f4e2e4dbe103d1c0c21a87b765395354d070ab9","user":{"login":"sharktank","id":848334,"avatar_url":"https://avatars.githubusercontent.com/u/848334?v=3","gravatar_id":"","url":"https://api.github.com/users/sharktank","html_url":"https://github.com/sharktank","followers_url":"https://api.github.com/users/sharktank/followers","following_url":"https://api.github.com/users/sharktank/following{/other_user}","gists_url":"https://api.github.com/users/sharktank/gists{/gist_id}","starred_url":"https://api.github.com/users/sharktank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharktank/subscriptions","organizations_url":"https://api.github.com/users/sharktank/orgs","repos_url":"https://api.github.com/users/sharktank/repos","events_url":"https://api.github.com/users/sharktank/events{/privacy}","received_events_url":"https://api.github.com/users/sharktank/received_events","type":"Organization","site_admin":false},"repo":{"id":39666202,"name":"ft-frontend","full_name":"sharktank/ft-frontend","owner":{"login":"sharktank","id":848334,"avatar_url":"https://avatars.githubusercontent.com/u/848334?v=3","gravatar_id":"","url":"https://api.github.com/users/sharktank","html_url":"https://github.com/sharktank","followers_url":"https://api.github.com/users/sharktank/followers","following_url":"https://api.github.com/users/sharktank/following{/other_user}","gists_url":"https://api.github.com/users/sharktank/gists{/gist_id}","starred_url":"https://api.github.com/users/sharktank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharktank/subscriptions","organizations_url":"https://api.github.com/users/sharktank/orgs","repos_url":"https://api.github.com/users/sharktank/repos","events_url":"https://api.github.com/users/sharktank/events{/privacy}","received_events_url":"https://api.github.com/users/sharktank/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sharktank/ft-frontend","description":"","fork":false,"url":"https://api.github.com/repos/sharktank/ft-frontend","forks_url":"https://api.github.com/repos/sharktank/ft-frontend/forks","keys_url":"https://api.github.com/repos/sharktank/ft-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sharktank/ft-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sharktank/ft-frontend/teams","hooks_url":"https://api.github.com/repos/sharktank/ft-frontend/hooks","issue_events_url":"https://api.github.com/repos/sharktank/ft-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/sharktank/ft-frontend/events","assignees_url":"https://api.github.com/repos/sharktank/ft-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/sharktank/ft-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/sharktank/ft-frontend/tags","blobs_url":"https://api.github.com/repos/sharktank/ft-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sharktank/ft-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sharktank/ft-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/sharktank/ft-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sharktank/ft-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/sharktank/ft-frontend/languages","stargazers_url":"https://api.github.com/repos/sharktank/ft-frontend/stargazers","contributors_url":"https://api.github.com/repos/sharktank/ft-frontend/contributors","subscribers_url":"https://api.github.com/repos/sharktank/ft-frontend/subscribers","subscription_url":"https://api.github.com/repos/sharktank/ft-frontend/subscription","commits_url":"https://api.github.com/repos/sharktank/ft-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/sharktank/ft-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/sharktank/ft-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/sharktank/ft-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/sharktank/ft-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/sharktank/ft-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sharktank/ft-frontend/merges","archive_url":"https://api.github.com/repos/sharktank/ft-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sharktank/ft-frontend/downloads","issues_url":"https://api.github.com/repos/sharktank/ft-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/sharktank/ft-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/sharktank/ft-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/sharktank/ft-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sharktank/ft-frontend/labels{/name}","releases_url":"https://api.github.com/repos/sharktank/ft-frontend/releases{/id}","created_at":"2015-07-25T00:46:07Z","updated_at":"2015-07-25T01:47:34Z","pushed_at":"2015-07-29T05:28:35Z","git_url":"git://github.com/sharktank/ft-frontend.git","ssh_url":"git@github.com:sharktank/ft-frontend.git","clone_url":"https://github.com/sharktank/ft-frontend.git","svn_url":"https://github.com/sharktank/ft-frontend","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"sharktank:master","ref":"master","sha":"02ed3578ee3c62c9f99ac284c80629cb34212e6b","user":{"login":"sharktank","id":848334,"avatar_url":"https://avatars.githubusercontent.com/u/848334?v=3","gravatar_id":"","url":"https://api.github.com/users/sharktank","html_url":"https://github.com/sharktank","followers_url":"https://api.github.com/users/sharktank/followers","following_url":"https://api.github.com/users/sharktank/following{/other_user}","gists_url":"https://api.github.com/users/sharktank/gists{/gist_id}","starred_url":"https://api.github.com/users/sharktank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharktank/subscriptions","organizations_url":"https://api.github.com/users/sharktank/orgs","repos_url":"https://api.github.com/users/sharktank/repos","events_url":"https://api.github.com/users/sharktank/events{/privacy}","received_events_url":"https://api.github.com/users/sharktank/received_events","type":"Organization","site_admin":false},"repo":{"id":39666202,"name":"ft-frontend","full_name":"sharktank/ft-frontend","owner":{"login":"sharktank","id":848334,"avatar_url":"https://avatars.githubusercontent.com/u/848334?v=3","gravatar_id":"","url":"https://api.github.com/users/sharktank","html_url":"https://github.com/sharktank","followers_url":"https://api.github.com/users/sharktank/followers","following_url":"https://api.github.com/users/sharktank/following{/other_user}","gists_url":"https://api.github.com/users/sharktank/gists{/gist_id}","starred_url":"https://api.github.com/users/sharktank/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharktank/subscriptions","organizations_url":"https://api.github.com/users/sharktank/orgs","repos_url":"https://api.github.com/users/sharktank/repos","events_url":"https://api.github.com/users/sharktank/events{/privacy}","received_events_url":"https://api.github.com/users/sharktank/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/sharktank/ft-frontend","description":"","fork":false,"url":"https://api.github.com/repos/sharktank/ft-frontend","forks_url":"https://api.github.com/repos/sharktank/ft-frontend/forks","keys_url":"https://api.github.com/repos/sharktank/ft-frontend/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sharktank/ft-frontend/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sharktank/ft-frontend/teams","hooks_url":"https://api.github.com/repos/sharktank/ft-frontend/hooks","issue_events_url":"https://api.github.com/repos/sharktank/ft-frontend/issues/events{/number}","events_url":"https://api.github.com/repos/sharktank/ft-frontend/events","assignees_url":"https://api.github.com/repos/sharktank/ft-frontend/assignees{/user}","branches_url":"https://api.github.com/repos/sharktank/ft-frontend/branches{/branch}","tags_url":"https://api.github.com/repos/sharktank/ft-frontend/tags","blobs_url":"https://api.github.com/repos/sharktank/ft-frontend/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sharktank/ft-frontend/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sharktank/ft-frontend/git/refs{/sha}","trees_url":"https://api.github.com/repos/sharktank/ft-frontend/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sharktank/ft-frontend/statuses/{sha}","languages_url":"https://api.github.com/repos/sharktank/ft-frontend/languages","stargazers_url":"https://api.github.com/repos/sharktank/ft-frontend/stargazers","contributors_url":"https://api.github.com/repos/sharktank/ft-frontend/contributors","subscribers_url":"https://api.github.com/repos/sharktank/ft-frontend/subscribers","subscription_url":"https://api.github.com/repos/sharktank/ft-frontend/subscription","commits_url":"https://api.github.com/repos/sharktank/ft-frontend/commits{/sha}","git_commits_url":"https://api.github.com/repos/sharktank/ft-frontend/git/commits{/sha}","comments_url":"https://api.github.com/repos/sharktank/ft-frontend/comments{/number}","issue_comment_url":"https://api.github.com/repos/sharktank/ft-frontend/issues/comments{/number}","contents_url":"https://api.github.com/repos/sharktank/ft-frontend/contents/{+path}","compare_url":"https://api.github.com/repos/sharktank/ft-frontend/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sharktank/ft-frontend/merges","archive_url":"https://api.github.com/repos/sharktank/ft-frontend/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sharktank/ft-frontend/downloads","issues_url":"https://api.github.com/repos/sharktank/ft-frontend/issues{/number}","pulls_url":"https://api.github.com/repos/sharktank/ft-frontend/pulls{/number}","milestones_url":"https://api.github.com/repos/sharktank/ft-frontend/milestones{/number}","notifications_url":"https://api.github.com/repos/sharktank/ft-frontend/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sharktank/ft-frontend/labels{/name}","releases_url":"https://api.github.com/repos/sharktank/ft-frontend/releases{/id}","created_at":"2015-07-25T00:46:07Z","updated_at":"2015-07-25T01:47:34Z","pushed_at":"2015-07-29T05:28:35Z","git_url":"git://github.com/sharktank/ft-frontend.git","ssh_url":"git@github.com:sharktank/ft-frontend.git","clone_url":"https://github.com/sharktank/ft-frontend.git","svn_url":"https://github.com/sharktank/ft-frontend","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"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/sharktank/ft-frontend/pulls/2"},"html":{"href":"https://github.com/sharktank/ft-frontend/pull/2"},"issue":{"href":"https://api.github.com/repos/sharktank/ft-frontend/issues/2"},"comments":{"href":"https://api.github.com/repos/sharktank/ft-frontend/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/sharktank/ft-frontend/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/sharktank/ft-frontend/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/sharktank/ft-frontend/statuses/7f4e2e4dbe103d1c0c21a87b765395354d070ab9"}}}}