-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
327 lines (327 loc) · 17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<meta name="theme-color" content="1C1C1F">
<title>musiqpad | Lounge</title>
<meta name="description" content="Real time music streaming and chat with friends. Musiqpad is a place where people can discover new music.">
<meta name="keywords" content="discover, new, music, song, sound, youtube, stream, chat, friends, share, listen, woot, meh, plug, dj, dubtrack, fm, turntable">
<link rel="shortcut icon" type="image/png" href="https://musiqpadmqp.github.io/pads/lib/img/icon.png"/>
<link href="pads/lib/css/mdi.min.css" media="all" rel="stylesheet" type="text/css"/>
<script src="jquery-1.11.3.min.js"></script>
<script type="text/javascript">(function(e,t){var n=e.amplitude||{};var r=t.createElement("script");r.type="text/javascript";r.async=true;r.src="libs/amplitude-2.9.0-min.gz.js";r.onload=function(){e.amplitude.runQueuedFunctions()};var s=t.getElementsByTagName("script")[0];s.parentNode.insertBefore(r,s);var i=function(){this._q=[];return this};function a(e){i.prototype[e]=function(){this._q.push([e].concat(Array.prototype.slice.call(arguments,0)));return this}}var o=["add","append","clearAll","set","setOnce","unset"];for(var c=0;c<o.length;c++){a(o[c])}n.Identify=i;n._q=[];function u(e){n[e]=function(){n._q.push([e].concat(Array.prototype.slice.call(arguments,0)));}}var l=["init","logEvent","logRevenue","setUserId","setUserProperties","setOptOut","setVersionName","setDomain","setDeviceId","setGlobalUserProperties","identify","clearUserProperties"];for(var p=0;p<l.length;p++){u(l[p])}e.amplitude=n})(window,document);amplitude.init("2d3eb4a42289c22e4a7a3f7ea45718a9");amplitude.logEvent("LOUNGE_LOADED")</script>
<link rel="stylesheet" type="text/css" href="lounge/css/lobby.css">
<base target="_parent"/>
</head>
<body>
<div id="background"></div>
<section id="scroll">
<section id="header">
<div class="header-container">
<div class="header-content">
<a href="/" title="Copyright (c) 2015-2021 Musiqpad Team"><img src="pads/lib/img/mqp.png" class="avatar" alt="musiqpad"></a>
</div>
</div>
</section>
<section>
<div class="header-content extra-info">You can see here all online pads. Join in your favourite and listen together music.<br></div>
</section>
<section id="search">
<input type="text" id="searchbox" placeholder="Search for pads...">
</section>
<section id="list">
<div class="pad template" style="">
<a href="">
<div class="pad-img">
<nav>
<span class="song-title"></span>
<div>
<span class="mdi mdi-account-multiple user-logo"></span>
<span class="users"></span>
</div>
</nav>
</div>
<div class="pad-info">
<p class="pad-name">Looking for pads...</p>
<p class="pad-owner"></p>
<p class="pad-dj"></p>
</div>
</a>
</div>
</section>
</section>
<section id="footer">
<div class="left">
<div class="ad"></div>
</div>
<div class="right">
</div>
</section>
<div class="cover"></div>
<script>
var pads = {};
var announcement = "";
function updateRooms() {
$.getJSON('https://mqpapi.glitch.me/announce', function(data) {
if (data.announcement) {
announcement = data.announcement;
$('.ad').html('<div class="mdi mdi-bullhorn" style="padding-right:10px"></div>' + data.announcement);
$('.ad').attr('title', data.announcement);
$('.ad').click(makeAnnounceModal);
}
if (data.allowApiKeyGeneration) {
$('.btn-key').show();
}
else {
$('.btn-key').hide();
}
if (data.version) {
$('.welcome').html('<i>Welcome to musiqpad ' + data.version + '. Please read our <a target="_blank" href="blog_subdomain/faq/">FAQ</a></i>');
}
});
$.getJSON("https://mqpapi.glitch.me/pad/list", function(data) {
var template = $('.pad.template');
template.show();
$('.pad:not(.template)').remove();
//data.sort(function(a, b){return (b.user_count?b.user_count:0)-(a.user_count?a.user_count:0)});
data.sort(function(a, b) {
var b_uc = (b.user_count?b.user_count:0);
var a_uc = (a.user_count?a.user_count:0);
if (b_uc != a_uc) {
return b_uc - a_uc;
} else if (b.is_self_hosted != a.is_self_hosted) {
return (b.is_self_hosted * -1) - (a.is_self_hosted * -1)
} else {
return (b.current_song + "").length - (a.current_song + "").length;
}
});
for (var i = 0, len = data.length; i < len; i++) {
var room = data[i];
if (room.slug) {
pads[room.slug] = room;
}
if ((!room.pad_url || room.pad_url == '') && (!room.socket_host || room.socket_host == '')) {
continue;
}
var roomDiv = template.clone();
roomDiv.removeClass('template');
var roomClass = 'pad-' + room.slug;
roomDiv.addClass(roomClass);
roomDiv.attr('data-pad', room.slug);
$('#list').append(roomDiv);
var isSelfHosted = room.is_self_hosted == undefined || room.is_self_hosted == null || room.is_self_hosted == 1;
roomDiv.find('a').attr('href', isSelfHosted ? room.pad_url : '/p/' + room.slug);
roomDiv.find('.pad-name').text(room.pad_name ? room.pad_name : room.slug + ' (Pending Initial Update)');
roomDiv.find('.pad-owner').text( (!room.pad_owner) ? (!room.api_pad_owner) ? 'Waiting for Owner' : 'Owner: ' + room.api_pad_owner : 'Owner: '+ room.pad_owner );
roomDiv.find('.pad-dj').text('Nobody is playing');
roomDiv.find('.users').text(room.user_count ? room.user_count : '0');
roomDiv.find('.pad-dj').text(!room.current_dj_name ? '' : 'DJ: ' + room.current_dj_name);
roomDiv.find('.song-title').html(!isSelfHosted ? '<img class="mp-official" src="/pads/lib/img/icon.png"></img>MP Official' : '');
if (room.current_song) {
//$.get('https://youtube.com/get_video_info?video_id=W2H_E_BHdh8', function( data ) {
// roomDiv.find('.song-title').text(data.title);
//});
//roomDiv.find('.song-title').text(room.currentSong.title);
roomDiv.find('.pad-img').css({
'background-image': 'url(https://i.ytimg.com/vi/' + room.current_song + '/mqdefault.jpg)',
'background-size': '100% 100%'
});
} else {
roomDiv.find('.pad-img').css({
'background-image': 'url(pads/lib/img/avatar.png)',
'background-position': 'center'
});
}
}
filterPads();
template.hide();
});
}
updateRooms();
setInterval(updateRooms, 60 * 1000);
function getRoomFromClassList(jqueryElement) {
if (jqueryElement != null && jqueryElement.length != 0) {
return $(jqueryElement[0]).attr('data-pad');
}
return null;
}
function hasQueryParam(field) {
var url = window.location.href;
if(url.indexOf('?' + field) != -1)
return true;
else if(url.indexOf('&' + field) != -1)
return true;
return false
}
if (hasQueryParam('embed')) {
$('body').addClass('embed');
}
function registerApiKey() {
var token = getCookie('token');
var slug = $('.api_slug')[0].value;
var padUrl = $('.api_pad_url')[0].value;
var serverHost = $('.api_server_host')[0].value;
if ((!slug || slug == '') && (!serverHost || serverHost == '')) {
$('.modal-bg').remove();
return;
}
if (!token) {
alert("Please ensure that you have logged into/created an account in the 'Welcome to musiqpad!' pad before attempting to generate an api key.");
return;
}
if (!(/(?:[A-Za-z0-9-]+\.)+[A-Za-z0-9]{1,3}:\d{1,5}/.test(serverHost))) {
alert('Your server host does not appear to be using the correct format.');
return;
}
if (!(/^[a-z0-9_-]{1,32}$/.test(slug.toLowerCase()))) {
alert('Your slug can only contain alphanumeric characters, underscores and dashes.');
return;
}
$.get('https://mqpapi.glitch.me/genkey?token=' + token + '&server_host=' + serverHost + '&slug=' + slug + (padUrl == null || padUrl == '' ? '' : '&pad_url=' + padUrl), function(data) {
console.log(data);
if (data.apiKey) {
amplitude.logEvent('CREATED_API_KEY', { slug: slug, padUrl: padUrl, socketHost: serverHost });
$('.modal-bg').remove();
$('body').append('\
<div class="modal-bg">\
<div class="modal-container">\
<div class="modal">\
<div class="modal-box">\
<div class="modal-text">\
<h3>Your API Key for "' + slug + '"</h3>\
<input type="text" class="modal-input" readonly onClick="this.select();" value="' + data.apiKey + '" /><br><br>\
Make sure to keep this safe as you will not be able to recover it!\
</div>\
</div>\
<div class="modal-controls">\
<div class="modal-ctrl">\
<div class="modal-no" onclick="$(\'.modal-bg\').remove()">\
<div class="mdi mdi-close"></div>\
</div>\
<div class="modal-yes" onclick="$(\'.modal-bg\').remove()">\
<div class="mdi mdi-check"></div>\
</div>\
</div>\
</div>\
</div>\
</div>\
</div>\
');
$('body').on('click', '.modal-yes', function() {
$('.modal-bg').remove();
});
}
else {
alert('Failed to generate API Key. If you keep seeing this message please contact: [email protected]');
}
}).error(function(data) {
if (data.status == 403) {
alert("Please ensure that you have logged into/created an account in the 'Welcome to musiqpad!' pad before attempting to generate an api key.");
}
else if (data.status == 409) {
alert("The slug you are attempting to create is already in use. If you would like to update the information connected to this slug please contact: [email protected]");
}
else if (data.status == 400){
alert("Invalid paramters.");
}
//$('.modal-bg').remove();
});
}
function getCookie(name) {
var value = "; " + document.cookie;
var parts = value.split("; " + name + "=");
if (parts.length == 2) return parts.pop().split(";").shift();
}
function makeModal() {
$('body').append('\
<div class="modal-bg">\
<div class="modal-container">\
<div class="modal">\
<div class="modal-box">\
<div class="modal-text">\
<h3>Register for an API Key</h3>\
<input type="text" class="modal-input api_slug" placeholder="Room Slug" />\
<input type="text" class="modal-input api_server_host" placeholder="Socket Host & Port (Format: domain:port)" />\
<input type="text" class="modal-input api_pad_url" placeholder="Pad URL (Not required)" /><br><br>\
<ul>\
<li>Only sockets supporting SSL will work on the musiqpad frontend. If your socket does NOT support SSL then you will have to host your own frontend.</li>\
<li>Pad URL is only used for Self Hosted pads that have their own frontend page.</li>\
<li>If you want your pad to be hosted on musiqpad\'s frontend leave this blank.</li>\
</ul>\
</div>\
</div>\
<div class="modal-controls">\
<div class="modal-ctrl">\
<div class="modal-no" onclick="$(\'.modal-bg\').remove()">\
<div class="mdi mdi-close"></div>\
</div>\
<div class="modal-yes" onclick="registerApiKey()">\
<div class="mdi mdi-check"></div>\
</div>\
</div>\
</div>\
</div>\
</div>\
</div>\
');
}
$('.btn-key').on('click', function(){
makeModal();
});
$('#searchbox').on("change keyup paste", function(){
filterPads();
});
function filterPads(){
var val = $('#searchbox').val().toLowerCase();
for(var slug in pads){
if(!/^[a-z\.,_-]+$/.test(slug)) continue;
var pad = pads[slug];
if(slug.indexOf(val) == -1 && (pad.pad_name || "").toLowerCase().indexOf(val) == -1 && (pad.pad_owner || pad.api_pad_owner || "").toLowerCase().indexOf(val) == -1)
{} else {
$('.pad-' + slug).show();
}
}
}
function makeAlertModal(data) {
$('body').append('\
<div class="modal-bg">\
<div class="modal-container">\
<div class="modal large">\
<div class="modal-box">\
<div class="modal-text">' +
data + '\
</div>\
</div>\
<div class="modal-controls">\
<div class="modal-ctrl">\
<div class="modal-yes" onclick="$(\'.modal-bg\').remove()" style="width:100%;">\
<div class="mdi mdi-check"></div>\
</div>\
</div>\
</div>\
</div>\
</div>\
</div>\
');
}
function makeTroubleshootingModal() {
makeAlertModal('\
<h3>Can\'t see your pad in the list?</h3>\
<p>The most common reason for pads to not be shown is that they are either offline or not sending lobby updates.<br/>Below are some common troubleshooting issues.</p>\
<ul>\
<li>Pads will only be shown when they have sent an update in the last <b>30 minutes</b>.</li>\
<li>New Pads have a grace period of <b>2 hours</b> in which they need to send an update.</li>\
<li>If you pad misses the update period it will be shown again once it next updates</li>\
</ul>\
');
}
function makeAnnounceModal() {
makeAlertModal('\
<h3>Announcement</h3>' + announcement
);
}
</script>
</body>
</html>