client.js 70 KB

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