server.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. Meteor.startup(function() {
  2. reCAPTCHA.config({
  3. privatekey: '6LcVxg0TAAAAAI2fgIEEWHFxwNXeVIs8mzq5cfRM'
  4. });
  5. var stations = [{tag: "edm", display: "EDM"}, {tag: "pop", display: "Pop"}]; //Rooms to be set on server startup
  6. for(var i in stations){
  7. if(Rooms.find({type: stations[i]}).count() === 0){
  8. createRoom(stations[i].display, stations[i].tag);
  9. }
  10. }
  11. });
  12. var stations = [];
  13. var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_";
  14. function createUniqueSongId() {
  15. var code = "";
  16. for (var i = 0; i < 6; i++) {
  17. code += chars[Math.floor(Math.random() * chars.length)];
  18. }
  19. if (Playlists.find({"songs.mid": code}).count() > 0) {
  20. return createUniqueSongId();
  21. } else {
  22. return code;
  23. }
  24. }
  25. function getStation(type, cb) {
  26. stations.forEach(function(station) {
  27. if (station.type === type) {
  28. cb(station);
  29. return;
  30. }
  31. });
  32. }
  33. function createRoom(display, tag) {
  34. var type = tag;
  35. if (Rooms.find({type: type}).count() === 0) {
  36. Rooms.insert({display: display, type: type}, function(err) {
  37. if (err) {
  38. throw err;
  39. } else {
  40. if (Playlists.find({type: type}).count() === 1) {
  41. stations.push(new Station(type));
  42. } else {
  43. Playlists.insert({type: type, songs: getSongsByType(type)}, function (err2) {
  44. if (err2) {
  45. throw err2;
  46. } else {
  47. stations.push(new Station(type));
  48. }
  49. });
  50. }
  51. }
  52. });
  53. } else {
  54. return "Room already exists";
  55. }
  56. }
  57. function Station(type) {
  58. var _this = this;
  59. var startedAt = Date.now();
  60. var playlist = Playlists.findOne({type: type});
  61. var songs = playlist.songs;
  62. if (playlist.lastSong === undefined) {
  63. Playlists.update({type: type}, {$set: {lastSong: 0}});
  64. playlist = Playlists.findOne({type: type});
  65. songs = playlist.songs;
  66. }
  67. var currentSong = playlist.lastSong;
  68. if (currentSong < (songs.length - 1)) {
  69. currentSong++;
  70. } else currentSong = 0;
  71. var currentTitle = songs[currentSong].title;
  72. Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}}});
  73. this.skipSong = function() {
  74. songs = Playlists.findOne({type: type}).songs;
  75. songs.forEach(function(song, index) {
  76. if (song.title === currentTitle) {
  77. currentSong = index;
  78. }
  79. });
  80. if (currentSong < (songs.length - 1)) {
  81. currentSong++;
  82. } else currentSong = 0;
  83. if (songs);
  84. if (currentSong === 0) {
  85. this.shufflePlaylist();
  86. } else {
  87. if (songs[currentSong].mid === undefined) {
  88. var newSong = songs[currentSong];
  89. newSong.mid = createUniqueSongId();
  90. songs[currentSong].mid = newSong.mid;
  91. Playlists.update({type: type, "songs": songs[currentSong]}, {$set: {"songs.$": newSong}});
  92. }
  93. if (songs[currentSong].likes === undefined) {
  94. var newSong = songs[currentSong];
  95. newSong.likes = 0;
  96. Playlists.update({type: type, "songs": newSong}, {$set: {"songs.$": newSong}});
  97. }
  98. if (songs[currentSong].dislikes === undefined) {
  99. var newSong = songs[currentSong];
  100. newSong.dislikes = 0;
  101. Playlists.update({type: type, "songs": newSong}, {$set: {"songs.$": newSong}});
  102. }
  103. currentTitle = songs[currentSong].title;
  104. Playlists.update({type: type}, {$set: {lastSong: currentSong}});
  105. Rooms.update({type: type}, {$set: {timePaused: 0}});
  106. this.songTimer();
  107. Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}}});
  108. }
  109. };
  110. this.shufflePlaylist = function() {
  111. songs = Playlists.findOne({type: type}).songs;
  112. currentSong = 0;
  113. Playlists.update({type: type}, {$set: {"songs": []}});
  114. songs = shuffle(songs);
  115. songs.forEach(function(song) {
  116. if (song.mid === undefined) {
  117. song.mid = createUniqueSongId();
  118. }
  119. if (song.likes === undefined) {
  120. song.likes = 0;
  121. }
  122. if (song.dislikes === undefined) {
  123. song.dislikes = 0;
  124. }
  125. Playlists.update({type: type}, {$push: {"songs": song}});
  126. });
  127. currentTitle = songs[currentSong].title;
  128. Playlists.update({type: type}, {$set: {lastSong: currentSong}});
  129. Rooms.update({type: type}, {$set: {timePaused: 0}});
  130. this.songTimer();
  131. Rooms.update({type: type}, {$set: {currentSong: {song: songs[currentSong], started: startedAt}}});
  132. };
  133. Rooms.update({type: type}, {$set: {timePaused: 0}});
  134. var timer;
  135. this.songTimer = function() {
  136. startedAt = Date.now();
  137. if (timer !== undefined) {
  138. timer.pause();
  139. }
  140. timer = new Timer(function() {
  141. _this.skipSong();
  142. }, songs[currentSong].duration * 1000);
  143. };
  144. var state = Rooms.findOne({type: type}).state;
  145. this.pauseRoom = function() {
  146. if (state !== "paused") {
  147. timer.pause();
  148. Rooms.update({type: type}, {$set: {state: "paused"}});
  149. state = "paused";
  150. }
  151. };
  152. this.resumeRoom = function() {
  153. if (state !== "playing") {
  154. timer.resume();
  155. Rooms.update({type: type}, {$set: {state: "playing", timePaused: timer.timeWhenPaused()}});
  156. state = "playing";
  157. }
  158. };
  159. this.cancelTimer = function() {
  160. timer.pause();
  161. };
  162. this.getState = function() {
  163. return state;
  164. };
  165. this.type = type;
  166. this.songTimer();
  167. }
  168. function shuffle(array) {
  169. var currentIndex = array.length, temporaryValue, randomIndex ;
  170. // While there remain elements to shuffle...
  171. while (0 !== currentIndex) {
  172. // Pick a remaining element...
  173. randomIndex = Math.floor(Math.random() * currentIndex);
  174. currentIndex -= 1;
  175. // And swap it with the current element.
  176. temporaryValue = array[currentIndex];
  177. array[currentIndex] = array[randomIndex];
  178. array[randomIndex] = temporaryValue;
  179. }
  180. return array;
  181. }
  182. function Timer(callback, delay) {
  183. var timerId, start, remaining = delay;
  184. var timeWhenPaused = 0;
  185. var timePaused = new Date();
  186. this.pause = function() {
  187. Meteor.clearTimeout(timerId);
  188. remaining -= new Date() - start;
  189. timePaused = new Date();
  190. };
  191. this.resume = function() {
  192. start = new Date();
  193. Meteor.clearTimeout(timerId);
  194. timerId = Meteor.setTimeout(callback, remaining);
  195. timeWhenPaused += new Date() - timePaused;
  196. };
  197. this.timeWhenPaused = function() {
  198. return timeWhenPaused;
  199. };
  200. this.resume();
  201. }
  202. Meteor.users.deny({update: function () { return true; }});
  203. Meteor.users.deny({insert: function () { return true; }});
  204. Meteor.users.deny({remove: function () { return true; }});
  205. function getSongDuration(query, artistName){
  206. var duration;
  207. var search = query;
  208. query = query.toLowerCase().split(" ").join("%20");
  209. var res = Meteor.http.get('https://api.spotify.com/v1/search?q=' + query + '&type=track');
  210. for(var i in res.data){
  211. for(var j in res.data[i].items){
  212. if(search.indexOf(res.data[i].items[j].name) !== -1 && artistName.indexOf(res.data[i].items[j].artists[0].name) !== -1){
  213. duration = res.data[i].items[j].duration_ms / 1000;
  214. return duration;
  215. }
  216. }
  217. }
  218. }
  219. function getSongAlbumArt(query, artistName){
  220. var albumart;
  221. var search = query;
  222. query = query.toLowerCase().split(" ").join("%20");
  223. var res = Meteor.http.get('https://api.spotify.com/v1/search?q=' + query + '&type=track');
  224. for(var i in res.data){
  225. for(var j in res.data[i].items){
  226. if(search.indexOf(res.data[i].items[j].name) !== -1 && artistName.indexOf(res.data[i].items[j].artists[0].name) !== -1){
  227. albumart = res.data[i].items[j].album.images[1].url
  228. return albumart;
  229. }
  230. }
  231. }
  232. }
  233. //var room_types = ["edm", "nightcore"];
  234. var songsArr = [];
  235. function getSongsByType(type) {
  236. if (type === "edm") {
  237. return [
  238. {id: "aE2GCa-_nyU", mid: "fh6_Gf", title: "Radioactive", duration: getSongDuration("Radioactive - Lindsey Stirling and Pentatonix", "Lindsey Stirling, Pentatonix"), artist: "Lindsey Stirling, Pentatonix", type: "YouTube", img: "https://i.scdn.co/image/62167a9007cef2e8ef13ab1d93019312b9b03655"},
  239. {id: "aHjpOzsQ9YI", mid: "goG88g", title: "Crystallize", artist: "Lindsey Stirling", duration: getSongDuration("Crystallize", "Lindsey Stirling"), type: "YouTube", img: "https://i.scdn.co/image/b0c1ccdd0cd7bcda741ccc1c3e036f4ed2e52312"}
  240. ];
  241. } else if (type === "nightcore") {
  242. return [{id: "f7RKOP87tt4", mid: "5pGGog", title: "Monster (DotEXE Remix)", duration: getSongDuration("Monster (DotEXE Remix)", "Meg & Dia"), artist: "Meg & Dia", type: "YouTube", img: "https://i.scdn.co/image/35ecdfba9c31a6c54ee4c73dcf1ad474c560cd00"}];
  243. } else {
  244. return [{id: "dQw4w9WgXcQ", mid: "6_fdr4", title: "Never Gonna Give You Up", duration: getSongDuration("Never Gonna Give You Up", "Rick Astley"), artist: "Rick Astley", type: "YouTube", img: "https://i.scdn.co/image/5246898e19195715e65e261899baba890a2c1ded"}];
  245. }
  246. }
  247. Rooms.find({}).fetch().forEach(function(room) {
  248. var type = room.type;
  249. if (Playlists.find({type: type}).count() === 0) {
  250. if (type === "edm") {
  251. Playlists.insert({type: type, songs: getSongsByType(type)});
  252. } else if (type === "nightcore") {
  253. Playlists.insert({type: type, songs: getSongsByType(type)});
  254. } else {
  255. Playlists.insert({type: type, songs: getSongsByType(type)});
  256. }
  257. }
  258. if (Playlists.findOne({type: type}).songs.length === 0) {
  259. // Add a global video to Playlist so it can proceed
  260. } else {
  261. stations.push(new Station(type));
  262. }
  263. });
  264. Accounts.validateNewUser(function(user) {
  265. var username;
  266. if (user.services) {
  267. if (user.services.github) {
  268. username = user.services.github.username;
  269. } else if (user.services.facebook) {
  270. username = user.services.facebook.first_name;
  271. } else if (user.services.password) {
  272. username = user.username;
  273. }
  274. }
  275. if (Meteor.users.find({"profile.usernameL": username.toLowerCase()}).count() !== 0) {
  276. throw new Meteor.Error(403, "An account with that username already exists.");
  277. } else {
  278. return true;
  279. }
  280. });
  281. Accounts.onCreateUser(function(options, user) {
  282. var username;
  283. if (user.services) {
  284. if (user.services.github) {
  285. username = user.services.github.username;
  286. } else if (user.services.facebook) {
  287. username = user.services.facebook.first_name;
  288. } else if (user.services.password) {
  289. username = user.username;
  290. }
  291. }
  292. user.profile = {username: username, usernameL: username.toLowerCase(), rank: "default", liked: [], disliked: []};
  293. return user;
  294. });
  295. ServiceConfiguration.configurations.remove({
  296. service: "facebook"
  297. });
  298. ServiceConfiguration.configurations.insert({
  299. service: "facebook",
  300. appId: "1496014310695890",
  301. secret: "9a039f254a08a1488c08bb0737dbd2a6"
  302. });
  303. ServiceConfiguration.configurations.remove({
  304. service: "github"
  305. });
  306. ServiceConfiguration.configurations.insert({
  307. service: "github",
  308. clientId: "dcecd720f47c0e4001f7",
  309. secret: "375939d001ef1a0ca67c11dbf8fb9aeaa551e01b"
  310. });
  311. Meteor.publish("playlists", function() {
  312. return Playlists.find({})
  313. });
  314. Meteor.publish("rooms", function() {
  315. return Rooms.find({});
  316. });
  317. Meteor.publish("queues", function() {
  318. return Queues.find({});
  319. });
  320. Meteor.publish("chat", function() {
  321. return Chat.find({});
  322. });
  323. Meteor.publish("userProfiles", function() {
  324. return Meteor.users.find({}, {fields: {profile: 1, createdAt: 1}});
  325. });
  326. Meteor.publish("isAdmin", function() {
  327. return Meteor.users.find({_id: this.userId, "profile.rank": "admin"});
  328. });
  329. function isAdmin() {
  330. var userData = Meteor.users.find(Meteor.userId());
  331. if (Meteor.userId() && userData.count !== 0 && userData.fetch()[0].profile.rank === "admin") {
  332. return true;
  333. } else {
  334. return false;
  335. }
  336. }
  337. Meteor.methods({
  338. sendMessage: function(type, message) {
  339. if (Meteor.userId()) {
  340. var user = Meteor.user();
  341. var time = new Date();
  342. var username = user.profile.username;
  343. if (message.length === 0) {
  344. throw new Meteor.Error(406, "Message length cannot be 0.");
  345. }
  346. if (message.length > 300) {
  347. throw new Meteor.Error(406, "Message length cannot be more than 300 characters long..");
  348. }
  349. Chat.insert({type: type, message: message, time: time, username: username});
  350. return true;
  351. } else {
  352. throw new Meteor.Error(403, "Invalid permissions.");
  353. }
  354. },
  355. likeSong: function(mid) {
  356. if (Meteor.userId()) {
  357. var user = Meteor.user();
  358. if (user.profile.liked.indexOf(mid) === -1) {
  359. Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.liked": mid}});
  360. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": 1}})
  361. } else {
  362. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
  363. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}})
  364. }
  365. if (user.profile.disliked.indexOf(mid) !== -1) {
  366. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
  367. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}})
  368. }
  369. return true;
  370. } else {
  371. throw new Meteor.Error(403, "Invalid permissions.");
  372. }
  373. },
  374. dislikeSong: function(mid) {
  375. if (Meteor.userId()) {
  376. var user = Meteor.user();
  377. if (user.profile.disliked.indexOf(mid) === -1) {
  378. Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.disliked": mid}});
  379. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": 1}});
  380. } else {
  381. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
  382. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}});
  383. }
  384. if (user.profile.liked.indexOf(mid) !== -1) {
  385. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
  386. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}});
  387. }
  388. return true;
  389. } else {
  390. throw new Meteor.Error(403, "Invalid permissions.");
  391. }
  392. },
  393. submitReport: function(report, id) {
  394. var obj = report;
  395. obj.id = id;
  396. Reports.insert(obj);
  397. },
  398. shufflePlaylist: function(type) {
  399. if (isAdmin()) {
  400. getStation(type, function(station) {
  401. if (station === undefined) {
  402. throw new Meteor.Error(404, "Station not found.");
  403. } else {
  404. station.cancelTimer();
  405. station.shufflePlaylist();
  406. }
  407. });
  408. }
  409. },
  410. skipSong: function(type) {
  411. if (isAdmin()) {
  412. getStation(type, function(station) {
  413. if (station === undefined) {
  414. throw new Meteor.Error(404, "Station not found.");
  415. } else {
  416. station.skipSong();
  417. }
  418. });
  419. }
  420. },
  421. pauseRoom: function(type) {
  422. if (isAdmin()) {
  423. getStation(type, function(station) {
  424. if (station === undefined) {
  425. throw new Meteor.Error(403, "Room doesn't exist.");
  426. } else {
  427. station.pauseRoom();
  428. }
  429. });
  430. } else {
  431. throw new Meteor.Error(403, "Invalid permissions.");
  432. }
  433. },
  434. resumeRoom: function(type) {
  435. if (isAdmin()) {
  436. getStation(type, function(station) {
  437. if (station === undefined) {
  438. throw new Meteor.Error(403, "Room doesn't exist.");
  439. } else {
  440. station.resumeRoom();
  441. }
  442. });
  443. } else {
  444. throw new Meteor.Error(403, "Invalid permissions.");
  445. }
  446. },
  447. createUserMethod: function(formData, captchaData) {
  448. var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, captchaData);
  449. if (!verifyCaptchaResponse.success) {
  450. console.log('reCAPTCHA check failed!', verifyCaptchaResponse);
  451. throw new Meteor.Error(422, 'reCAPTCHA Failed: ' + verifyCaptchaResponse.error);
  452. } else {
  453. console.log('reCAPTCHA verification passed!');
  454. Accounts.createUser({
  455. username: formData.username,
  456. email: formData.email,
  457. password: formData.password
  458. });
  459. }
  460. return true;
  461. },
  462. addSongToQueue: function(type, songData) {
  463. if (Meteor.userId()) {
  464. type = type.toLowerCase();
  465. if (Rooms.find({type: type}).count() === 1) {
  466. if (Queues.find({type: type}).count() === 0) {
  467. Queues.insert({type: type, songs: []});
  468. }
  469. if (songData !== undefined && Object.keys(songData).length === 5 && songData.type !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.img !== undefined) {
  470. songData.duration = getSongDuration(songData.title, songData.artist);
  471. songData.img = getSongAlbumArt(songData.title, songData.artist);
  472. var mid = createUniqueSongId();
  473. if (mid !== undefined) {
  474. songData.mid = mid;
  475. Queues.update({type: type}, {
  476. $push: {
  477. songs: {
  478. id: songData.id,
  479. mid: songData.mid,
  480. title: songData.title,
  481. artist: songData.artist,
  482. duration: songData.duration,
  483. img: songData.img,
  484. type: songData.type
  485. }
  486. }
  487. });
  488. return true;
  489. } else {
  490. throw new Meteor.Error(500, "Am error occured.");
  491. }
  492. } else {
  493. throw new Meteor.Error(403, "Invalid data.");
  494. }
  495. } else {
  496. throw new Meteor.Error(403, "Invalid genre.");
  497. }
  498. } else {
  499. throw new Meteor.Error(403, "Invalid permissions.");
  500. }
  501. },
  502. updateQueueSong: function(genre, oldSong, newSong) {
  503. if (isAdmin()) {
  504. newSong.mid = oldSong.mid;
  505. Queues.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
  506. return true;
  507. } else {
  508. throw new Meteor.Error(403, "Invalid permissions.");
  509. }
  510. },
  511. updatePlaylistSong: function(genre, oldSong, newSong) {
  512. if (isAdmin()) {
  513. newSong.mid = oldSong.mid;
  514. Playlists.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
  515. return true;
  516. } else {
  517. throw new Meteor.Error(403, "Invalid permissions.");
  518. }
  519. },
  520. removeSongFromQueue: function(type, mid) {
  521. if (isAdmin()) {
  522. type = type.toLowerCase();
  523. Queues.update({type: type}, {$pull: {songs: {mid: mid}}});
  524. } else {
  525. throw new Meteor.Error(403, "Invalid permissions.");
  526. }
  527. },
  528. removeSongFromPlaylist: function(type, mid) {
  529. if (isAdmin()) {
  530. type = type.toLowerCase();
  531. Playlists.update({type: type}, {$pull: {songs: {mid: mid}}});
  532. } else {
  533. throw new Meteor.Error(403, "Invalid permissions.");
  534. }
  535. },
  536. addSongToPlaylist: function(type, songData) {
  537. if (isAdmin()) {
  538. type = type.toLowerCase();
  539. if (Rooms.find({type: type}).count() === 1) {
  540. if (Playlists.find({type: type}).count() === 0) {
  541. Playlists.insert({type: type, songs: []});
  542. }
  543. if (songData !== undefined && Object.keys(songData).length === 7 && songData.type !== undefined && songData.mid !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.duration !== undefined && songData.img !== undefined) {
  544. songData.likes = 0;
  545. songData.dislikes = 0
  546. Playlists.update({type: type}, {
  547. $push: {
  548. songs: {
  549. id: songData.id,
  550. mid: songData.mid,
  551. title: songData.title,
  552. artist: songData.artist,
  553. duration: songData.duration,
  554. img: songData.img,
  555. type: songData.type,
  556. likes: songData.likes,
  557. dislikes: songData.dislikes
  558. }
  559. }
  560. });
  561. Queues.update({type: type}, {$pull: {songs: {mid: songData.mid}}});
  562. return true;
  563. } else {
  564. throw new Meteor.Error(403, "Invalid data.");
  565. }
  566. } else {
  567. throw new Meteor.Error(403, "Invalid genre.");
  568. }
  569. } else {
  570. throw new Meteor.Error(403, "Invalid permissions.");
  571. }
  572. },
  573. createRoom: function(display, tag) {
  574. if (isAdmin()) {
  575. createRoom(display, tag);
  576. } else {
  577. throw new Meteor.Error(403, "Invalid permissions.");
  578. }
  579. },
  580. deleteRoom: function(type){
  581. if (isAdmin()) {
  582. Rooms.remove({type: type});
  583. Playlists.remove({type: type});
  584. Queues.remove({type: type});
  585. return true;
  586. } else {
  587. throw new Meteor.Error(403, "Invalid permissions.");
  588. }
  589. },
  590. getUserNum: function(){
  591. return Object.keys(Meteor.default_server.sessions).length;
  592. }
  593. });