cd Backend
npm starthttp://localhost:3000/dashboard-live.html
http://localhost:3000/videoplayer-live.html
- Click "Play" on any video
- Watch for ~30 seconds
- Close the player or go back to dashboard
- Dashboard shows "Continue Watching" ✅
- Resume button has saved position ✅
- Complete a video → See +25 XP notification ✅
POST /api/progress/save-watch-time
→ Called every 5s while watching (auto-saves position)
POST /api/progress/video-complete
→ Called when video ends (awards XP)
GET /api/progress/continue-watching?userId=1
→ Lists videos you haven't finished (for dashboard)
videoplayer-live.html- Video player with auto-resume + XP counterdashboard-live.html- Dashboard showing "Continue Watching" + stats
// Handles:
// - Auto-save every 5 seconds
// - Load/save to localStorage (works offline)
// - Sync with backend
// - XP tracking
// - Resume functionalityYou watch video for 2 min
↓
Frontend auto-saves: "user 1, video_xyz, 120 seconds"
↓
Saved to localStorage (instant) + backend (async)
↓
You close player
↓
You open dashboard
↓
Dashboard shows: "📍 Continue watching from 2:00"
↓
You click "Resume"
↓
Video loads and jumps to 2:00 mark automatically
↓
You finish the video
↓
+25 XP awarded → XP counter updates → Dashboard syncs
| Feature | How It Works |
|---|---|
| Auto-Resume | Position saved every 5s, loaded on next visit |
| Live XP | Counter updates instantly as you earn XP |
| Continue Watching | Shows incomplete videos with progress bar |
| No Setup | Works with existing database, no migrations |
| Offline Support | Uses localStorage, syncs when online |
| Fast | Vanilla JS + fetch, no heavy frameworks |
Backend/routes/progress.js, line 5:
const XP_PER_VIDEO = 25; ← Change this
Frontend/videoplayer-live.html, line ~280:
}, 5000); ← 5000ms = 5 seconds
Frontend/dashboard-live.html, line ~200:
setInterval(loadDashboardData, 10000); ← 10 seconds
| Problem | Solution |
|---|---|
| Video doesn't resume | Check localStorage in browser console; make sure MySQL is running |
| XP not updating | Hard refresh browser (Ctrl+F5); check backend logs |
| Continue watching empty | Watch a video for 30+ seconds, close, refresh dashboard |
| Page blank/errors | Check browser console (F12); make sure backend is running |
See LIVE_TRACKING_SETUP.md for:
- Detailed architecture
- All endpoint specs
- Advanced customization
- Production security notes
// Import the sync manager
// <script src="js/sync-manager.js"></script>
// Create instance
const sync = new SyncManager({
userId: 1,
onXPChange: (data) => console.log('XP:', data.total),
onVideoComplete: (data) => console.log('Video done!', data),
});
// Load data
await sync.loadUserStats();
await sync.loadContinueWatching();
// Auto-called while watching
sync.saveWatchProgress(videoId, currentTime);
// Called on video end
sync.markVideoComplete(videoId, watchedSeconds);- Add quiz questions after each video
- Implement leaderboard (top XP earners)
- Add badges/achievements system
- Enable video quality selection
- Add real-time WebSocket sync (instead of polling)
That's it! You're ready to go. The system handles everything automatically. 🎉
For questions, check the browser console logs or refer to LIVE_TRACKING_SETUP.md.