blastoise/public/core.js

68 lines
1.8 KiB
JavaScript

// MusicRoom - Core module
// Shared state and namespace setup
window.MusicRoom = {
// Audio element
audio: new Audio(),
// WebSocket and channel state
ws: null,
currentChannelId: null,
currentTrackId: null,
currentTitle: null,
serverTimestamp: 0,
serverTrackDuration: 0,
lastServerUpdate: 0,
serverPaused: true,
// Channels list
channels: [],
// Sync state
wantSync: true, // User intent - do they want to be synced?
synced: false, // Actual state - are we currently synced?
// Volume
preMuteVolume: 1,
STORAGE_KEY: "blastoise_volume",
// Playback state
localTimestamp: 0,
queue: [],
currentIndex: 0,
playbackMode: "repeat-all",
// User state
currentUser: null,
serverStatus: null,
// Library (all discovered tracks)
library: [],
// Caching state
prefetchController: null,
loadingSegments: new Set(),
trackCaches: new Map(), // Map of filename -> Set of cached segment indices
trackBlobs: new Map(), // Map of filename -> Blob URL for fully cached tracks
bulkDownloadStarted: new Map(),
cachedTracks: new Set(), // Set of track IDs that are fully cached locally
streamOnly: false, // When true, skip bulk downloads (still cache played tracks)
cacheLimit: 100 * 1024 * 1024, // 100MB default cache limit
// Download metrics
audioBytesPerSecond: 20000, // Audio bitrate estimate for range requests
downloadSpeed: 0, // Actual network download speed
recentDownloads: [], // Track recent downloads for speed calculation
// Constants
SEGMENTS: 20,
FAST_THRESHOLD: 10 * 1024 * 1024, // 10 MB/s
// UI update tracking (to avoid unnecessary DOM updates)
lastProgressPct: -1,
lastTimeCurrent: "",
lastTimeTotal: "",
lastBufferPct: -1,
lastSpeedText: ""
};