From 7815497e7fd1e02b002e0eadeb41ec715e06db16 Mon Sep 17 00:00:00 2001 From: ShadowLp174 Date: Tue, 14 Nov 2023 17:47:17 +0100 Subject: [PATCH] improved elapsed time display (most bugs fixed + new features) --- Player.js | 1 + dashboard/index.js | 7 ++++- dashboard/views/components/player.ejs | 1 + dashboard/views/dashboard/index.ejs | 17 +++++++++--- package-lock.json | 40 ++++++++++++++------------- package.json | 4 +-- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/Player.js b/Player.js index 05b787b..70f8469 100644 --- a/Player.js +++ b/Player.js @@ -332,6 +332,7 @@ class RevoltPlayer extends EventEmitter { } } }, { highWaterMark: 1048576 / 4 }); + connection.media.once("startPlay", () => this.emit("streamStartPlay")); connection.media.playStream(stream); stream.once("data", () => this.startedPlaying = Date.now()); if (this.connection.preferredVolume) connection.media.setVolume(this.connection.preferredVolume); diff --git a/dashboard/index.js b/dashboard/index.js index 96c8730..c6e87f9 100644 --- a/dashboard/index.js +++ b/dashboard/index.js @@ -400,6 +400,9 @@ class Dashboard { const startPlayHandler = song => { socket.emit("startplay", getSongData(song, player)); } + const streamStartPlayHandler = () => { + socket.emit("streamStartPlay"); + } const stopPlayHandler = () => { socket.emit("stopplay"); } @@ -418,6 +421,7 @@ class Dashboard { socket.emit("queue", event); } player.on("startplay", startPlayHandler); + player.on("streamStartPlay", streamStartPlayHandler); player.on("stopplay", stopPlayHandler); player.on("volume", volumeHandler); player.on("userupdate", userHandler); @@ -425,6 +429,7 @@ class Dashboard { player.on("queue", queueHandler); socket.on("disconnect", () => { player.removeListener("startplay", startPlayHandler); + player.removeListener("streamStartPlay", streamStartPlayHandler); player.removeListener("stopplay", stopPlayHandler); player.removeListener("volume", volumeHandler); player.removeListener("userupdate", userHandler); @@ -438,7 +443,7 @@ class Dashboard { socket.emit("info", { connected: !!d.voice, ...currInfo(this.remix.client.channels.get(con.channelId)), - currSong: (!!d.voice) ? getSongData(d.player.data.current, d.player) : null, + currSong: (!!d.voice) ? {...getSongData(d.player.data.current, d.player), elapsedTime: d.player.player.seconds * 1000} : null, currData: (!!d.voice) ? getPlayerData(d.player) : null }); if (!!d.voice) subscribePlayer(d.player, socket); diff --git a/dashboard/views/components/player.ejs b/dashboard/views/components/player.ejs index d8c0148..3361232 100644 --- a/dashboard/views/components/player.ejs +++ b/dashboard/views/components/player.ejs @@ -826,6 +826,7 @@ } const resetTime = () => { elapsedTime.innerText = "00:00"; + duration.innerText = "00:00" } function update(vid) { diff --git a/dashboard/views/dashboard/index.ejs b/dashboard/views/dashboard/index.ejs index 7e85be4..77aa647 100644 --- a/dashboard/views/dashboard/index.ejs +++ b/dashboard/views/dashboard/index.ejs @@ -194,7 +194,10 @@ renderQueue(info.currData.queue); } if (info.channel) updateCDisplay(info); - if (info.currSong) update(info.currSong); + if (info.currSong) { + update(info.currSong); + if (info.currSong.elapsedTime > 0) startTime(info.currSong.elapsedTime); + } if (info.channel) enablePlayer(); }); socket.on("joined", (data) => { @@ -222,10 +225,16 @@ }) socket.on("left", () => { resetPlayer(); updateCDisplay({ channel: { name: "-" }, server: { name: "-" } }) }); socket.on("startplay", (vid) => { - startTime(0); - update(vid); + pauseTime(0); + resetTime(); + update(vid) + }); + socket.on("streamStartPlay", () => startTime(0)) + socket.on("stopplay", () => { + pauseTime(0); + resetTime(); + resetPlayer(); }); - socket.on("stopplay", () => resetPlayer()); socket.on("volume", (v) => setVolume(v * 100)); socket.on("queue", (d) => updateQueue(d)); diff --git a/package-lock.json b/package-lock.json index 7e8e1db..1501eec 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "remix-revolt", + "name": "remix", "lockfileVersion": 2, "requires": true, "packages": { @@ -21,7 +21,7 @@ "i18next-fs-backend": "^2.1.5", "mysql": "^2.18.1", "prism-media": "^1.3.5", - "revoice.js": "^0.1.754", + "revoice.js": "^0.1.7541", "revolt-uploader": "^1.1.0", "revolt.js": "npm:revolt.js-update@^7.0.0-beta.9-fix2.0", "revoltbots.js": "^1.0.5", @@ -33,7 +33,7 @@ "youtubei.js": "^5.1.0", "yt-dlp-wrap-extended": "^2.3.15", "yt-search": "^2.10.4", - "ytdl-core": "npm:@distube/ytdl-core@^4.11.9" + "ytdl-core": "npm:@distube/ytdl-core@^4.13.2" } }, "node_modules/@ampproject/remapping": { @@ -4225,9 +4225,9 @@ } }, "node_modules/revoice.js": { - "version": "0.1.754", - "resolved": "https://registry.npmjs.org/revoice.js/-/revoice.js-0.1.754.tgz", - "integrity": "sha512-737lVt1W9Pq2UAV4ycoMox14Ktw8MQQEWSo5k8SHSt3PMToT7Fg/gcuvbSsITV3LmzP/4V8Z0v7gyxouDK9GLA==", + "version": "0.1.7541", + "resolved": "https://registry.npmjs.org/revoice.js/-/revoice.js-0.1.7541.tgz", + "integrity": "sha512-RQxUYfvDS7lSUN7+ORND6oHhkYTy1z/y7JJikxUoYZd925sNX+wBCVAlx2ZQt8JnfsNqCn1EGayavCLWKF9jJg==", "dependencies": { "better-docs": "^2.7.2", "ffmpeg-static": "^5.0.2", @@ -5568,14 +5568,15 @@ }, "node_modules/ytdl-core": { "name": "@distube/ytdl-core", - "version": "4.11.9", - "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.11.9.tgz", - "integrity": "sha512-wlQu48gG9eV8YCASpra1bw2iXIlc3FuF/WiB8akBGmrp/jd9tGvuxwgOH5oKYQZYSSjzazsW2VX7L5rt+8Fu5Q==", + "version": "4.13.2", + "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.13.2.tgz", + "integrity": "sha512-FBjy4LXsBv34qFrmEF1dSbKWQtqB+yd0dt4MYYUq8oYys2Bvqps3QSFGTUZO5QA6nKD/XRsMJfcG5lgEJaUqiQ==", "dependencies": { + "http-cookie-agent": "^5.0.4", "m3u8stream": "^0.8.6", - "miniget": "^4.2.2", "sax": "^1.2.4", - "undici": "^5.22.0" + "tough-cookie": "^4.1.3", + "undici": "^5.25.2" }, "engines": { "node": ">=12" @@ -8430,9 +8431,9 @@ } }, "revoice.js": { - "version": "0.1.754", - "resolved": "https://registry.npmjs.org/revoice.js/-/revoice.js-0.1.754.tgz", - "integrity": "sha512-737lVt1W9Pq2UAV4ycoMox14Ktw8MQQEWSo5k8SHSt3PMToT7Fg/gcuvbSsITV3LmzP/4V8Z0v7gyxouDK9GLA==", + "version": "0.1.7541", + "resolved": "https://registry.npmjs.org/revoice.js/-/revoice.js-0.1.7541.tgz", + "integrity": "sha512-RQxUYfvDS7lSUN7+ORND6oHhkYTy1z/y7JJikxUoYZd925sNX+wBCVAlx2ZQt8JnfsNqCn1EGayavCLWKF9jJg==", "requires": { "better-docs": "^2.7.2", "ffmpeg-static": "^5.0.2", @@ -9373,14 +9374,15 @@ } }, "ytdl-core": { - "version": "npm:@distube/ytdl-core@4.11.9", - "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.11.9.tgz", - "integrity": "sha512-wlQu48gG9eV8YCASpra1bw2iXIlc3FuF/WiB8akBGmrp/jd9tGvuxwgOH5oKYQZYSSjzazsW2VX7L5rt+8Fu5Q==", + "version": "npm:@distube/ytdl-core@4.13.2", + "resolved": "https://registry.npmjs.org/@distube/ytdl-core/-/ytdl-core-4.13.2.tgz", + "integrity": "sha512-FBjy4LXsBv34qFrmEF1dSbKWQtqB+yd0dt4MYYUq8oYys2Bvqps3QSFGTUZO5QA6nKD/XRsMJfcG5lgEJaUqiQ==", "requires": { + "http-cookie-agent": "^5.0.4", "m3u8stream": "^0.8.6", - "miniget": "^4.2.2", "sax": "^1.2.4", - "undici": "^5.22.0" + "tough-cookie": "^4.1.3", + "undici": "^5.25.2" } } } diff --git a/package.json b/package.json index 5a948f0..f01bac8 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "i18next-fs-backend": "^2.1.5", "mysql": "^2.18.1", "prism-media": "^1.3.5", - "revoice.js": "^0.1.754", + "revoice.js": "^0.1.7541", "revolt-uploader": "^1.1.0", "revolt.js": "npm:revolt.js-update@^7.0.0-beta.9-fix2.0", "revoltbots.js": "^1.0.5", @@ -28,7 +28,7 @@ "youtubei.js": "^5.1.0", "yt-dlp-wrap-extended": "^2.3.15", "yt-search": "^2.10.4", - "ytdl-core": "npm:@distube/ytdl-core@^4.11.9" + "ytdl-core": "npm:@distube/ytdl-core@^4.13.2" }, "scripts": { "dev": "node --inspect index.js --trace-warnings",