client.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911
  1. Meteor.startup(function() {
  2. reCAPTCHA.config({
  3. publickey: '6LcVxg0TAAAAAE18vBiH00UAyaJggsmLm890SjZl'
  4. });
  5. Avatar.setOptions({
  6. fallbackType: "initials",
  7. defaultImageUrl: "http://static.boredpanda.com/blog/wp-content/uploads/2014/04/amazing-fox-photos-182.jpg",
  8. generateCSS: true,
  9. imageSizes: {
  10. 'header': 40
  11. }
  12. });
  13. });
  14. Deps.autorun(function() {
  15. Meteor.subscribe("queues");
  16. Meteor.subscribe("reports");
  17. Meteor.subscribe("chat");
  18. Meteor.subscribe("playlists");
  19. Meteor.subscribe("alerts");
  20. Meteor.subscribe("userData", Meteor.userId());
  21. });
  22. var ban_interval = Meteor.setInterval(function() {
  23. var userId = Meteor.userId();
  24. if (userId !== undefined) {
  25. var userData = Meteor.user();
  26. if (localStorage.getItem("banned") === "true") {
  27. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  28. var ban = userData.punishments.ban;
  29. if (new Date(ban.bannedUntil).getTime() <= new Date().getTime()) {
  30. Meteor.call("isBanned", function(err, res) {
  31. if (res === false) {
  32. localStorage.setItem("banned", false);
  33. Meteor._reload.reload();
  34. }
  35. });
  36. }
  37. } else {
  38. localStorage.setItem("banned", false);
  39. Meteor._reload.reload();
  40. }
  41. } else {
  42. if (userData !== undefined && userData !== null && userData.punishments !== undefined && userData.punishments.ban !== undefined) {
  43. localStorage.setItem("banned", true);
  44. Meteor._reload.reload();
  45. }
  46. }
  47. }
  48. }, 1000);
  49. var minterval;
  50. var hpSound = undefined;
  51. var songsArr = [];
  52. var ytArr = [];
  53. var _sound = undefined;
  54. var parts = location.href.split('/');
  55. var id = parts.pop();
  56. var type = id.toLowerCase();
  57. var resizeSeekerbarInterval;
  58. var station_c = undefined;
  59. var songMID;
  60. UI.registerHelper("formatTime", function(seconds) {
  61. var d = moment.duration(parseInt(seconds), 'seconds');
  62. return d.minutes() + ":" + ("0" + d.seconds()).slice(-2);
  63. });
  64. /*UI.registerHelper("formatTimeFromNow", function(time) {
  65. var d = moment(time);
  66. return d.fromNow();
  67. });*/
  68. function getSpotifyInfo(title, cb, artist) {
  69. var q = "";
  70. q = title;
  71. if (artist !== undefined) {
  72. q += " artist:" + artist;
  73. }
  74. $.ajax({
  75. type: "GET",
  76. url: 'https://api.spotify.com/v1/search?q=' + encodeURIComponent(q) + '&type=track',
  77. applicationType: "application/json",
  78. contentType: "json",
  79. success: function (data) {
  80. cb(data);
  81. }
  82. });
  83. }
  84. Template.settings.events({
  85. "click #save-settings": function() {
  86. Meteor.call("updateSettings", $("#showRating").is(":checked"));
  87. }
  88. });
  89. Template.profile.events({
  90. "click #edit-name": function(){
  91. $("#name").hide();
  92. $("#name-div").show();
  93. $("#edit-name").hide();
  94. $("#cancel-edit").show();
  95. },
  96. "click #submit-name": function(){
  97. var user = Meteor.user();
  98. $("#name").show();
  99. $("#name-div").hide();
  100. $("#edit-name").show();
  101. $("#cancel-edit").hide();
  102. var realname = $("#input-name").val();
  103. var username = user.profile.username;
  104. $("#name").text("Name: " + realname);
  105. $("#input-name").val("")
  106. Meteor.call("updateRealName", username, realname);
  107. },
  108. "click #cancel-edit": function(){
  109. $("#name").show();
  110. $("#name-div").hide();
  111. $("#edit-name").show();
  112. $("#cancel-edit").hide();
  113. $("#input-name").val("");
  114. }
  115. })
  116. Template.profile.helpers({
  117. "realname": function(){
  118. return Session.get("realname");
  119. },
  120. "username": function() {
  121. return Session.get("username")
  122. },
  123. "first_joined": function() {
  124. return moment(Session.get("first_joined")).format("DD/MM/YYYY HH:mm:ss");
  125. },
  126. "rank": function() {
  127. return Session.get("rank");
  128. },
  129. loaded: function() {
  130. return Session.get("loaded");
  131. },
  132. likedSongs: function(){
  133. var likedArr = [];
  134. Session.get("liked").forEach(function(mid){
  135. Rooms.find().forEach(function(room){
  136. Playlists.find({type: room.type}).forEach(function(pl){
  137. for(var i in pl.songs){
  138. if(pl.songs[i].mid === mid){
  139. likedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  140. }
  141. }
  142. });
  143. })
  144. });
  145. return likedArr;
  146. },
  147. dislikedSongs: function(){
  148. var dislikedArr = [];
  149. Session.get("disliked").forEach(function(mid){
  150. Rooms.find().forEach(function(room){
  151. Playlists.find({type: room.type}).forEach(function(pl){
  152. for(var i in pl.songs){
  153. if(pl.songs[i].mid === mid){
  154. dislikedArr.push({title: pl.songs[i].title, artist: pl.songs[i].artist, room: room.display});
  155. }
  156. }
  157. });
  158. })
  159. });
  160. return dislikedArr;
  161. },
  162. initials: function() {
  163. var user = Meteor.user();
  164. if (user !== undefined) {
  165. return user.profile.username[0].toUpperCase();
  166. } else {
  167. return "";
  168. }
  169. },
  170. });
  171. Template.profile.onCreated(function() {
  172. var parts = Router.current().url.split('/');
  173. var username = parts.pop();
  174. Session.set("loaded", false);
  175. Meteor.subscribe("userProfiles", username.toLowerCase(), function() {
  176. if (Meteor.users.find({"profile.usernameL": username.toLowerCase()}).count() === 0) {
  177. window.location = "/";
  178. } else {
  179. var data = Meteor.users.findOne({"profile.usernameL": username.toLowerCase()});
  180. Session.set("realname", data.profile.realname);
  181. Session.set("username", data.profile.username);
  182. Session.set("first_joined", data.createdAt);
  183. Session.set("rank", data.profile.rank);
  184. Session.set("liked", data.profile.liked);
  185. Session.set("disliked", data.profile.disliked);
  186. Session.set("loaded", true);
  187. }
  188. });
  189. });
  190. Template.settings.helpers({
  191. username: function() {
  192. if (Meteor.user() !== undefined) {
  193. return Meteor.user().profile.username;
  194. } else {
  195. return "";
  196. }
  197. }
  198. });
  199. Template.settings.onCreated(function() {
  200. $(document).ready(function() {
  201. var user = Meteor.user();
  202. function initSettings() {
  203. if (user !== undefined) {
  204. if (user.profile.settings && user.profile.settings.showRating === true) {
  205. function setChecked() {
  206. $("#showRating").prop("checked", true);
  207. if (!$("#showRating").prop("checked")) {
  208. Meteor.setTimeout(function() {
  209. setChecked();
  210. }, 100);
  211. }
  212. }
  213. setChecked();
  214. }
  215. } else {
  216. Meteor.setTimeout(function() {
  217. initSettings();
  218. }, 500);
  219. }
  220. }
  221. initSettings();
  222. });
  223. });
  224. curPath=function(){var c=window.location.pathname;var b=c.slice(0,-1);var a=c.slice(-1);if(b==""){return"/"}else{if(a=="/"){return b}else{return c}}};
  225. Handlebars.registerHelper('active', function(path) {
  226. return curPath() == path ? 'active' : '';
  227. });
  228. Template.header.helpers({
  229. currentUser: function() {
  230. return Meteor.user();
  231. },
  232. userId: function() {
  233. return Meteor.userId();
  234. },
  235. initials: function() {
  236. var user = Meteor.user();
  237. if (user !== undefined) {
  238. return user.profile.username[0].toUpperCase();
  239. } else {
  240. return "";
  241. }
  242. },
  243. isAdmin: function() {
  244. if (Meteor.user() && Meteor.user().profile) {
  245. return Meteor.user().profile.rank === "admin";
  246. } else {
  247. return false;
  248. }
  249. },
  250. isModerator: function() {
  251. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  252. return true;
  253. } else {
  254. return false;
  255. }
  256. }
  257. });
  258. Template.header.events({
  259. "click .logout": function(e){
  260. e.preventDefault();
  261. Meteor.logout();
  262. if (hpSound !== undefined) {
  263. hpSound.stop();
  264. }
  265. }
  266. });
  267. Template.register.onCreated(function() {
  268. Accounts.onLoginFailure(function() {
  269. var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> Something went wrong when trying to register with GitHub. Maybe an account with that username already exists?</div>');
  270. $(".landing").before(errAlert);
  271. Meteor.setTimeout(function() {
  272. errAlert.fadeOut(5000, function() {
  273. errAlert.remove();
  274. });
  275. }, 10000);
  276. });
  277. });
  278. Template.login.onCreated(function() {
  279. Session.set("github", true);
  280. Accounts.onLoginFailure(function() {
  281. if (Session.get("github") === true) {
  282. var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> Something went wrong when trying to log in with GitHub.</div>');
  283. $(".landing").before(errAlert);
  284. Meteor.setTimeout(function() {
  285. errAlert.fadeOut(5000, function() {
  286. errAlert.remove();
  287. });
  288. }, 10000);
  289. }
  290. });
  291. });
  292. Template.register.events({
  293. "submit form": function(e){
  294. e.preventDefault();
  295. var username = e.target.registerUsername.value;
  296. var email = e.target.registerEmail.value;
  297. var password = e.target.registerPassword.value;
  298. var captchaData = grecaptcha.getResponse();
  299. Meteor.call("createUserMethod", {username: username, email: email, password: password}, captchaData, function(err, res) {
  300. grecaptcha.reset();
  301. if (err) {
  302. console.log(err);
  303. var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> ' + err.reason + '</div>');
  304. $(".landing").before(errAlert);
  305. Meteor.setTimeout(function() {
  306. errAlert.fadeOut(5000, function() {
  307. errAlert.remove();
  308. });
  309. }, 5000);
  310. } else {
  311. Meteor.loginWithPassword(username, password);
  312. Accounts.onLogin(function(){
  313. window.location.href = "/";
  314. })
  315. }
  316. });
  317. },
  318. "click #github-login": function(){
  319. Meteor.loginWithGithub({loginStyle: "redirect"});
  320. }
  321. });
  322. Template.login.events({
  323. "submit form": function(e){
  324. e.preventDefault();
  325. Session.set("github", false);
  326. var username = e.target.loginUsername.value;
  327. var password = e.target.loginPassword.value;
  328. Meteor.loginWithPassword(username, password, function(err) {
  329. if (err) {
  330. var errAlert = $('<div style="margin-bottom: 0" class="alert alert-danger" role="alert"><strong>Oh Snap!</strong> ' + err.reason + '</div>');
  331. $(".landing").before(errAlert);
  332. Meteor.setTimeout(function() {
  333. errAlert.fadeOut(5000, function() {
  334. errAlert.remove();
  335. });
  336. }, 5000);
  337. } else {
  338. window.location.href = "/";
  339. }
  340. });
  341. },
  342. "click #github-login": function(){
  343. Meteor.loginWithGithub({loginStyle: "redirect"}, function(err, res) {
  344. console.log(err, res);
  345. });
  346. }
  347. });
  348. Template.dashboard.helpers({
  349. rooms: function() {
  350. return Rooms.find({});
  351. },
  352. currentSong: function() {
  353. var type = this.type;
  354. var room = Rooms.findOne({type: type});
  355. if (room !== undefined) {
  356. return room.currentSong;
  357. } else {
  358. return {};
  359. }
  360. },
  361. isAdmin: function() {
  362. if (Meteor.user() && Meteor.user().profile) {
  363. return Meteor.user().profile.rank === "admin";
  364. } else {
  365. return false;
  366. }
  367. },
  368. isModerator: function() {
  369. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  370. return true;
  371. } else {
  372. return false;
  373. }
  374. }
  375. });
  376. Template.dashboard.onCreated(function() {
  377. if (_sound !== undefined) _sound.stop();
  378. if (minterval !== undefined) {
  379. Meteor.clearInterval(minterval);
  380. }
  381. if (resizeSeekerbarInterval !== undefined) {
  382. Meteor.clearInterval(resizeSeekerbarInterval);
  383. resizeSeekerbarInterval = undefined;
  384. }
  385. if (station_c !== undefined) {
  386. station_c.stop();
  387. }
  388. Session.set("type", undefined);
  389. });
  390. function executeCommand(command, params){
  391. if (command === "help" || command === "commands") {
  392. $('#helpModal').modal('show');
  393. return true;
  394. } else if (command === "volume") {
  395. if (params.length === 1) {
  396. var volume = Number(params[0]);
  397. if (volume >= 0 || volume <= 100) {
  398. if (volume === 0) {
  399. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  400. } else {
  401. $("#volume-icon").removeClass("fa-volume-off").addClass("fa-volume-down")
  402. }
  403. $("#volume-slider").slider("setValue", volume);
  404. if (yt_player !== undefined) {
  405. yt_player.setVolume(volume);
  406. localStorage.setItem("volume", volume);
  407. } else if (_sound !== undefined) {
  408. //_sound
  409. var volume = volume / 100;
  410. _sound.setVolume(volume);
  411. localStorage.setItem("volume", volume * 100);
  412. }
  413. return true;
  414. }
  415. }
  416. } else if(command === "mute"){
  417. $("#volume-slider").slider("setValue", 0);
  418. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off");
  419. if (yt_player !== undefined) {
  420. yt_player.setVolume(0);
  421. localStorage.setItem("volume", 0);
  422. } else if (_sound !== undefined) {
  423. //_sound
  424. _sound.setVolume(0);
  425. localStorage.setItem("volume", 0);
  426. }
  427. } else if(command === "ban"){
  428. var user = params[0];
  429. var time = params[1];
  430. var reason = params[2];
  431. Meteor.call("banUser", user, time, reason, function(err, res){
  432. if(err){
  433. console.log(err);
  434. }
  435. });
  436. } else if(command === "pause"){
  437. Meteor.call("pauseRoom", Session.get("type"), function(err, res){
  438. if(err){
  439. console.log(err);
  440. }
  441. });
  442. } else if(command === "resume"){
  443. Meteor.call("resumeRoom", Session.get("type"), function(err, res){
  444. if(err){
  445. console.log(err);
  446. }
  447. });
  448. } else if(command === "shuffle"){
  449. Meteor.call("shufflePlaylist", Session.get("type"), function(err, res){
  450. if(err){
  451. console.log(err);
  452. }
  453. });
  454. } else if(command === "skip"){
  455. Meteor.call("skipSong", Session.get("type"), function(err, res){
  456. if(err){
  457. console.log(err);
  458. }
  459. });
  460. }
  461. }
  462. function sendMessage() {
  463. var message = $("#chat-input").val();
  464. if (message.length > 0 && message[0] !== " ") {
  465. if (message[0] === "/") {
  466. message = message.split("");
  467. message.shift();
  468. message = message.join("");
  469. var params = message.split(" ");
  470. var command = params.shift();
  471. command = command.replace(/\r?\n|\r/g, "");
  472. if (executeCommand(command, params)) {
  473. $("#chat-input").val("");
  474. } else {
  475. $("#chat-input").val("");
  476. }
  477. } else {
  478. Meteor.call("sendMessage", Session.get("type"), message, function (err, res) {
  479. if (res) {
  480. $("#chat-input").val("");
  481. }
  482. });
  483. }
  484. }
  485. }
  486. Template.room.events({
  487. "click #chat-tab": function() {
  488. $("#chat-tab").removeClass("unread-messages");
  489. },
  490. "click #sync": function() {
  491. if (Session.get("currentSong") !== undefined) {
  492. var room = Rooms.findOne({type: Session.get("type")});
  493. if (room !== undefined) {
  494. var timeIn = Date.now() - Session.get("currentSong").started - room.timePaused;
  495. var skipDuration = Number(Session.get("currentSong").skipDuration) | 0;
  496. if (yt_player !== undefined) {
  497. yt_player.seekTo(skipDuration + timeIn / 1000);
  498. }
  499. else if (_sound !== undefined) {
  500. _sound.seekTo(skipDuration * 1000 + timeIn);
  501. }
  502. }
  503. }
  504. },
  505. "click #lock": function() {
  506. Meteor.call("lockRoom", Session.get("type"));
  507. },
  508. "click #unlock": function() {
  509. Meteor.call("unlockRoom", Session.get("type"));
  510. },
  511. "click #side-panel": function(e) {
  512. Meteor.setTimeout(function() {
  513. var elem = document.getElementById('chat');
  514. elem.scrollTop = elem.scrollHeight;
  515. }, 1);
  516. },
  517. "click #submit": function() {
  518. sendMessage();
  519. },
  520. "keyup #chat-input": function(e) {
  521. if (e.type === "keyup" && e.which === 13) {
  522. e.preventDefault();
  523. if (!$('#chat-input').data('dropdownshown')) {
  524. sendMessage();
  525. }
  526. }
  527. },
  528. "click #like": function(e) {
  529. $("#like").blur();
  530. Meteor.call("likeSong", Session.get("currentSong").mid);
  531. },
  532. "click #dislike": function(e) {
  533. $("#dislike").blur();
  534. Meteor.call("dislikeSong", Session.get("currentSong").mid);
  535. },
  536. "click #vote-skip": function(){
  537. Meteor.call("voteSkip", type, function(err, res) {
  538. $("#vote-skip").attr("disabled", true);
  539. });
  540. songMID = Session.get("currentSong").mid;
  541. },
  542. "click #report-prev": function(e) {
  543. if (Session.get("previousSong") !== undefined) {
  544. Session.set("reportPrevious", true);
  545. $("#report-prev").prop("disabled", true);
  546. $("#report-curr").prop("disabled", false);
  547. }
  548. },
  549. "click #report-curr": function(e) {
  550. Session.set("reportPrevious", false);
  551. $("#report-prev").prop("disabled", false);
  552. $("#report-curr").prop("disabled", true);
  553. },
  554. "click #report-modal": function() {
  555. Session.set("currentSongR", Session.get("currentSong"));
  556. Session.set("previousSongR", Session.get("previousSong"));
  557. },
  558. "click #add-song-button": function(e){
  559. e.preventDefault();
  560. parts = location.href.split('/');
  561. var roomType = parts.pop();
  562. var genre = roomType.toLowerCase();
  563. var type = $("#type").val();
  564. id = $("#id").val();
  565. var title = $("#title").val();
  566. var artist = $("#artist").val();
  567. var img = $("#img").val();
  568. var songData = {type: type, id: id, title: title, artist: artist, img: img};
  569. if(Playlists.find({type: genre, "songs.id": songData.id}, {songs: {$elemMatch: {id: songData.id}}}).count() !== 0) {
  570. $("<div class='alert alert-danger alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Song not added.</strong> This song is already in the playlist.</div>").prependTo($(".landing")).delay(7000).fadeOut(1000, function() { $(this).remove(); });
  571. } else if(Queues.find({type: genre, "songs.id": songData.id}, {songs: {$elemMatch: {id: songData.id}}}).count() !== 0) {
  572. $("<div class='alert alert-danger alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Song not added.</strong> This song has already been requested.</div>").prependTo($(".landing")).delay(7000).fadeOut(1000, function() { $(this).remove(); });
  573. } else{
  574. Meteor.call("addSongToQueue", genre, songData, function(err, res) {
  575. console.log(err, res);
  576. if (err) {
  577. $("<div class='alert alert-danger alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Song not added.</strong> Something went wrong.</div>").prependTo($(".landing")).delay(7000).fadeOut(1000, function() { $(this).remove(); });
  578. } else {
  579. $("<div class='alert alert-success alert-dismissible' role='alert' style='margin-bottom: 0'><button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'><i class='fa fa-times'></i></span></button><strong>Song added.</strong> Your song has been added to the queue.</div>").prependTo($(".landing")).delay(7000).fadeOut(1000, function() { $(this).remove(); });
  580. }
  581. });
  582. }
  583. $("#close-modal-a").click();
  584. },
  585. "click #toggle-video": function(e){
  586. e.preventDefault();
  587. if (Session.get("mediaHidden")) {
  588. $("#media-container").removeClass("hidden");
  589. $("#toggle-video").text("Hide video");
  590. Session.set("mediaHidden", false);
  591. } else {
  592. $("#media-container").addClass("hidden");
  593. $("#toggle-video").text("Show video");
  594. Session.set("mediaHidden", true);
  595. }
  596. },
  597. "click #return": function(e){
  598. $("#add-info").hide();
  599. $("#search-info").show();
  600. },
  601. "click #search-song": function(){
  602. $("#song-results").empty();
  603. var search_type = $("#search_type").val();
  604. if (search_type === "YouTube") {
  605. $.ajax({
  606. type: "GET",
  607. url: "https://www.googleapis.com/youtube/v3/search?part=snippet&q=" + $("#song-input").val() + "&key=AIzaSyAgBdacEWrHCHVPPM4k-AFM7uXg-Q__YXY",
  608. applicationType: "application/json",
  609. contentType: "json",
  610. success: function(data){
  611. for(var i in data.items){
  612. $("#song-results").append("<p>" + data.items[i].snippet.title + "</p>");
  613. ytArr.push({title: data.items[i].snippet.title, id: data.items[i].id.videoId});
  614. }
  615. $("#song-results p").click(function(){
  616. $("#search-info").hide();
  617. $("#add-info").show();
  618. var title = $(this).text();
  619. for(var i in ytArr){
  620. if(ytArr[i].title === title){
  621. var songObj = {
  622. id: ytArr[i].id,
  623. title: ytArr[i].title,
  624. type: "youtube"
  625. };
  626. $("#title").val(songObj.title);
  627. $("#artist").val("");
  628. $("#id").val(songObj.id);
  629. $("#type").val("YouTube");
  630. getSpotifyInfo(songObj.title.replace(/\[.*\]/g, ""), function(data) {
  631. if (data.tracks.items.length > 0) {
  632. $("#title").val(data.tracks.items[0].name);
  633. var artists = [];
  634. $("#img").val(data.tracks.items[0].album.images[1].url);
  635. data.tracks.items[0].artists.forEach(function(artist) {
  636. artists.push(artist.name);
  637. });
  638. $("#artist").val(artists.join(", "));
  639. }
  640. });
  641. }
  642. }
  643. })
  644. }
  645. })
  646. } else if (search_type === "SoundCloud") {
  647. SC.get('/tracks', { q: $("#song-input").val()}, function(tracks) {
  648. for(var i in tracks){
  649. $("#song-results").append("<p>" + tracks[i].title + "</p>")
  650. songsArr.push({title: tracks[i].title, id: tracks[i].id, duration: tracks[i].duration / 1000});
  651. }
  652. $("#song-results p").click(function(){
  653. $("#search-info").hide();
  654. $("#add-info").show();
  655. var title = $(this).text();
  656. for(var i in songsArr){
  657. if(songsArr[i].title === title){
  658. var id = songsArr[i].id;
  659. var duration = songsArr[i].duration;
  660. var songObj = {
  661. title: songsArr[i].title,
  662. id: id,
  663. duration: duration,
  664. type: "soundcloud"
  665. }
  666. $("#title").val(songObj.title);
  667. // Set ID field
  668. $("#id").val(songObj.id);
  669. $("#type").val("SoundCloud");
  670. getSpotifyInfo(songObj.title.replace(/\[.*\]/g, ""), function(data) {
  671. if (data.tracks.items.length > 0) {
  672. $("#title").val(data.tracks.items[0].name);
  673. var artists = [];
  674. data.tracks.items[0].artists.forEach(function(artist) {
  675. artists.push(artist.name);
  676. });
  677. $("#artist").val(artists.join(", "));
  678. }
  679. // Set title field again if possible
  680. // Set artist if possible
  681. });
  682. }
  683. }
  684. })
  685. });
  686. }
  687. },
  688. "click #close-modal-a": function(){
  689. $("#search-info").show();
  690. $("#add-info").hide();
  691. },
  692. "click #volume-icon": function(){
  693. var volume = 0;
  694. var slider = $("#volume-slider").slider();
  695. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  696. if (yt_player !== undefined) {
  697. yt_player.setVolume(volume);
  698. localStorage.setItem("volume", volume);
  699. $("#volume-slider").slider("setValue", volume);
  700. } else if (_sound !== undefined) {
  701. _sound.setVolume(volume);
  702. localStorage.setItem("volume", volume);
  703. $("#volume-slider").slider("setValue", volume);
  704. }
  705. },
  706. "click #play": function() {
  707. Meteor.call("resumeRoom", type);
  708. },
  709. "click #pause": function() {
  710. Meteor.call("pauseRoom", type);
  711. },
  712. "click #skip": function() {
  713. Meteor.call("skipSong", type);
  714. },
  715. "click #shuffle": function() {
  716. Meteor.call("shufflePlaylist", type);
  717. },
  718. "change input": function(e) {
  719. if (e.target && e.target.id) {
  720. var partsOfId = e.target.id.split("-");
  721. partsOfId[1] = partsOfId[1].charAt(0).toUpperCase() + partsOfId[1].slice(1);
  722. var camelCase = partsOfId.join("");
  723. Session.set(camelCase, e.target.checked);
  724. }
  725. },
  726. "click #report-song-button": function() {
  727. var room = Session.get("type");
  728. var reportData = {};
  729. reportData.song = Session.get("currentSong").mid;
  730. reportData.type = [];
  731. reportData.reason = [];
  732. $(".report-layer-1 > .checkbox input:checked").each(function(){
  733. reportData.type.push(this.id);
  734. if (this.id == "report-other") {
  735. var otherText = $(".other-textarea").val();
  736. }
  737. });
  738. $(".report-layer-2 input:checked").each(function(){
  739. reportData.reason.push(this.id);
  740. });
  741. console.log(reportData);
  742. Meteor.call("submitReport", room, reportData, Session.get("id"), function() {
  743. $("#close-modal-r").click();
  744. });
  745. }
  746. });
  747. Template.banned.helpers({
  748. bannedAt: function() {
  749. if (Session.get("ban") !== undefined) {
  750. return Session.get("ban").bannedAt;
  751. }
  752. },
  753. bannedBy: function() {
  754. if (Session.get("ban") !== undefined) {
  755. return Session.get("ban").bannedBy;
  756. }
  757. },
  758. bannedUntil: function() {
  759. if (Session.get("ban") !== undefined) {
  760. return Session.get("ban").bannedUntil;
  761. }
  762. },
  763. bannedReason: function() {
  764. if (Session.get("ban") !== undefined) {
  765. return Session.get("ban").bannedReason;
  766. }
  767. }
  768. });
  769. Template.banned.onCreated(function() {
  770. if (rTimeInterval !== undefined) {
  771. Meteor.clearInterval(rTimeInterval)
  772. }
  773. rTimeInterval = Meteor.setInterval(function() {
  774. Session.set("time", new Date().getTime());
  775. }, 10000);
  776. Session.set("ban", Meteor.user().punishments.ban);
  777. });
  778. Template.registerHelper("rtime", function(date) {
  779. Session.get("time");
  780. if (date) {
  781. return moment(date).fromNow();
  782. }
  783. });
  784. var rTimeInterval = undefined;
  785. Template.room.onRendered(function() {
  786. if (rTimeInterval !== undefined) {
  787. Meteor.clearInterval(rTimeInterval)
  788. }
  789. rTimeInterval = Meteor.setInterval(function() {
  790. Session.set("time", new Date().getTime());
  791. }, 10000);
  792. $(document).ready(function() {
  793. function makeSlider(){
  794. var slider = $("#volume-slider").slider();
  795. var volume = Number(localStorage.getItem("volume"));
  796. $("#volume-slider").slider("setValue", volume);
  797. if (slider.length === 0) {
  798. Meteor.setTimeout(function() {
  799. makeSlider();
  800. }, 500);
  801. } else {
  802. if (volume === 0) {
  803. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  804. } else {
  805. $("#volume-icon").removeClass("fa-volume-off").addClass("fa-volume-down")
  806. }
  807. slider.on("slide", function(val) {
  808. if (val.value === 0) {
  809. $("#volume-icon").removeClass("fa-volume-down").addClass("fa-volume-off")
  810. } else {
  811. $("#volume-icon").removeClass("fa-volume-off").addClass("fa-volume-down")
  812. }
  813. if (yt_player !== undefined) {
  814. yt_player.setVolume(val.value);
  815. localStorage.setItem("volume", val.value);
  816. } else if (_sound !== undefined) {
  817. //_sound
  818. var volume = val.value / 100;
  819. _sound.setVolume(volume);
  820. localStorage.setItem("volume", val.value);
  821. }
  822. });
  823. }
  824. }
  825. makeSlider();
  826. });
  827. });
  828. Template.alerts.helpers({
  829. alerts: function() {
  830. return Alerts.find({active: true});
  831. }
  832. });
  833. Template.room.helpers({
  834. chat: function() {
  835. Meteor.setTimeout(function() {
  836. var elem = document.getElementById('chat');
  837. if (elem !== undefined && elem !== null) {
  838. elem.scrollTop = elem.scrollHeight;
  839. }
  840. }, 100);
  841. return Chat.find({type: Session.get("type")}, {sort: {time: -1}, limit: 50 }).fetch().reverse();
  842. },
  843. likes: function() {
  844. var playlist = Playlists.findOne({type: Session.get("type")});
  845. var likes = 0;
  846. playlist.songs.forEach(function(song) {
  847. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  848. likes = song.likes;
  849. return;
  850. }
  851. });
  852. return likes;
  853. },
  854. dislikes: function() {
  855. var playlist = Playlists.findOne({type: Session.get("type")});
  856. var dislikes = 0;
  857. playlist.songs.forEach(function(song) {
  858. if (Session.get("currentSong") && song.mid === Session.get("currentSong").mid) {
  859. dislikes = song.dislikes;
  860. return;
  861. }
  862. });
  863. return dislikes;
  864. },
  865. liked: function() {
  866. if (Meteor.userId()) {
  867. var currentSong = Session.get("currentSong");
  868. if (currentSong && Meteor.user().profile.liked.indexOf(currentSong.mid) !== -1) {
  869. return "active";
  870. } else {
  871. return "";
  872. }
  873. } else {
  874. "";
  875. }
  876. },
  877. disliked: function() {
  878. if (Meteor.userId()) {
  879. var currentSong = Session.get("currentSong");
  880. if (currentSong && Meteor.user().profile.disliked.indexOf(currentSong.mid) !== -1) {
  881. return "active";
  882. } else {
  883. return "";
  884. }
  885. } else {
  886. "";
  887. }
  888. },
  889. type: function() {
  890. var parts = location.href.split('/');
  891. var id = parts.pop().toLowerCase();
  892. return Rooms.findOne({type: id}).display;
  893. },
  894. users: function() {
  895. var parts = location.href.split('/');
  896. var id = parts.pop().toLowerCase();
  897. return Rooms.findOne({type: id}).users;
  898. },
  899. title: function(){
  900. return Session.get("title");
  901. },
  902. artist: function(){
  903. return Session.get("artist");
  904. },
  905. loaded: function() {
  906. return Session.get("loaded");
  907. },
  908. isAdmin: function() {
  909. if (Meteor.user() && Meteor.user().profile) {
  910. return Meteor.user().profile.rank === "admin";
  911. } else {
  912. return false;
  913. }
  914. },
  915. isModerator: function() {
  916. if (Meteor.user() && Meteor.user().profile && (Meteor.user().profile.rank === "admin" || Meteor.user().profile.rank === "moderator")) {
  917. return true;
  918. } else {
  919. return false;
  920. }
  921. },
  922. paused: function() {
  923. return Session.get("state") === "paused";
  924. },
  925. private: function() {
  926. return Rooms.findOne({type: Session.get("type")}).private === true;
  927. },
  928. report: function() {
  929. return Session.get("reportObj");
  930. },
  931. reportSong: function() {
  932. return Session.get("reportSong");
  933. },
  934. reportTitle: function() {
  935. return Session.get("reportTitle");
  936. },
  937. reportAuthor: function() {
  938. return Session.get("reportAuthor");
  939. },
  940. reportDuration: function() {
  941. return Session.get("reportDuration");
  942. },
  943. reportAudio: function() {
  944. return Session.get("reportAudio");
  945. },
  946. reportAlbumart: function() {
  947. return Session.get("reportAlbumart");
  948. },
  949. reportOther: function() {
  950. return Session.get("reportOther");
  951. },
  952. currentSong: function() {
  953. return Session.get("currentSong");
  954. },
  955. previousSong: function() {
  956. return Session.get("previousSong");
  957. },
  958. currentSongR: function() {
  959. return Session.get("currentSongR");
  960. },
  961. previousSongR: function() {
  962. return Session.get("previousSongR");
  963. },
  964. reportingSong: function() {
  965. if (Session.get("reportPrevious")) {
  966. return Session.get("previousSongR");
  967. } else {
  968. return Session.get("currentSongR");
  969. }
  970. },
  971. votes: function(){
  972. return Rooms.findOne({type: Session.get("type")}).votes;
  973. }
  974. });
  975. var allAlertSub = undefined;
  976. Template.alertsDashboard.onCreated(function() {
  977. if (allAlertSub === undefined) {
  978. allAlertSub = Meteor.subscribe("allAlerts");
  979. }
  980. });
  981. Template.alertsDashboard.helpers({
  982. "activeAlerts": function() {
  983. return Alerts.find({active: true});
  984. },
  985. "inactiveAlerts": function() {
  986. return Alerts.find({active: false});
  987. }
  988. });
  989. Template.alertsDashboard.events({
  990. "click #calart-create": function() {
  991. Meteor.call("addAlert", $("#calert-description").val(), $("#calert-priority").val().toLowerCase(), function (err, res) {
  992. if (err) {
  993. alert("Error " + err.error + ": " + err.reason);
  994. } else {
  995. $("#calert-description").val("");
  996. }
  997. });
  998. },
  999. "click #ralert-button": function() {
  1000. Meteor.call("removeAlerts");
  1001. }
  1002. });
  1003. Template.admin.helpers({
  1004. queueCount: function(display) {
  1005. display = display.toLowerCase();
  1006. var queues = Queues.findOne({type:display});
  1007. return queues && "songs" in queues ? queues.songs.length : 0;
  1008. },
  1009. queues: function() {
  1010. var queues = Queues.find({}).fetch();
  1011. return queues;
  1012. },
  1013. usersOnline: function(){
  1014. Meteor.call("getUserNum", function(err, num){
  1015. if(err){
  1016. console.log(err);
  1017. }
  1018. Session.set("userNum", num);
  1019. });
  1020. return Session.get("userNum");
  1021. },
  1022. allUsers: function(){
  1023. },
  1024. playlists: function() {
  1025. var playlists = Playlists.find({}).fetch();
  1026. playlists.map(function(playlist) {
  1027. if (Rooms.find({type: playlist.type}).count() !== 1) {
  1028. return;
  1029. } else {
  1030. playlist.display = Rooms.findOne({type: playlist.type}).display;
  1031. return playlist;
  1032. }
  1033. });
  1034. return playlists;
  1035. },
  1036. reportsCount: function(room) {
  1037. room = room.toLowerCase();
  1038. var reports = Reports.findOne({room:room});
  1039. return reports && "report" in reports ? reports.report.length : 0;
  1040. }
  1041. });
  1042. Template.admin.events({
  1043. "click #croom_create": function() {
  1044. Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), function (err, res) {
  1045. if (err) {
  1046. alert("Error " + err.error + ": " + err.reason);
  1047. } else {
  1048. window.location = "/" + $("#croom_tag").val();
  1049. }
  1050. });
  1051. },
  1052. "click a": function(e){
  1053. var id = e.currentTarget.id;
  1054. console.log(id.toLowerCase());
  1055. Session.set("playlistToEdit", id);
  1056. }
  1057. });
  1058. Template.stations.helpers({
  1059. playlist: function() {
  1060. var query = {type: Session.get("playlistToEdit").toLowerCase()};
  1061. var playlists = Playlists.find(query).fetch();
  1062. console.log(Session.get("playlistToEdit"), query, playlists);
  1063. return playlists;
  1064. },
  1065. whichStation: function(){
  1066. return Session.get("playlistToEdit");
  1067. }
  1068. });
  1069. Template.queues.helpers({
  1070. queues: function() {
  1071. var queues = Queues.find({}).fetch();
  1072. queues.map(function(queue) {
  1073. if (Rooms.find({type: queue.type}).count() !== 1) {
  1074. return;
  1075. } else {
  1076. queue.display = Rooms.findOne({type: queue.type}).display;
  1077. return queue;
  1078. }
  1079. });
  1080. return queues;
  1081. }
  1082. })
  1083. var yt_player = undefined;
  1084. var _sound = undefined;
  1085. var previewEndSongTimeout = undefined;
  1086. Template.stations.events({
  1087. "click .preview-button": function(e){
  1088. Session.set("song", this);
  1089. },
  1090. "click #previewImageButton": function() {
  1091. $("#preview-image").attr("src", Session.get("song").img);
  1092. },
  1093. "click .edit-queue-button": function(e){
  1094. Session.set("song", this);
  1095. Session.set("genre", $(e.target).data("genre"));
  1096. Session.set("type", "queue");
  1097. $("#type").val(this.type);
  1098. $("#mid").val(this.mid);
  1099. $("#artist").val(this.artist);
  1100. $("#title").val(this.title);
  1101. $("#img").val(this.img);
  1102. $("#id").val(this.id);
  1103. $("#likes").val(this.likes);
  1104. $("#dislikes").val(this.dislikes);
  1105. $("#duration").val(this.duration);
  1106. $("#skip-duration").val(this.skipDuration);
  1107. },
  1108. "click .edit-playlist-button": function(e){
  1109. Session.set("song", this);
  1110. Session.set("genre", $(e.target).data("genre"));
  1111. Session.set("type", "playlist");
  1112. $("#type").val(this.type);
  1113. $("#mid").val(this.mid);
  1114. $("#artist").val(this.artist);
  1115. $("#title").val(this.title);
  1116. $("#img").val(this.img);
  1117. $("#id").val(this.id);
  1118. $("#likes").val(this.likes);
  1119. $("#dislikes").val(this.dislikes);
  1120. $("#duration").val(this.duration);
  1121. $("#skip-duration").val(this.skipDuration);
  1122. },
  1123. "click #rreset_confirm": function(e){
  1124. Meteor.call("resetRating");
  1125. },
  1126. "click .add-song-button": function(e){
  1127. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1128. Meteor.call("addSongToPlaylist", genre, this);
  1129. },
  1130. "click .deny-song-button": function(e){
  1131. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1132. Meteor.call("removeSongFromQueue", genre, this.mid);
  1133. },
  1134. "click .remove-song-button": function(e){
  1135. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1136. Meteor.call("removeSongFromPlaylist", genre, this.mid);
  1137. },
  1138. "click #moveSong": function(e){
  1139. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1140. if (genre !== Session.get(genre)) {
  1141. Meteor.call("addSongToPlaylist", genre, {type: Session.get("song").type, mid: Session.get("song").mid, id: Session.get("song").id, title: Session.get("song").title, artist: Session.get("song").artist, duration: Session.get("song").duration, skipDuration: Session.get("song").skipDuration, img: Session.get("song").img, likes: Session.get("song").likes, dislikes: Session.get("song").dislikes});
  1142. Meteor.call("removeSongFromPlaylist", Session.get("genre"), Session.get("song").mid);
  1143. }else {
  1144. console.log("Something Went Wrong?!");
  1145. return false;
  1146. }
  1147. },
  1148. "click #copySong": function(e){
  1149. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1150. Meteor.call("addSongToPlaylist", genre, {type: Session.get("song").type, mid: Session.get("song").mid, id: Session.get("song").id, title: Session.get("song").title, artist: Session.get("song").artist, duration: Session.get("song").duration, skipDuration: Session.get("song").skipDuration, img: Session.get("song").img, likes: Session.get("song").likes, dislikes: Session.get("song").dislikes});
  1151. },
  1152. "click .copyMove-button": function(e){
  1153. Session.set("song", this);
  1154. Session.set("genre", $(e.target).data("genre"));
  1155. },
  1156. "click #play": function() {
  1157. $("#play").attr("disabled", true);
  1158. $("#stop").attr("disabled", false);
  1159. var song = Session.get("song");
  1160. var id = song.id;
  1161. var type = song.type;
  1162. var volume = localStorage.getItem("volume") || 20;
  1163. if (type === "YouTube") {
  1164. if (yt_player === undefined) {
  1165. yt_player = new YT.Player("previewPlayer", {
  1166. height: 540,
  1167. width: 568,
  1168. videoId: id,
  1169. playerVars: {controls: 0, iv_load_policy: 3, showinfo: 0},
  1170. events: {
  1171. 'onReady': function(event) {
  1172. event.target.seekTo(Number(song.skipDuration));
  1173. event.target.playVideo();
  1174. event.target.setVolume(volume);
  1175. },
  1176. 'onStateChange': function(event){
  1177. if (event.data == YT.PlayerState.PAUSED) {
  1178. event.target.playVideo();
  1179. }
  1180. if (event.data == YT.PlayerState.PLAYING) {
  1181. $("#play").attr("disabled", true);
  1182. $("#stop").attr("disabled", false);
  1183. } else {
  1184. $("#play").attr("disabled", false);
  1185. $("#stop").attr("disabled", true);
  1186. }
  1187. }
  1188. }
  1189. });
  1190. } else {
  1191. yt_player.loadVideoById(id);
  1192. yt_player.seekTo(Number(song.skipDuration));
  1193. }
  1194. $("#previewPlayer").show();
  1195. } else if (type === "SoundCloud") {
  1196. SC.stream("/tracks/" + song.id, function(sound) {
  1197. _sound = sound;
  1198. sound.setVolume(volume / 100);
  1199. sound.play();
  1200. });
  1201. }
  1202. if (previewEndSongTimeout !== undefined) {
  1203. Meteor.clearTimeout(previewEndSongTimeout);
  1204. }
  1205. previewEndSongTimeout = Meteor.setTimeout(function() {
  1206. if (yt_player !== undefined) {
  1207. yt_player.stopVideo();
  1208. }
  1209. if (_sound !== undefined) {
  1210. _sound.stop();
  1211. }
  1212. $("#play").attr("disabled", false);
  1213. $("#stop").attr("disabled", true);
  1214. $("#previewPlayer").hide();
  1215. }, song.duration * 1000);
  1216. },
  1217. "click #stop": function() {
  1218. $("#play").attr("disabled", false);
  1219. $("#stop").attr("disabled", true);
  1220. if (previewEndSongTimeout !== undefined) {
  1221. Meteor.clearTimeout(previewEndSongTimeout);
  1222. }
  1223. if (yt_player !== undefined) {
  1224. yt_player.stopVideo();
  1225. }
  1226. if (_sound !== undefined) {
  1227. _sound.stop();
  1228. }
  1229. },
  1230. "click #forward": function() {
  1231. var error = false;
  1232. if (yt_player !== undefined) {
  1233. var duration = Number(Session.get("song").duration) | 0;
  1234. var skipDuration = Number(Session.get("song").skipDuration) | 0;
  1235. if (yt_player.getDuration() < duration + skipDuration) {
  1236. alert("The duration of the YouTube video is smaller than the duration.");
  1237. error = true;
  1238. } else {
  1239. yt_player.seekTo(skipDuration + duration - 10);
  1240. }
  1241. }
  1242. if (_sound !== undefined) {
  1243. _sound.seekTo((skipDuration + duration - 10) * 1000);
  1244. }
  1245. if (!error) {
  1246. if (previewEndSongTimeout !== undefined) {
  1247. Meteor.clearTimeout(previewEndSongTimeout);
  1248. }
  1249. previewEndSongTimeout = Meteor.setTimeout(function() {
  1250. if (yt_player !== undefined) {
  1251. yt_player.stopVideo();
  1252. }
  1253. if (_sound !== undefined) {
  1254. _sound.stop();
  1255. }
  1256. $("#play").attr("disabled", false);
  1257. $("#stop").attr("disabled", true);
  1258. $("#previewPlayer").hide();
  1259. }, 10000);
  1260. }
  1261. },
  1262. "click #croom_create": function() {
  1263. Meteor.call("createRoom", $("#croom_display").val(), $("#croom_tag").val(), $("#two").prop("checked"), function (err, res) {
  1264. if (err) {
  1265. alert("Error " + err.error + ": " + err.reason);
  1266. } else {
  1267. window.location = "/" + $("#croom_tag").val();
  1268. }
  1269. });
  1270. },
  1271. "click #get-spotify-info": function() {
  1272. var search = $("#title").val();
  1273. var artistName = $("#artist").val();
  1274. getSpotifyInfo(search, function(data) {
  1275. for(var i in data){
  1276. for(var j in data[i].items){
  1277. if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
  1278. $("#img").val(data[i].items[j].album.images[1].url);
  1279. $("#duration").val(data[i].items[j].duration_ms / 1000);
  1280. return;
  1281. }
  1282. }
  1283. }
  1284. }, artistName);
  1285. },
  1286. "click #save-song-button": function() {
  1287. var newSong = {};
  1288. newSong.id = $("#id").val();
  1289. newSong.likes = Number($("#likes").val());
  1290. newSong.dislikes = Number($("#dislikes").val());
  1291. newSong.title = $("#title").val();
  1292. newSong.artist = $("#artist").val();
  1293. newSong.img = $("#img").val();
  1294. newSong.type = $("#type").val();
  1295. newSong.duration = Number($("#duration").val());
  1296. newSong.skipDuration = $("#skip-duration").val();
  1297. if(newSong.skipDuration === undefined){
  1298. newSong.skipDuration = 0;
  1299. };
  1300. if (Session.get("type") === "playlist") {
  1301. Meteor.call("updatePlaylistSong", Session.get("genre"), Session.get("song"), newSong, function() {
  1302. $('#editModal').modal('hide');
  1303. });
  1304. } else {
  1305. Meteor.call("updateQueueSong", Session.get("genre"), Session.get("song"), newSong, function() {
  1306. $('#editModal').modal('hide');
  1307. });
  1308. }
  1309. },
  1310. "click .delete-room": function(){
  1311. var typeDel = $(this)[0].type;
  1312. Meteor.call("deleteRoom", typeDel);
  1313. }
  1314. });
  1315. Template.queues.events({
  1316. "click .preview-button": function(e){
  1317. Session.set("song", this);
  1318. },
  1319. "click #previewImageButton": function() {
  1320. $("#preview-image").attr("src", Session.get("song").img);
  1321. },
  1322. "click .edit-queue-button": function(e){
  1323. Session.set("song", this);
  1324. Session.set("genre", $(e.target).data("genre"));
  1325. Session.set("type", "queue");
  1326. $("#type").val(this.type);
  1327. $("#mid").val(this.mid);
  1328. $("#artist").val(this.artist);
  1329. $("#title").val(this.title);
  1330. $("#img").val(this.img);
  1331. $("#id").val(this.id);
  1332. $("#likes").val(this.likes);
  1333. $("#dislikes").val(this.dislikes);
  1334. $("#duration").val(this.duration);
  1335. $("#skip-duration").val(this.skipDuration);
  1336. },
  1337. "click .add-song-button": function(e){
  1338. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1339. Meteor.call("addSongToPlaylist", genre, this);
  1340. },
  1341. "click .deny-song-button": function(e){
  1342. var genre = $(e.target).data("genre") || $(e.target).parent().data("genre");
  1343. Meteor.call("removeSongFromQueue", genre, this.mid);
  1344. },
  1345. "click #play": function() {
  1346. $("#play").attr("disabled", true);
  1347. $("#stop").attr("disabled", false);
  1348. var song = Session.get("song");
  1349. var id = song.id;
  1350. var type = song.type;
  1351. var volume = localStorage.getItem("volume") || 20;
  1352. if (type === "YouTube") {
  1353. if (yt_player === undefined) {
  1354. yt_player = new YT.Player("previewPlayer", {
  1355. height: 540,
  1356. width: 568,
  1357. videoId: id,
  1358. playerVars: {autoplay: 1, controls: 0, iv_load_policy: 3, showinfo: 0},
  1359. events: {
  1360. 'onReady': function(event) {
  1361. event.target.seekTo(Number(song.skipDuration));
  1362. event.target.playVideo();
  1363. event.target.setVolume(volume);
  1364. },
  1365. 'onStateChange': function(event){
  1366. if (event.data == YT.PlayerState.PAUSED) {
  1367. event.target.playVideo();
  1368. }
  1369. if (event.data == YT.PlayerState.PLAYING) {
  1370. $("#play").attr("disabled", true);
  1371. $("#stop").attr("disabled", false);
  1372. } else {
  1373. $("#play").attr("disabled", false);
  1374. $("#stop").attr("disabled", true);
  1375. }
  1376. }
  1377. }
  1378. });
  1379. } else {
  1380. yt_player.loadVideoById(id);
  1381. yt_player.seekTo(Number(song.skipDuration));
  1382. }
  1383. $("#previewPlayer").show();
  1384. } else if (type === "SoundCloud") {
  1385. SC.stream("/tracks/" + song.id, function(sound) {
  1386. _sound = sound;
  1387. sound.setVolume(volume / 100);
  1388. sound.play();
  1389. });
  1390. }
  1391. if (previewEndSongTimeout !== undefined) {
  1392. Meteor.clearTimeout(previewEndSongTimeout);
  1393. }
  1394. previewEndSongTimeout = Meteor.setTimeout(function() {
  1395. if (yt_player !== undefined) {
  1396. yt_player.stopVideo();
  1397. }
  1398. if (_sound !== undefined) {
  1399. _sound.stop();
  1400. }
  1401. $("#play").attr("disabled", false);
  1402. $("#stop").attr("disabled", true);
  1403. $("#previewPlayer").hide();
  1404. }, song.duration * 1000);
  1405. },
  1406. "click #stop": function() {
  1407. $("#play").attr("disabled", false);
  1408. $("#stop").attr("disabled", true);
  1409. if (previewEndSongTimeout !== undefined) {
  1410. Meteor.clearTimeout(previewEndSongTimeout);
  1411. }
  1412. if (yt_player !== undefined) {
  1413. yt_player.stopVideo();
  1414. }
  1415. if (_sound !== undefined) {
  1416. _sound.stop();
  1417. }
  1418. },
  1419. "click #forward": function() {
  1420. var error = false;
  1421. if (yt_player !== undefined) {
  1422. var duration = Number(Session.get("song").duration) | 0;
  1423. var skipDuration = Number(Session.get("song").skipDuration) | 0;
  1424. if (yt_player.getDuration() < duration + skipDuration) {
  1425. alert("The duration of the YouTube video is smaller than the duration.");
  1426. error = true;
  1427. } else {
  1428. yt_player.seekTo(skipDuration + duration - 10);
  1429. }
  1430. }
  1431. if (_sound !== undefined) {
  1432. _sound.seekTo((skipDuration + duration - 10) * 1000);
  1433. }
  1434. if (!error) {
  1435. if (previewEndSongTimeout !== undefined) {
  1436. Meteor.clearTimeout(previewEndSongTimeout);
  1437. }
  1438. previewEndSongTimeout = Meteor.setTimeout(function() {
  1439. if (yt_player !== undefined) {
  1440. yt_player.stopVideo();
  1441. }
  1442. if (_sound !== undefined) {
  1443. _sound.stop();
  1444. }
  1445. $("#play").attr("disabled", false);
  1446. $("#stop").attr("disabled", true);
  1447. $("#previewPlayer").hide();
  1448. }, 10000);
  1449. }
  1450. },
  1451. "click #get-spotify-info": function() {
  1452. var search = $("#title").val();
  1453. var artistName = $("#artist").val();
  1454. getSpotifyInfo(search, function(data) {
  1455. for(var i in data){
  1456. for(var j in data[i].items){
  1457. if(search.indexOf(data[i].items[j].name) !== -1 && artistName.indexOf(data[i].items[j].artists[0].name) !== -1){
  1458. $("#img").val(data[i].items[j].album.images[1].url);
  1459. $("#duration").val(data[i].items[j].duration_ms / 1000);
  1460. return;
  1461. }
  1462. }
  1463. }
  1464. }, artistName);
  1465. },
  1466. "click #save-song-button": function() {
  1467. var newSong = {};
  1468. newSong.id = $("#id").val();
  1469. newSong.likes = Number($("#likes").val());
  1470. newSong.dislikes = Number($("#dislikes").val());
  1471. newSong.title = $("#title").val();
  1472. newSong.artist = $("#artist").val();
  1473. newSong.img = $("#img").val();
  1474. newSong.type = $("#type").val();
  1475. newSong.duration = Number($("#duration").val());
  1476. newSong.skipDuration = $("#skip-duration").val();
  1477. if(newSong.skipDuration === undefined){
  1478. newSong.skipDuration = 0;
  1479. };
  1480. if (Session.get("type") === "playlist") {
  1481. Meteor.call("updatePlaylistSong", Session.get("genre"), Session.get("song"), newSong, function() {
  1482. $('#editModal').modal('hide');
  1483. });
  1484. } else {
  1485. Meteor.call("updateQueueSong", Session.get("genre"), Session.get("song"), newSong, function() {
  1486. $('#editModal').modal('hide');
  1487. });
  1488. }
  1489. }
  1490. });
  1491. Template.stations.onCreated(function() {
  1492. var tag = document.createElement("script");
  1493. tag.src = "https://www.youtube.com/iframe_api";
  1494. var firstScriptTag = document.getElementsByTagName('script')[0];
  1495. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  1496. yt_player = undefined;
  1497. _sound = undefined;
  1498. });
  1499. Template.queues.onCreated(function() {
  1500. var tag = document.createElement("script");
  1501. tag.src = "https://www.youtube.com/iframe_api";
  1502. var firstScriptTag = document.getElementsByTagName('script')[0];
  1503. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  1504. yt_player = undefined;
  1505. _sound = undefined;
  1506. });
  1507. Template.stations.onRendered(function() {
  1508. $("#previewModal").on("hidden.bs.modal", function() {
  1509. if (previewEndSongTimeout !== undefined) {
  1510. Meteor.clearTimeout(previewEndSongTimeout);
  1511. }
  1512. $("#play").attr("disabled", false);
  1513. $("#stop").attr("disabled", true);
  1514. if (yt_player !== undefined) {
  1515. $("#previewPlayer").hide();
  1516. yt_player.seekTo(0);
  1517. yt_player.stopVideo();
  1518. }
  1519. if (_sound !== undefined) {
  1520. _sound.stop();
  1521. }
  1522. });
  1523. $(document).ready(function() {
  1524. function makeSlider(){
  1525. var slider = $("#volume-slider").slider();
  1526. var volume = localStorage.getItem("volume") || 20;
  1527. $("#volume-slider").slider("setValue", volume);
  1528. if (slider.length === 0) {
  1529. Meteor.setTimeout(function() {
  1530. makeSlider();
  1531. }, 500);
  1532. } else {
  1533. slider.on("slide", function(val) {
  1534. localStorage.setItem("volume", val.value);
  1535. if (yt_player !== undefined) {
  1536. yt_player.setVolume(val.value);
  1537. } else if (_sound !== undefined) {
  1538. var volume = val.value / 100;
  1539. _sound.setVolume(volume);
  1540. }
  1541. });
  1542. }
  1543. }
  1544. makeSlider();
  1545. });
  1546. });
  1547. Template.queues.onRendered(function() {
  1548. $("#previewModal").on("hidden.bs.modal", function() {
  1549. if (previewEndSongTimeout !== undefined) {
  1550. Meteor.clearTimeout(previewEndSongTimeout);
  1551. }
  1552. $("#play").attr("disabled", false);
  1553. $("#stop").attr("disabled", true);
  1554. if (yt_player !== undefined) {
  1555. $("#previewPlayer").hide();
  1556. yt_player.seekTo(0);
  1557. yt_player.stopVideo();
  1558. }
  1559. if (_sound !== undefined) {
  1560. _sound.stop();
  1561. }
  1562. });
  1563. $(document).ready(function() {
  1564. function makeSlider(){
  1565. var slider = $("#volume-slider").slider();
  1566. var volume = localStorage.getItem("volume") || 20;
  1567. $("#volume-slider").slider("setValue", volume);
  1568. if (slider.length === 0) {
  1569. Meteor.setTimeout(function() {
  1570. makeSlider();
  1571. }, 500);
  1572. } else {
  1573. slider.on("slide", function(val) {
  1574. localStorage.setItem("volume", val.value);
  1575. if (yt_player !== undefined) {
  1576. yt_player.setVolume(val.value);
  1577. } else if (_sound !== undefined) {
  1578. var volume = val.value / 100;
  1579. _sound.setVolume(volume);
  1580. }
  1581. });
  1582. }
  1583. }
  1584. makeSlider();
  1585. });
  1586. });
  1587. Template.playlist.helpers({
  1588. playlist_songs: function() {
  1589. parts = location.href.split('/');
  1590. id = parts.pop();
  1591. type = id.toLowerCase();
  1592. var data = Playlists.findOne({type: type});
  1593. if (data !== undefined) {
  1594. data.songs.map(function(song) {
  1595. if (Session.get("currentSong") !== undefined && song.mid === Session.get("currentSong").mid) {
  1596. song.current = true;
  1597. } else {
  1598. song.current = false;
  1599. }
  1600. return song;
  1601. });
  1602. return data.songs;
  1603. } else {
  1604. return [];
  1605. }
  1606. }
  1607. });
  1608. Template.playlist.events({
  1609. "keyup #search-playlist": function(){
  1610. if($("#search-playlist").val().length === 0){
  1611. $(".pl-item").show();
  1612. } else {
  1613. $(".pl-item").hide();
  1614. var input = $("#search-playlist").val().toLowerCase();
  1615. $(".pl-item strong").each(function(i, el){
  1616. if($(el).text().toLowerCase().indexOf(input) !== -1){
  1617. $(el).parent(".pl-item").show();
  1618. }
  1619. })
  1620. $(".pl-item #pl-artist").each(function(i, el){
  1621. if($(el).text().toLowerCase().indexOf(input) !== -1){
  1622. $(el).parent(".pl-item").show();
  1623. }
  1624. })
  1625. }
  1626. },
  1627. "click #pl-item": function(){
  1628. console.log($(this).text());
  1629. }
  1630. })
  1631. Meteor.subscribe("rooms");
  1632. Template.room.onCreated(function () {
  1633. Chat.after.find(function() {
  1634. if (!$("#chat-tab").hasClass("active")) {
  1635. $("#chat-tab").addClass("unread-messages");
  1636. }
  1637. });
  1638. Session.set("reportSong", false);
  1639. Session.set("reportTitle", false);
  1640. Session.set("reportAuthor", false);
  1641. Session.set("reportDuration", false);
  1642. Session.set("reportAudio", false);
  1643. Session.set("reportAlbumart", false);
  1644. Session.set("reportOther", false);
  1645. if (resizeSeekerbarInterval !== undefined) {
  1646. Meteor.clearInterval(resizeSeekerbarInterval);
  1647. resizeSeekerbarInterval = undefined;
  1648. }
  1649. yt_player = undefined;
  1650. _sound = undefined;
  1651. Session.set("videoHidden", false);
  1652. var tag = document.createElement("script");
  1653. tag.src = "https://www.youtube.com/iframe_api";
  1654. var firstScriptTag = document.getElementsByTagName('script')[0];
  1655. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  1656. var currentSong = undefined;
  1657. var currentSongR = undefined;
  1658. function getTimeElapsed() {
  1659. if (currentSong !== undefined) {
  1660. var room = Rooms.findOne({type: type});
  1661. if (room !== undefined) {
  1662. return Date.now() - currentSong.started - room.timePaused;
  1663. }
  1664. }
  1665. return 0;
  1666. }
  1667. function getSongInfo(songData){
  1668. Session.set("title", songData.title);
  1669. Session.set("artist", songData.artist);
  1670. Session.set("id", songData.id);
  1671. $("#song-img").attr("src", songData.img);
  1672. Session.set("duration", parseInt(songData.duration));
  1673. var d = moment.duration(parseInt(songData.duration), 'seconds');
  1674. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  1675. Session.set("timeFormat", d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  1676. }
  1677. function resizeSeekerbar() {
  1678. if (Session.get("state") === "playing") {
  1679. $("#seeker-bar").width(((getTimeElapsed() / 1000) / Session.get("duration") * 100) + "%");
  1680. }
  1681. }
  1682. function startSong() {
  1683. $("#time-elapsed").text("0:00");
  1684. $("#vote-skip").attr("disabled", false);
  1685. if (currentSong !== undefined) {
  1686. if (_sound !== undefined) _sound.stop();
  1687. if (yt_player !== undefined && yt_player.stopVideo !== undefined) yt_player.stopVideo();
  1688. var volume = localStorage.getItem("volume") || 20;
  1689. if (currentSong.type === "SoundCloud") {
  1690. if ($("#soundcloud-image").length !== 1) {
  1691. //$("#media-container").append('<img alt="Not loading" src="/soundcloud-image.png" class="embed-responsive-item" id="soundcloud-image" />');
  1692. $("#media-container").append('<h1 id="soundcloud-image">We have temporarily disabled the playing of SoundCloud songs. We are sorry for this inconvenience.</h1>');
  1693. }
  1694. if ($("#player").length === 1) {
  1695. $("#player").hide();
  1696. }
  1697. $("#soundcloud-image").show();
  1698. //getSongInfo(currentSong);
  1699. /*SC.stream("/tracks/" + currentSong.id, function(sound){
  1700. _sound = sound;
  1701. sound.setVolume(volume / 100);
  1702. sound.play();
  1703. var interval = setInterval(function() {
  1704. if (sound.getState() === "playing") {
  1705. sound.seek(getTimeElapsed());
  1706. window.clearInterval(interval);
  1707. }
  1708. }, 200);
  1709. Session.set("duration", parseInt(currentSong.duration));
  1710. var d = moment.duration(parseInt(currentSong.duration), 'seconds');
  1711. $("#time-total").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  1712. resizeSeekerbar();
  1713. });*/
  1714. } else {
  1715. if ($("#player").length !== 1) {
  1716. $("#media-container").append('<div id="player" class="embed-responsive-item"></div>');
  1717. }
  1718. if ($("#soundcloud-image").length === 1) {
  1719. $("#soundcloud-image").hide();
  1720. }
  1721. $("#player").show();
  1722. function loadVideo() {
  1723. if (YT.loaded === 0 && YT.loading === 1) {
  1724. Session.set("loadVideoTimeout", Meteor.setTimeout(function() {
  1725. loadVideo();
  1726. }, 500));
  1727. } else {
  1728. if (yt_player === undefined) {
  1729. yt_player = new YT.Player("player", {
  1730. height: 540,
  1731. width: 960,
  1732. videoId: currentSong.id,
  1733. playerVars: {controls: 0, iv_load_policy: 3, rel: 0, showinfo: 0},
  1734. events: {
  1735. 'onReady': function(event) {
  1736. if(currentSong.skipDuration === undefined){
  1737. currentSong.skipDuration = 0;
  1738. }
  1739. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  1740. event.target.playVideo();
  1741. event.target.setVolume(volume);
  1742. resizeSeekerbar();
  1743. },
  1744. 'onStateChange': function(event){
  1745. if (YT !== undefined) {
  1746. if (event.data == YT.PlayerState.PAUSED && Session.get("state") === "playing") {
  1747. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  1748. event.target.playVideo();
  1749. }
  1750. if (event.data == YT.PlayerState.PLAYING && Session.get("state") === "paused") {
  1751. event.target.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  1752. event.target.pauseVideo();
  1753. }
  1754. }
  1755. }
  1756. }
  1757. });
  1758. } else {
  1759. yt_player.loadVideoById(currentSong.id);
  1760. if(currentSong.skipDuration === undefined){
  1761. currentSong.skipDuration = 0;
  1762. }
  1763. yt_player.seekTo(Number(currentSong.skipDuration) + getTimeElapsed() / 1000);
  1764. }
  1765. Session.set("pauseVideo", false);
  1766. getSongInfo(currentSong);
  1767. }
  1768. };
  1769. loadVideo();
  1770. }
  1771. }
  1772. }
  1773. Session.set("loaded", false);
  1774. Meteor.subscribe("rooms", function() {
  1775. var parts = location.href.split('/');
  1776. var id = parts.pop();
  1777. var type = id.toLowerCase();
  1778. Session.set("type", type);
  1779. if (Rooms.find({type: type}).count() !== 1) {
  1780. window.location = "/";
  1781. } else {
  1782. station_c = Meteor.subscribe(type);
  1783. Session.set("loaded", true);
  1784. minterval = Meteor.setInterval(function () {
  1785. var room = Rooms.findOne({type: type});
  1786. if (room !== undefined) {
  1787. if (room.state === "paused" || Session.get("pauseVideo")) {
  1788. Session.set("state", "paused");
  1789. // TODO Fix issue where sometimes nothing loads with the YT is not defined error. The error points to around this.
  1790. if (yt_player !== undefined && yt_player.getPlayerState !== undefined && yt_player.getPlayerState() === 1) {
  1791. yt_player.pauseVideo();
  1792. } else if (_sound !== undefined && _sound.getState().indexOf("playing") !== -1) {
  1793. _sound.pause();
  1794. }
  1795. } else {
  1796. Session.set("state", "playing");
  1797. if (yt_player !== undefined && yt_player.getPlayerState !== undefined && yt_player.getPlayerState() !== 1) {
  1798. yt_player.playVideo();
  1799. } else if (_sound !== undefined && _sound.getState().indexOf("paused") !== -1) {
  1800. _sound.play();
  1801. }
  1802. }
  1803. }
  1804. if (currentSongR === undefined || room.currentSong.started !== currentSongR.started) {
  1805. Session.set("previousSong", currentSong);
  1806. currentSongR = room.currentSong;
  1807. currentSong = room.currentSong.song;
  1808. currentSong.started = room.currentSong.started;
  1809. Session.set("currentSong", currentSong);
  1810. Meteor.clearTimeout(Session.get("loadVideoTimeout"));
  1811. startSong();
  1812. }
  1813. if (currentSong !== undefined) {
  1814. if (room !== undefined) {
  1815. var duration = (Date.now() - currentSong.started - room.timePaused) / 1000;
  1816. var song_duration = currentSong.duration;
  1817. if (song_duration <= duration) {
  1818. Session.set("pauseVideo", true);
  1819. }
  1820. var d = moment.duration(duration, 'seconds');
  1821. if (Session.get("state") === "playing") {
  1822. $("#time-elapsed").text(d.minutes() + ":" + ("0" + d.seconds()).slice(-2));
  1823. }
  1824. }
  1825. }
  1826. }, 100);
  1827. resizeSeekerbarInterval = Meteor.setInterval(function () {
  1828. resizeSeekerbar();
  1829. }, 500);
  1830. }
  1831. });
  1832. });