-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession.html
More file actions
440 lines (380 loc) · 19.2 KB
/
session.html
File metadata and controls
440 lines (380 loc) · 19.2 KB
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Session - PRESSUR™</title>
<link rel="icon" type="image/png" href="assets/img/logo.png">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link rel="stylesheet" href="css/style.css">
<script src="js/session.js"></script>
<style>
/* Frame Constraints */
.session-frame {
max-width: 900px;
width: 100%;
background-color: var(--card-bg);
border: 1px solid var(--border-color);
border-radius: 20px;
}
/* Pulsing Animation for Start Button */
@keyframes pulse-border {
0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.7); }
70% { box-shadow: 0 0 0 15px rgba(255, 255, 255, 0); }
100% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0); }
}
.btn-pulse {
animation: pulse-border 2s infinite;
border: 2px solid white !important;
}
/* Visualization container height */
#waveform {
cursor: pointer;
position: relative;
background: rgba(0,0,0,0.3);
border-radius: 10px;
height: 250px; /* Increased height */
overflow: hidden;
}
.volume-slider {
width: 150px;
accent-color: var(--accent-start);
}
/* Navbar tweaks */
.navbar { background: transparent; padding: 20px; }
.offcanvas { background-color: var(--bg-dark); border-left: 1px solid var(--border-color); color: white; }
</style>
</head>
<body class="bg-dark text-white">
<nav class="navbar navbar-dark">
<div class="container-fluid">
<span class="navbar-brand fw-bold title-gradient">PRESSUR™</span>
<button class="navbar-toggler border-0" type="button" data-bs-toggle="offcanvas" data-bs-target="#navMenu">
<i class="bi bi-list fs-1"></i>
</button>
</div>
</nav>
<div class="offcanvas offcanvas-end" tabindex="-1" id="navMenu">
<div class="offcanvas-header border-bottom border-secondary border-opacity-25">
<h5 class="offcanvas-title fw-light" id="menuWelcome">Menu</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas"></button>
</div>
<div class="offcanvas-body d-flex flex-column">
<ul class="nav flex-column mb-auto">
<li class="nav-item mb-2">
<a class="nav-link text-white rounded nav-link-custom" id="nav-categories" href="categories.html">
<i class="bi bi-grid-fill me-2"></i> Categories
</a>
</li>
<li class="nav-item mb-2">
<a class="nav-link text-white rounded nav-link-custom" id="nav-session" href="session.html">
<i class="bi bi-play-circle me-2"></i> Current Session
</a>
</li>
<li class="nav-item mb-2">
<a class="nav-link text-white rounded nav-link-custom" id="nav-analytics" href="#">
<i class="bi bi-graph-up me-2"></i> Analytics
</a>
</li>
<hr class="border-secondary opacity-25">
<li class="nav-item">
<a class="nav-link text-danger" href="#" onclick="Session.logout()">
<i class="bi bi-box-arrow-right me-2"></i> Finish Session
</a>
</li>
</ul>
<div id="menuTimerSection" class="d-none mt-auto pt-4 border-top border-secondary border-opacity-25 text-center">
<p class="x-small text-uppercase ls-1 text-light mb-1">Chamber Session</p>
<div class="h3 fw-bold text-gradient mb-0" id="menuTimerClock">00:00</div>
<p class="x-small text-light">remaining</p>
</div>
</div>
</div>
<div class="container py-5 d-flex flex-column align-items-center">
<div class="session-frame p-4 mb-4 shadow-lg" id="playerFrame">
<div class="d-flex justify-content-between align-items-start mb-2">
<div>
<h2 id="sessionCategory" class="text-uppercase ls-1 mb-0 text-info" style="font-size: 1.2rem;">Category</h2>
<p id="trackTitle" class="text-white fw-light opacity-75">Track Name</p>
</div>
<button class="btn btn-link text-white opacity-50 p-0" onclick="toggleFullScreen()">
<i class="bi bi-arrows-fullscreen"></i>
</button>
</div>
<div id="waveform" class="mb-2"></div>
<div class="d-flex justify-content-between px-1 mb-3" style="font-size: 0.85rem; font-family: monospace;">
<span id="currentTime">00:00</span>
<span id="totalDuration">00:00</span>
</div>
<div class="row align-items-center">
<div class="col-4">
<button class="btn btn-outline-secondary btn-sm rounded-pill border-0" id="favBtn">
<i class="bi bi-star me-2"></i>Favorite
</button>
</div>
<div class="col-4 text-center">
<button id="playPauseBtn" class="btn btn-gradient rounded-circle mx-auto d-flex align-items-center justify-content-center btn-pulse" style="width: 60px; height: 60px;">
<i class="bi bi-play-fill fs-2" id="playIcon"></i>
</button>
</div>
<div class="col-4 d-flex justify-content-end align-items-center">
<i class="bi bi-volume-down-fill me-2 text-secondary"></i>
<input type="range" class="volume-slider" id="volumeSlider" min="0" max="1" step="0.05" value="0.5">
</div>
</div>
</div>
<div class="session-frame p-3 mb-4 d-flex justify-content-between align-items-center px-4 border-info border-opacity-25">
<div class="d-flex align-items-center">
<i class="bi bi-heart-fill text-danger me-3 fs-4 pulse-slow"></i>
<span class="text-uppercase fw-bold ls-1 small">Heart Rate</span>
</div>
<div class="h3 mb-0 fw-bold"><span id="bpmVal">72</span> <small class="fs-6 text-light">BPM</small></div>
</div>
<div class="row w-100" style="max-width: 900px;">
<div class="col-md-6 ps-0 pe-2">
<div class="session-frame p-4 h-100">
<h6 class="text-uppercase ls-1 mb-3 small text-info"><i class="bi bi-clock-history me-2"></i>Session Duration</h6>
<div class="d-grid gap-2" id="durationButtons">
<div class="row g-2">
<div class="col-6"><button class="btn btn-outline-light w-100 py-2 btn-duration" data-mins="15">15m</button></div>
<div class="col-6"><button class="btn btn-outline-light w-100 py-2 btn-duration" data-mins="30">30m</button></div>
<div class="col-6"><button class="btn btn-outline-light w-100 py-2 btn-duration" data-mins="45">45m</button></div>
<div class="col-6"><button class="btn btn-outline-light w-100 py-2 btn-duration" data-mins="60">60m</button></div>
</div>
</div>
<div id="activeTimerDisplay" class="d-none text-center py-3">
<div class="display-6 fw-bold text-gradient" id="timerClock">00:00</div>
<p class="small text-light mt-2">Remaining in session</p>
</div>
</div>
</div>
<div class="col-md-6 pe-0 ps-2">
<div class="session-frame p-4 h-100">
<div class="opacity-50">
<div class="d-flex justify-content-between align-items-center mb-2">
<div><h6 class="mb-0 small fw-bold">Biometric Adaptation</h6><p class="x-small text-light mb-0">Auto-adjust intensity</p></div>
<div class="form-check form-switch"><input class="form-check-input" type="checkbox" disabled></div>
</div>
<div class="d-flex justify-content-between align-items-center mb-3">
<div><h6 class="mb-0 small fw-bold">PRESSUR™ Sync</h6><p class="x-small text-light mb-0">Sync chamber lighting</p></div>
<div class="form-check form-switch"><input class="form-check-input" type="checkbox" disabled></div>
</div>
<button class="btn btn-dark btn-sm w-100 mb-3 text-light"><i class="bi bi-download me-2"></i>Download for Offline</button>
</div>
<hr class="border-secondary opacity-25">
<div class="row text-center mt-3">
<div class="col-6 border-end border-secondary border-opacity-25">
<div class="small text-light text-uppercase ls-1">Sessions</div>
<div class="fw-bold" id="statSessions">0</div>
</div>
<div class="col-6">
<div class="small text-light text-uppercase ls-1">Total Hrs</div>
<div class="fw-bold" id="statHours">0.0</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/wavesurfer.js@7"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
let wavesurfer;
document.addEventListener('DOMContentLoaded', () => {
const urlParams = new URLSearchParams(window.location.search);
const trackPath = decodeURIComponent(urlParams.get('track'));
const category = urlParams.get('cat');
// Set Titles
document.getElementById('sessionCategory').textContent = category;
document.getElementById('trackTitle').textContent = trackPath.split('/').pop().replace(/-compr\.mp3$/, '').replace(/_/g, ' ').replace(/^\d+\./, '');
// 1. Time Formatting Helper
const formatTime = (seconds) => {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
};
// 2. Initialize Wavesurfer
wavesurfer = WaveSurfer.create({
container: '#waveform',
waveColor: 'rgba(79, 74, 133, 0.5)',
progressColor: '#00c6ff',
cursorColor: '#ffffff',
barWidth: 3,
barGap: 2,
height: 160, // Reduced to leave room for stamps
minPxPerSec: 30, // Higher number = more zoomed in/scrolling
autoCenter: true,
interact: true,
fillParent: true
});
// Update timestamps on progress
wavesurfer.on('audioprocess', (time) => {
document.getElementById('currentTime').textContent = formatTime(time);
});
wavesurfer.on('ready', () => {
document.getElementById('totalDuration').textContent = formatTime(wavesurfer.getDuration());
});
// 3. Heart Rate Faker
setInterval(() => {
const base = 72;
const drift = Math.floor(Math.random() * 5) - 2;
document.getElementById('bpmVal').textContent = base + drift;
}, 3000);
// 4. SESSION TIMER LOGIC (Bound to User)
const currentUser = Session.getCurrentUser();
const SESSION_STATE_KEY = `pressur_active_session_${currentUser.id}`;
const startSessionTimer = (minutes) => {
const durationMs = minutes * 60 * 1000;
const endTime = Date.now() + durationMs;
const state = { endTime, durationMins: parseInt(minutes), isActive: true };
localStorage.setItem(SESSION_STATE_KEY, JSON.stringify(state));
// Visual feedback: briefly flash the timer
document.getElementById('activeTimerDisplay').style.opacity = "0";
updateTimerUI();
setTimeout(() => document.getElementById('activeTimerDisplay').style.opacity = "1", 100);
};
const updateTimerUI = () => {
const state = JSON.parse(localStorage.getItem(SESSION_STATE_KEY));
if (!state || !state.isActive) {
document.getElementById('durationButtons').classList.remove('d-none');
document.getElementById('activeTimerDisplay').classList.add('d-none');
return;
}
document.getElementById('durationButtons').classList.add('d-none');
document.getElementById('activeTimerDisplay').classList.remove('d-none');
// Clear any existing interval to prevent "doubling up"
if (window.sessionInterval) clearInterval(window.sessionInterval);
window.sessionInterval = setInterval(() => {
const remaining = state.endTime - Date.now();
if (remaining <= 0) {
clearInterval(window.sessionInterval);
finishSession(state.durationMins);
} else {
const timeStr = formatTime(remaining / 1000);
document.getElementById('timerClock').textContent = timeStr;
// Also update the menu timer if it exists on this page
if (document.getElementById('menuTimerClock')) {
document.getElementById('menuTimerClock').textContent = timeStr;
}
}
}, 1000);
};
const finishSession = (mins) => {
localStorage.removeItem(SESSION_STATE_KEY);
// Update the "Database"
Session.saveSessionStats(mins);
// Play a gentle alert if you have one, or just the modal
alert("Congratulations Session Completed! Your session has finished. Take some time to gather yourself, you're ready for whatever the rest of the day brings.");
// Refresh UI to show updated stats in the right-side frame
updateStatsDisplay();
updateTimerUI();
};
const updateStatsDisplay = () => {
const user = Session.getCurrentUser();
if (user && user.stats) {
document.getElementById('statSessions').textContent = user.stats.totalSessions || 0;
document.getElementById('statHours').textContent = (user.stats.totalMinutes / 60).toFixed(1) || "0.0";
}
};
// Call on load
updateStatsDisplay();
updateTimerUI();
// Listen for duration clicks
document.querySelectorAll('.btn-duration').forEach(btn => {
btn.addEventListener('click', () => startSessionTimer(btn.dataset.mins));
});
wavesurfer.load(trackPath);
// 2. Play/Pause & Media Session API
const btn = document.getElementById('playPauseBtn');
const icon = document.getElementById('playIcon');
const togglePlay = () => {
wavesurfer.playPause();
const isPlaying = wavesurfer.isPlaying();
// UI Toggle
icon.className = isPlaying ? 'bi bi-pause-fill fs-2' : 'bi bi-play-fill fs-2';
btn.classList.toggle('btn-pulse', !isPlaying);
// Media Session API (Bluetooth Controls)
if ('mediaSession' in navigator) {
navigator.mediaSession.playbackState = isPlaying ? 'playing' : 'paused';
}
};
btn.addEventListener('click', togglePlay);
// Setup Media Session metadata
wavesurfer.on('ready', () => {
if ('mediaSession' in navigator) {
navigator.mediaSession.metadata = new MediaMetadata({
title: document.getElementById('trackTitle').textContent,
artist: 'PRESSUR™',
album: category,
artwork: [{ src: 'assets/img/logo.png', sizes: '512x512', type: 'image/png' }]
});
navigator.mediaSession.setActionHandler('play', togglePlay);
navigator.mediaSession.setActionHandler('pause', togglePlay);
}
});
// Volume Control
document.getElementById('volumeSlider').addEventListener('input', (e) => {
wavesurfer.setVolume(e.target.value);
});
// Menu
// 1. Set Welcome Name
const user = Session.getCurrentUser();
if (user) {
document.getElementById('menuWelcome').textContent = `Welcome, ${user.name}`;
}
// 2. Highlight Active Page
const currentPage = window.location.pathname.split("/").pop() || 'index.html';
if (currentPage === 'categories.html') document.getElementById('nav-categories').classList.add('active-page');
if (currentPage === 'session.html') document.getElementById('nav-session').classList.add('active-page');
// 3. Persistent Menu Timer
const updateMenuTimer = () => {
if (!user) return;
const state = JSON.parse(localStorage.getItem(`pressur_active_session_${user.id}`));
const timerSection = document.getElementById('menuTimerSection');
const timerClock = document.getElementById('menuTimerClock');
if (state && state.isActive) {
timerSection.classList.remove('d-none');
const remaining = state.endTime - Date.now();
if (remaining > 0) {
const mins = Math.floor(remaining / 1000 / 60);
const secs = Math.floor((remaining / 1000) % 60);
timerClock.textContent = `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
} else {
timerSection.classList.add('d-none'); // Hide when done
}
} else {
timerSection.classList.add('d-none');
}
};
// Run timer update every second
setInterval(updateMenuTimer, 1000);
updateMenuTimer();
// Favourite
const favBtn = document.getElementById('favBtn');
const trackFilename = decodeURIComponent(urlParams.get('track')).split('/').pop();
// Initial State Check
const updateFavUI = (isFav) => {
favBtn.innerHTML = isFav ? '<i class="bi bi-star-fill me-2 text-warning"></i>Favorited' : '<i class="bi bi-star me-2"></i>Add to Favorites';
favBtn.classList.toggle('border-warning', isFav);
};
updateFavUI(Session.isFavorite(trackFilename));
// Click Event
favBtn.addEventListener('click', () => {
const newState = Session.toggleFavorite(trackFilename);
updateFavUI(newState);
});
});
function toggleFullScreen() {
const elem = document.getElementById('playerFrame');
if (!document.fullscreenElement) {
elem.requestFullscreen().catch(err => {
alert(`Error attempting to enable full-screen mode: ${err.message}`);
});
} else {
document.exitFullscreen();
}
}
</script>
</body>
</html>