From 399105eec98c58cdf34a006e495f98742ba98d50 Mon Sep 17 00:00:00 2001 From: DevAndromeda <46562212+DevAndromeda@users.noreply.github.com> Date: Wed, 21 Jul 2021 11:12:40 +0545 Subject: [PATCH] feat(Queue): add bufferingTimeout --- package.json | 6 +++--- src/Structures/Queue.ts | 18 +++++++++++++---- src/types/types.ts | 2 ++ yarn.lock | 43 ++++++++++++++++++++++++----------------- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 94d251c..48ccacf 100644 --- a/package.json +++ b/package.json @@ -52,14 +52,14 @@ }, "homepage": "https://discord-player.js.org", "dependencies": { - "@discordjs/voice": "^0.5.3", + "@discordjs/voice": "^0.5.4", "discord-ytdl-core": "^5.0.4", "libsodium-wrappers": "^0.7.9", "soundcloud-scraper": "^5.0.0", "spotify-url-info": "^2.2.3", "tiny-typed-emitter": "^2.0.3", "youtube-sr": "^4.1.7", - "ytdl-core": "^4.8.3" + "ytdl-core": "^4.9.0" }, "devDependencies": { "@babel/cli": "^7.14.5", @@ -74,7 +74,7 @@ "@typescript-eslint/eslint-plugin": "^4.28.1", "@typescript-eslint/parser": "^4.28.1", "discord-api-types": "^0.18.1", - "discord.js": "^13.0.0-dev.d6c43a5.1625875428", + "discord.js": "^13.0.0-dev.1e90be8.1626825831", "eslint": "^7.30.0", "jsdoc-babel": "^0.5.0", "prettier": "^2.3.2", diff --git a/src/Structures/Queue.ts b/src/Structures/Queue.ts index 323113e..aa18865 100644 --- a/src/Structures/Queue.ts +++ b/src/Structures/Queue.ts @@ -99,7 +99,8 @@ class Queue { leaveOnEmptyCooldown: 1000, autoSelfDeaf: true, ytdlOptions: {}, - initialVolume: 100 + initialVolume: 100, + bufferingTimeout: 1000 } as PlayerOptions, options ); @@ -644,9 +645,11 @@ class Queue { if (options.seek) this._streamTime = options.seek; this._filtersUpdate = options.filtersUpdate; - this.connection.playStream(resource).then(() => { - this.setVolume(this.options.initialVolume); - }); + setTimeout(() => { + this.connection.playStream(resource).then(() => { + this.setVolume(this.options.initialVolume); + }); + }, this.#getBufferingTimeout()); } /** @@ -717,6 +720,13 @@ class Queue { #watchDestroyed() { if (this.#destroyed) throw new Error("Cannot use destroyed queue"); } + + #getBufferingTimeout() { + const timeout = this.options.bufferingTimeout; + + if (isNaN(timeout) || timeout < 0 || !Number.isFinite(timeout)) return 1000; + return timeout; + } } export { Queue }; diff --git a/src/types/types.ts b/src/types/types.ts index 7a40ce2..8b1d470 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -127,6 +127,7 @@ export interface PlayerProgressbarOptions { * @property {boolean} [autoSelfDeaf=true] If it should set the bot in deaf mode * @property {YTDLDownloadOptions} [ytdlOptions={}] The youtube download options * @property {number} [initialVolume=100] The initial player volume + * @property {number} [bufferingTimeout=1000] Buffering timeout for the stream */ export interface PlayerOptions { leaveOnEnd?: boolean; @@ -136,6 +137,7 @@ export interface PlayerOptions { autoSelfDeaf?: boolean; ytdlOptions?: downloadOptions; initialVolume?: number; + bufferingTimeout?: number; } /** diff --git a/yarn.lock b/yarn.lock index d515e7f..7e85724 100644 --- a/yarn.lock +++ b/yarn.lock @@ -981,10 +981,10 @@ "@discordjs/node-pre-gyp" "^0.4.0" node-addon-api "^3.2.1" -"@discordjs/voice@^0.5.3": - version "0.5.3" - resolved "https://registry.yarnpkg.com/@discordjs/voice/-/voice-0.5.3.tgz#fbb1821b64d3dff1d379ec3821d632f1e11b95bb" - integrity sha512-We7rumaR6prv/nHavWQzo/4Qk8enROWJ0Y8Zpe5GwI8vRXxas0Tn+oiD7PE+VTmIAx3QyMuB3l26mHv7zydTdQ== +"@discordjs/voice@^0.5.4": + version "0.5.4" + resolved "https://registry.yarnpkg.com/@discordjs/voice/-/voice-0.5.4.tgz#02af74778177be8f42772118ba2193af481f442e" + integrity sha512-CLkJH1YXHhLyocvwAgIJBeyCe3iBVvg6pDPcJUEAwg09TykjJRH6qSpg2ly858WffzR7jOsLcliODAOMDwKtnA== dependencies: "@types/ws" "^7.4.4" discord-api-types "^0.18.1" @@ -1099,13 +1099,20 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.1.tgz#24691fa2b0c3ec8c0d34bfcfd495edac5593ebb4" integrity sha512-N87VuQi7HEeRJkhzovao/JviiqKjDKMVKxKMfUvSKw+MbkbW8R0nA3fi/MQhhlxV2fQ+2ReM+/Nt4efdrJx3zA== -"@types/ws@^7.4.4", "@types/ws@^7.4.5", "@types/ws@^7.4.6": +"@types/ws@^7.4.4", "@types/ws@^7.4.6": version "7.4.6" resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.6.tgz#c4320845e43d45a7129bb32905e28781c71c1fff" integrity sha512-ijZ1vzRawI7QoWnTNL8KpHixd2b2XVb9I9HAqI3triPsh1EC0xH0Eg6w2O3TKbDCgiNNlJqfrof6j4T2I+l9vw== dependencies: "@types/node" "*" +"@types/ws@^7.4.5": + version "7.4.7" + resolved "https://registry.yarnpkg.com/@types/ws/-/ws-7.4.7.tgz#f7c390a36f7a0679aa69de2d501319f4f8d9b702" + integrity sha512-JQbbmxZTZehdc2iszGKs5oC3NFnjeay7mtAWrdt7qNtAVK0g19muApzAy4bm9byz79xa2ZnO/BOBC2R8RC5Lww== + dependencies: + "@types/node" "*" + "@typescript-eslint/eslint-plugin@^4.28.1": version "4.28.2" resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-4.28.2.tgz#7a8320f00141666813d0ae43b49ee8244f7cf92a" @@ -2018,10 +2025,10 @@ discord-api-types@^0.18.1: resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.18.1.tgz#5d08ed1263236be9c21a22065d0e6b51f790f492" integrity sha512-hNC38R9ZF4uaujaZQtQfm5CdQO58uhdkoHQAVvMfIL0LgOSZeW575W8H6upngQOuoxWd8tiRII3LLJm9zuQKYg== -discord-api-types@^0.19.0-next.f393ba520d7d6d2aacaca7b3ca5d355fab614f6e: - version "0.19.0-next.f393ba520d7d6d2aacaca7b3ca5d355fab614f6e" - resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.19.0-next.f393ba520d7d6d2aacaca7b3ca5d355fab614f6e.tgz#d5f36f5712ec8fe2fe928b5c37618c94a3969d6a" - integrity sha512-ttRA/8e/WKHDbGFfED5WlS7gID+kalmNr6iMiWBCvkphQ7kFHiTOVbnj/zX9ksaRaYXp/I38SCQ+qZvLu8DJZg== +discord-api-types@^0.19.0: + version "0.19.0" + resolved "https://registry.yarnpkg.com/discord-api-types/-/discord-api-types-0.19.0.tgz#86ba8021b29190cf860e90a2bc3e29b1d7aab3ba" + integrity sha512-t2HKLd43Lbe+rf+ffYfKVv9Kk5f6p7sFqvO6CMV55ZB0PgZv8WigCkt9FoJciYo5S3Q6CGYK+WnE/ZG+6vkBDQ== discord-ytdl-core@^5.0.4: version "5.0.4" @@ -2030,10 +2037,10 @@ discord-ytdl-core@^5.0.4: dependencies: prism-media "^1.2.9" -discord.js@^13.0.0-dev.d6c43a5.1625875428: - version "13.0.0-dev.d6c43a5.1625875428" - resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-13.0.0-dev.d6c43a5.1625875428.tgz#e8d963b33d18c7af77098e5fc6ef719972e73242" - integrity sha512-mTW3MpURf2QMjZe1O/H8owreUZttTfDyGY48Ka79l3GIJIHXOKx+hxv+yI5ve5GWF2ie6z8MPQ4hHqlTHk8OKg== +discord.js@^13.0.0-dev.1e90be8.1626825831: + version "13.0.0-dev.1e90be8.1626825831" + resolved "https://registry.yarnpkg.com/discord.js/-/discord.js-13.0.0-dev.1e90be8.1626825831.tgz#2acfc7a95482863f4bafbe54464392f8d4a8ed3d" + integrity sha512-Kv32vfxiqHzSB4HY1MfHdvf868toZde86sPOCBhvmLbKZo5XaiZKMuZgfAUv7pBriNNTA0FtKoIid/2BqjuZqg== dependencies: "@discordjs/builders" "^0.2.0" "@discordjs/collection" "^0.1.6" @@ -2041,7 +2048,7 @@ discord.js@^13.0.0-dev.d6c43a5.1625875428: "@sapphire/async-queue" "^1.1.4" "@types/ws" "^7.4.5" abort-controller "^3.0.0" - discord-api-types "^0.19.0-next.f393ba520d7d6d2aacaca7b3ca5d355fab614f6e" + discord-api-types "^0.19.0" node-fetch "^2.6.1" ws "^7.5.1" @@ -4935,10 +4942,10 @@ youtube-sr@^4.1.7: dependencies: node-fetch "^2.6.1" -ytdl-core@^4.8.3: - version "4.8.3" - resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.8.3.tgz#21570d1834db13dec7828cf87bbf4c83c0fe68d7" - integrity sha512-cWCBeX4FCgjcKmuVK384MT582RIAakpUSeMF/NPVmhO8cWiG+LeQLnBordvLolb0iXYzfUvalgmycYAE5Sy6Xw== +ytdl-core@^4.9.0: + version "4.9.0" + resolved "https://registry.yarnpkg.com/ytdl-core/-/ytdl-core-4.9.0.tgz#d166f6e7ab7c2ac344ada9568f507af1255c6406" + integrity sha512-pfuWqEIrP3iYqz5jOMmaz9m+DAzfQpt8X1jmzoOsPdYWrLMV4ml7+p/zhDi0F8IF90i4Jmd0Pq0W1awnKDatKg== dependencies: m3u8stream "^0.8.3" miniget "^4.0.0"