main.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. window.onload = function () {
  2. var socket = io();
  3. socket.on('disconnect', function () {
  4. console.log('Disconnected from server');
  5. });
  6. socket.on('search', function (res) {
  7. console.log(res);
  8. });
  9. var data = {
  10. user: {
  11. id: null
  12. },
  13. modals: {
  14. register: {
  15. visible: false,
  16. email: "",
  17. username: "",
  18. password: ""
  19. },
  20. account: {
  21. visible: false
  22. },
  23. donate: {
  24. visible: false
  25. },
  26. project: {
  27. visible: false
  28. }
  29. },
  30. home: {
  31. visible: false,
  32. groups: [
  33. {
  34. id: "lu08gw56571r4497wrk9",
  35. name: "Official Rooms",
  36. rooms: [
  37. { id: "73qvw65746acvo8yqfr", thumbnail: "https://lh6.googleusercontent.com/-ghASz3s6yL4/AAAAAAAAAAI/AAAAAAAAALc/tFblPp2myu0/s0-c-k-no-ns/photo.jpg", name: "Country", description: "Johnny Cash - I Walk The Line", users: 10 },
  38. { id: "enxcysmhn1k7ld56ogvi", thumbnail: "http://66.media.tumblr.com/1734069af425e491fae7deae0a19869f/tumblr_o0i0xmIYrF1v421f2o1_1280.jpg", name: "Pop", description: "Sia - Cheap Thrills", users: 14 },
  39. { id: "kqa99gbva7lij05dn29", thumbnail: "http://www.youredm.com/wp-content/uploads/2014/09/taking-you-higher.jpg", name: "Chill", description: "MrSuicideSheep - Taking you higher", users: 13 },
  40. { id: "w19hu791iiub6wmjf9a4i", thumbnail: "http://edmsauce.wpengine.netdna-cdn.com/wp-content/uploads/2012/12/Deadmau5-album-title-goes-here.jpg", name: "EDM", description: "Deadmau5 - There Might Be Coffee", users: 13 }
  41. ]
  42. },
  43. {
  44. id: "g2b8v03xaedj8ht1emi",
  45. name: "Trending Rooms",
  46. rooms: [
  47. { id: "73qvw65746acvo8yqfr", thumbnail: "https://lh6.googleusercontent.com/-ghASz3s6yL4/AAAAAAAAAAI/AAAAAAAAALc/tFblPp2myu0/s0-c-k-no-ns/photo.jpg", name: "Country", description: "Johnny Cash - I Walk The Line", users: 10 },
  48. { id: "enxcysmhn1k7ld56ogvi", thumbnail: "http://66.media.tumblr.com/1734069af425e491fae7deae0a19869f/tumblr_o0i0xmIYrF1v421f2o1_1280.jpg", name: "Pop", description: "Sia - Cheap Thrills", users: 14 },
  49. { id: "kqa99gbva7lij05dn29", thumbnail: "http://www.youredm.com/wp-content/uploads/2014/09/taking-you-higher.jpg", name: "Chill", description: "MrSuicideSheep - Taking you higher", users: 13 },
  50. { id: "w19hu791iiub6wmjf9a4i", thumbnail: "http://edmsauce.wpengine.netdna-cdn.com/wp-content/uploads/2012/12/Deadmau5-album-title-goes-here.jpg", name: "EDM", description: "Deadmau5 - There Might Be Coffee", users: 13 }
  51. ]
  52. }
  53. ]
  54. },
  55. room: {
  56. visible: false,
  57. id: "",
  58. name: "",
  59. description: "",
  60. player: {
  61. },
  62. chat: {
  63. visible: false,
  64. messages: []
  65. },
  66. users: {
  67. list: {}
  68. },
  69. playlist: {
  70. visible: false,
  71. messages: []
  72. }
  73. }
  74. };
  75. var methods = {
  76. leaveRoom: function () {
  77. data.room.visible = false;
  78. window.setTimeout(function () { data.home.visible = true; }, 500);
  79. socket.leave("/" + data.room.id);
  80. },
  81. enterRoom: function (room) {
  82. data.home.visible = false;
  83. window.setTimeout(function () { data.room.visible = true; }, 500);
  84. data.room.id = room.id;
  85. data.room.displayName = room.displayName;
  86. data.room.description = room.description;
  87. socket.join("/" + room.id);
  88. socket.emit("/stations/join/:id", room.id, function(result) {
  89. console.log(result);
  90. });
  91. },
  92. modalVisibilityChange: function (name) {
  93. var modal = data.modals[name];
  94. if (modal) {
  95. switch (name) {
  96. case 'register': {
  97. data.modals.register.email = "";
  98. data.modals.register.username = "";
  99. data.modals.register.password = "";
  100. grecaptcha.reset();
  101. } break;
  102. }
  103. }
  104. },
  105. showModal: function (name) {
  106. Object.keys(data.modals).forEach(function (key) {
  107. var visibility = data.modals[key].visible;
  108. data.modals[key].visible = (key == name);
  109. if (visibility != data.modals[key].visible) {
  110. methods.modalVisibilityChange(key);
  111. }
  112. });
  113. },
  114. modalVisible: function (name) {
  115. var visible = false;
  116. // check if the specific modal is visible
  117. if (name) {
  118. Object.keys(data.modals).forEach(function (key) { if (key == name) visible = data.modals[key].visible; });
  119. }
  120. // check if any of them are visible
  121. else {
  122. Object.keys(data.modals).forEach(function (key) { if (visible == false) visible = data.modals[key].visible; });
  123. }
  124. return visible;
  125. },
  126. modalPositionStyle: function (name, width, height) {
  127. return {
  128. width: width + 'px',
  129. height: height + 'px',
  130. left: 'calc(50% - ' + (width / 2) + 'px)',
  131. top: (data.modals[name].visible ? 'calc(50% - ' + (height / 2) + 'px)' : '-' + (height + 32) + 'px')
  132. }
  133. },
  134. register: function () {
  135. socket.emit('/users/register', {
  136. email: data.modals.register.email,
  137. username: data.modals.register.username,
  138. password: data.modals.register.password,
  139. recaptcha: grecaptcha.getResponse()
  140. });
  141. }
  142. };
  143. var app = new Vue({ el: '#app', data: data, methods: methods, ready: function () { window.setTimeout(function () { data.home.visible = true; }, 250); } });
  144. window.socket = socket;
  145. window.data = data;
  146. };