app.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. History = new Mongo.Collection("history");
  2. if (Meteor.isClient) {
  3. Template.register.events({
  4. "submit form": function(e){
  5. e.preventDefault();
  6. var username = e.target.registerUsername.value;
  7. var email = e.target.registerEmail.value;
  8. var password = e.target.registerPassword.value;
  9. Accounts.createUser({
  10. username: username,
  11. email: email,
  12. password: password
  13. });
  14. },
  15. "click #facebook-login": function(){
  16. Meteor.loginWithFacebook()
  17. },
  18. "click #github-login": function(){
  19. Meteor.loginWithGithub()
  20. },
  21. "click #login": function(){
  22. $("#register-view").hide();
  23. $("#login-view").show();
  24. }
  25. });
  26. Template.login.events({
  27. "submit form": function(e){
  28. e.preventDefault();
  29. var username = e.target.loginUsername.value;
  30. var password = e.target.loginPassword.value;
  31. Meteor.loginWithPassword(username, password);
  32. Accounts.onLoginFailure(function(){
  33. $("input").css("background-color","indianred").addClass("animated shake");
  34. $("input").on("click",function(){
  35. $("input").css({
  36. "background-color": "transparent",
  37. "width": "250px"
  38. });
  39. })
  40. });
  41. },
  42. "click #facebook-login": function(){
  43. Meteor.loginWithFacebook()
  44. },
  45. "click #github-login": function(){
  46. Meteor.loginWithGithub()
  47. },
  48. "click #register": function(){
  49. $("#login-view").hide();
  50. $("#register-view").show();
  51. }
  52. });
  53. Template.dashboard.events({
  54. "click .logout": function(e){
  55. e.preventDefault();
  56. Meteor.logout();
  57. },
  58. "click .button-tunein": function(){
  59. SC.stream("/tracks/172055891/", function(sound){
  60. console.log(sound);
  61. sound._player._volume = 0.3;
  62. sound.play();
  63. });
  64. },
  65. "click #play": function(){
  66. $("#play").hide();
  67. SC.stream("/tracks/172055891/", function(sound){
  68. sound._player._volume = 0.3;
  69. sound.play();
  70. $("#stop").on("click", function(){
  71. $("#stop").hide();
  72. $("#play").show();
  73. sound._player.pause();
  74. })
  75. });
  76. $("#stop").show();
  77. }
  78. });
  79. Template.Room.helpers({
  80. type: function() {
  81. var parts = location.href.split('/');
  82. var id = parts.pop();
  83. return id;
  84. },
  85. duration: function() {
  86. return Session.get("duration");
  87. }
  88. });
  89. <<<<<<< HEAD
  90. var currentSong = undefined;
  91. var _sound = undefined;
  92. var size = 0;
  93. function getTimeElapsed() {
  94. if (currentSong !== undefined) {
  95. return Date.now() - currentSong.started;
  96. }
  97. return 0;
  98. }
  99. function startSong() {
  100. if (currentSong !== undefined) {
  101. if (_sound !== undefined)_sound.stop();
  102. SC.stream("/tracks/" + currentSong.song.id + "/", function(sound){
  103. _sound = sound;
  104. sound._player._volume = 0.3;
  105. //sound.play();
  106. setTimeout(function() { // HACK, otherwise seek doesn't work.
  107. sound._player.seek(getTimeElapsed());
  108. }, 500);
  109. });
  110. }
  111. }
  112. Template.Room.onCreated(function () {
  113. /*var instance = this;
  114. HTTP.get('/api/room/edm', function (err, data) {
  115. instance.data = data;
  116. console.log(data);
  117. // PLAY SONG AND SUCH
  118. });*/
  119. /*console.log("Created!");
  120. Meteor.call("getDuration", function(err, res) {
  121. Session.set("duration", res);
  122. console.log(res);
  123. });
  124. Meteor.call("getStart", function(err, res) {
  125. Session.set("start", res);
  126. console.log(res);
  127. });
  128. Meteor.call("getSong", function(err, res) {
  129. Session.set("song", res);
  130. console.log(res);
  131. SC.stream("/tracks/" + res + "/", function(sound){
  132. console.log(sound);
  133. sound._player._volume = 0.3;
  134. sound.play();
  135. setTimeout(function() { // HACK, otherwise seek doesn't work.
  136. sound._player.seek(Date.now() - Session.get("start"));
  137. console.log((Date.now() - Session.get("start")) + "--");
  138. }, 500);
  139. =======
  140. Template.Room.onCreated(function () {
  141. var currentSong = undefined;
  142. var _sound = undefined;
  143. var size = 0;
  144. function getTimeElapsed() {
  145. if (currentSong !== undefined) {
  146. return Date.now() - currentSong.started;
  147. }
  148. return 0;
  149. }
  150. function startSong() {
  151. if (currentSong !== undefined) {
  152. if (_sound !== undefined)_sound.stop();
  153. SC.stream("/tracks/" + currentSong.song.id + "/", function(sound){
  154. _sound = sound;
  155. sound._player._volume = 0.3;
  156. sound.play();
  157. setTimeout(function() { // HACK, otherwise seek doesn't work.
  158. sound._player.seek(getTimeElapsed());
  159. }, 500);
  160. });
  161. }
  162. }
  163. Meteor.subscribe("history");
  164. Meteor.setInterval(function() {
  165. var data = undefined;
  166. var dataCursor = History.find({type: "edm"});
  167. dataCursor.map(function(doc) {
  168. if (data === undefined) {
  169. data = doc;
  170. }
  171. >>>>>>> ae1154a1dccc1c6b9069136b26cbeedc256eee2d
  172. });
  173. console.log(data);
  174. if (data.history.length > size) {
  175. currentSong = data.history[data.history.length-1];
  176. size = data.history.length;
  177. startSong();
  178. }
  179. }, 1000);
  180. });
  181. <<<<<<< HEAD
  182. Meteor.subscribe("history");
  183. Meteor.setInterval(function() {
  184. var data = History.findOne();
  185. if (data.history.length > size) {
  186. currentSong = data.history[data.history.length-1];
  187. size = data.history.length;
  188. startSong();
  189. }
  190. }, 1000);
  191. //console.log(History, "History");
  192. }
  193. if (Meteor.isServer) {
  194. =======
  195. }
  196. if (Meteor.isServer) {
  197. >>>>>>> ae1154a1dccc1c6b9069136b26cbeedc256eee2d
  198. var startedAt = Date.now();
  199. var songs = [{id: 172055891, duration: 20}, {id: 194153620, duration: 60}];
  200. var currentSong = 0;
  201. addToHistory(songs[currentSong], startedAt);
  202. function addToHistory(song, startedAt) {
  203. History.update({type: "edm"}, {$push: {history: {song: song, started: startedAt}}});
  204. }
  205. function skipSong() {
  206. if (currentSong < (songs.length - 1)) {
  207. currentSong++;
  208. } else currentSong = 0;
  209. songTimer();
  210. addToHistory(songs[currentSong], startedAt);
  211. }
  212. function songTimer() {
  213. startedAt = Date.now();
  214. Meteor.setTimeout(function() {
  215. skipSong();
  216. }, songs[currentSong].duration * 1000);
  217. }
  218. ServiceConfiguration.configurations.remove({
  219. service: "facebook"
  220. });
  221. ServiceConfiguration.configurations.insert({
  222. service: "facebook",
  223. appId: "1496014310695890",
  224. secret: "9a039f254a08a1488c08bb0737dbd2a6"
  225. });
  226. ServiceConfiguration.configurations.remove({
  227. service: "github"
  228. });
  229. ServiceConfiguration.configurations.insert({
  230. service: "github",
  231. clientId: "dcecd720f47c0e4001f7",
  232. secret: "375939d001ef1a0ca67c11dbf8fb9aeaa551e01b"
  233. });
  234. songTimer();
  235. Meteor.publish("history", function() {
  236. return History.find({type: "edm"})
  237. });
  238. }
  239. Router.route("/", {
  240. template: "Home"
  241. });
  242. Router.route("/:type", {
  243. template: "Room"
  244. });