server.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. var rank = user.profile.rank;
  344. if (message.length === 0) {
  345. throw new Meteor.Error(406, "Message length cannot be 0.");
  346. }
  347. if (message.length > 300) {
  348. throw new Meteor.Error(406, "Message length cannot be more than 300 characters long..");
  349. }
  350. Chat.insert({type: type, rank: rank, message: message, time: time, username: username});
  351. return true;
  352. } else {
  353. throw new Meteor.Error(403, "Invalid permissions.");
  354. }
  355. },
  356. likeSong: function(mid) {
  357. if (Meteor.userId()) {
  358. var user = Meteor.user();
  359. if (user.profile.liked.indexOf(mid) === -1) {
  360. Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.liked": mid}});
  361. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": 1}})
  362. } else {
  363. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
  364. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}})
  365. }
  366. if (user.profile.disliked.indexOf(mid) !== -1) {
  367. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
  368. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}})
  369. }
  370. return true;
  371. } else {
  372. throw new Meteor.Error(403, "Invalid permissions.");
  373. }
  374. },
  375. dislikeSong: function(mid) {
  376. if (Meteor.userId()) {
  377. var user = Meteor.user();
  378. if (user.profile.disliked.indexOf(mid) === -1) {
  379. Meteor.users.update({"profile.username": user.profile.username}, {$push: {"profile.disliked": mid}});
  380. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": 1}});
  381. } else {
  382. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.disliked": mid}});
  383. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.dislikes": -1}});
  384. }
  385. if (user.profile.liked.indexOf(mid) !== -1) {
  386. Meteor.users.update({"profile.username": user.profile.username}, {$pull: {"profile.liked": mid}});
  387. Playlists.update({"songs.mid": mid}, {$inc: {"songs.$.likes": -1}});
  388. }
  389. return true;
  390. } else {
  391. throw new Meteor.Error(403, "Invalid permissions.");
  392. }
  393. },
  394. submitReport: function(report, id) {
  395. var obj = report;
  396. obj.id = id;
  397. Reports.insert(obj);
  398. },
  399. shufflePlaylist: function(type) {
  400. if (isAdmin()) {
  401. getStation(type, function(station) {
  402. if (station === undefined) {
  403. throw new Meteor.Error(404, "Station not found.");
  404. } else {
  405. station.cancelTimer();
  406. station.shufflePlaylist();
  407. }
  408. });
  409. }
  410. },
  411. skipSong: function(type) {
  412. if (isAdmin()) {
  413. getStation(type, function(station) {
  414. if (station === undefined) {
  415. throw new Meteor.Error(404, "Station not found.");
  416. } else {
  417. station.skipSong();
  418. }
  419. });
  420. }
  421. },
  422. pauseRoom: function(type) {
  423. if (isAdmin()) {
  424. getStation(type, function(station) {
  425. if (station === undefined) {
  426. throw new Meteor.Error(403, "Room doesn't exist.");
  427. } else {
  428. station.pauseRoom();
  429. }
  430. });
  431. } else {
  432. throw new Meteor.Error(403, "Invalid permissions.");
  433. }
  434. },
  435. resumeRoom: function(type) {
  436. if (isAdmin()) {
  437. getStation(type, function(station) {
  438. if (station === undefined) {
  439. throw new Meteor.Error(403, "Room doesn't exist.");
  440. } else {
  441. station.resumeRoom();
  442. }
  443. });
  444. } else {
  445. throw new Meteor.Error(403, "Invalid permissions.");
  446. }
  447. },
  448. createUserMethod: function(formData, captchaData) {
  449. var verifyCaptchaResponse = reCAPTCHA.verifyCaptcha(this.connection.clientAddress, captchaData);
  450. if (!verifyCaptchaResponse.success) {
  451. console.log('reCAPTCHA check failed!', verifyCaptchaResponse);
  452. throw new Meteor.Error(422, 'reCAPTCHA Failed: ' + verifyCaptchaResponse.error);
  453. } else {
  454. console.log('reCAPTCHA verification passed!');
  455. Accounts.createUser({
  456. username: formData.username,
  457. email: formData.email,
  458. password: formData.password
  459. });
  460. }
  461. return true;
  462. },
  463. addSongToQueue: function(type, songData) {
  464. if (Meteor.userId()) {
  465. type = type.toLowerCase();
  466. if (Rooms.find({type: type}).count() === 1) {
  467. if (Queues.find({type: type}).count() === 0) {
  468. Queues.insert({type: type, songs: []});
  469. }
  470. if (songData !== undefined && Object.keys(songData).length === 5 && songData.type !== undefined && songData.title !== undefined && songData.title !== undefined && songData.artist !== undefined && songData.img !== undefined) {
  471. songData.duration = getSongDuration(songData.title, songData.artist);
  472. songData.img = getSongAlbumArt(songData.title, songData.artist);
  473. var mid = createUniqueSongId();
  474. if (mid !== undefined) {
  475. songData.mid = mid;
  476. Queues.update({type: type}, {
  477. $push: {
  478. songs: {
  479. id: songData.id,
  480. mid: songData.mid,
  481. title: songData.title,
  482. artist: songData.artist,
  483. duration: songData.duration,
  484. img: songData.img,
  485. type: songData.type
  486. }
  487. }
  488. });
  489. return true;
  490. } else {
  491. throw new Meteor.Error(500, "Am error occured.");
  492. }
  493. } else {
  494. throw new Meteor.Error(403, "Invalid data.");
  495. }
  496. } else {
  497. throw new Meteor.Error(403, "Invalid genre.");
  498. }
  499. } else {
  500. throw new Meteor.Error(403, "Invalid permissions.");
  501. }
  502. },
  503. updateQueueSong: function(genre, oldSong, newSong) {
  504. if (isAdmin()) {
  505. newSong.mid = oldSong.mid;
  506. Queues.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
  507. return true;
  508. } else {
  509. throw new Meteor.Error(403, "Invalid permissions.");
  510. }
  511. },
  512. updatePlaylistSong: function(genre, oldSong, newSong) {
  513. if (isAdmin()) {
  514. newSong.mid = oldSong.mid;
  515. Playlists.update({type: genre, "songs": oldSong}, {$set: {"songs.$": newSong}});
  516. return true;
  517. } else {
  518. throw new Meteor.Error(403, "Invalid permissions.");
  519. }
  520. },
  521. removeSongFromQueue: function(type, mid) {
  522. if (isAdmin()) {
  523. type = type.toLowerCase();
  524. Queues.update({type: type}, {$pull: {songs: {mid: mid}}});
  525. } else {
  526. throw new Meteor.Error(403, "Invalid permissions.");
  527. }
  528. },
  529. removeSongFromPlaylist: function(type, mid) {
  530. if (isAdmin()) {
  531. type = type.toLowerCase();
  532. Playlists.update({type: type}, {$pull: {songs: {mid: mid}}});
  533. } else {
  534. throw new Meteor.Error(403, "Invalid permissions.");
  535. }
  536. },
  537. addSongToPlaylist: function(type, songData) {
  538. if (isAdmin()) {
  539. type = type.toLowerCase();
  540. if (Rooms.find({type: type}).count() === 1) {
  541. if (Playlists.find({type: type}).count() === 0) {
  542. Playlists.insert({type: type, songs: []});
  543. }
  544. 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) {
  545. songData.likes = 0;
  546. songData.dislikes = 0
  547. Playlists.update({type: type}, {
  548. $push: {
  549. songs: {
  550. id: songData.id,
  551. mid: songData.mid,
  552. title: songData.title,
  553. artist: songData.artist,
  554. duration: songData.duration,
  555. img: songData.img,
  556. type: songData.type,
  557. likes: songData.likes,
  558. dislikes: songData.dislikes
  559. }
  560. }
  561. });
  562. Queues.update({type: type}, {$pull: {songs: {mid: songData.mid}}});
  563. return true;
  564. } else {
  565. throw new Meteor.Error(403, "Invalid data.");
  566. }
  567. } else {
  568. throw new Meteor.Error(403, "Invalid genre.");
  569. }
  570. } else {
  571. throw new Meteor.Error(403, "Invalid permissions.");
  572. }
  573. },
  574. createRoom: function(display, tag) {
  575. if (isAdmin()) {
  576. createRoom(display, tag);
  577. } else {
  578. throw new Meteor.Error(403, "Invalid permissions.");
  579. }
  580. },
  581. deleteRoom: function(type){
  582. if (isAdmin()) {
  583. Rooms.remove({type: type});
  584. Playlists.remove({type: type});
  585. Queues.remove({type: type});
  586. return true;
  587. } else {
  588. throw new Meteor.Error(403, "Invalid permissions.");
  589. }
  590. },
  591. getUserNum: function(){
  592. return Object.keys(Meteor.default_server.sessions).length;
  593. }
  594. });