diff options
| author | stoned <stoned@SPC.fritz.box> | 2022-01-19 13:40:00 +0100 |
|---|---|---|
| committer | stoned <stoned@SPC.fritz.box> | 2022-01-19 13:40:00 +0100 |
| commit | e1d2dfcab519a780361a17aec8130234a79c66e6 (patch) | |
| tree | 8b8aa135e07ba55f70dfb6e1e78e07b8c61d81f7 | |
| parent | 9f24b0f6d2c5c9678dec805cd98c324c2e7f46b4 (diff) | |
fix #83
| -rw-r--r-- | webAO/client.js | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/webAO/client.js b/webAO/client.js index 4fa921c..c6f2c04 100644 --- a/webAO/client.js +++ b/webAO/client.js @@ -1020,9 +1020,11 @@ class Client extends EventEmitter { } isAudio(trackname) { - if (trackname.includes(".") || // regex for file extenstions - trackname.startsWith("=") || - trackname.startsWith("-")) // category markers + if (trackname.endsWith(".wav") || + trackname.endsWith(".mp3") || + trackname.endsWith(".mp4") || + trackname.endsWith(".ogg") || + trackname.endsWith(".opus")) // NOT category markers { return true; } else { @@ -1037,14 +1039,6 @@ class Client extends EventEmitter { this.musics.push(trackname); } - handleMusicInfo(trackindex,trackname) { - if (this.isAudio(trackname)) { - this.addTrack(trackname); - } else { - this.createArea(trackindex,trackname); - } - } - createArea(id,name) { const thisarea = { name: name, @@ -1072,6 +1066,19 @@ class Client extends EventEmitter { document.getElementById("areas").appendChild(newarea); } + + /** + * Area list fuckery + */ + fix_last_area() { + if (this.areas.length > 0) { + let malplaced = this.areas.pop().name; + const areas = document.getElementById("areas"); + areas.removeChild(areas.lastChild); + this.addTrack(malplaced); + } + } + /** * Handles incoming music information, containing multiple entries * per packet. @@ -1087,7 +1094,13 @@ class Client extends EventEmitter { for (let i = 2; i < args.length - 1; i++) { if (i % 2 === 0) { document.getElementById("client_loadingtext").innerHTML = `Loading Music ${args[1]}/${this.music_list_length}`; - this.handleMusicInfo(args[i-1],safe_tags(args[i])); + const trackname = safe_tags(args[i]); + const trackindex = args[i-1]; + if (this.isAudio(trackname)) { + this.addTrack(trackname); + } else { + this.createArea(trackindex,trackname); + } } } @@ -1104,10 +1117,22 @@ class Client extends EventEmitter { this.resetMusicList(); this.resetAreaList(); + let musics_time = false; + for (let i = 1; i < args.length - 1; i++) { // Check when found the song for the first time + const trackname = safe_tags(args[i]); + const trackindex = i-1; document.getElementById("client_loadingtext").innerHTML = `Loading Music ${i}/${this.music_list_length}`; - this.handleMusicInfo(i-1,safe_tags(args[i])); + if (musics_time) { + this.addTrack(trackname); + } else if (this.isAudio(trackname)) { + musics_time = true; + this.fix_last_area(); + this.addTrack(trackname); + } else { + this.createArea(trackindex,trackname); + } } // Music done, carry on |
