server.js 23 KB

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