Skip to content

Commit

Permalink
fix: esm bug when checking library
Browse files Browse the repository at this point in the history
Fix #339
  • Loading branch information
skick1234 committed Oct 27, 2024
1 parent 6ea065c commit c96c812
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"husky": "^9.1.6",
"nano-staged": "^0.8.0",
"prettier": "^3.3.3",
"sodium-native": "^4.2.2",
"sodium-native": "^4.2.1",
"ts-node": "^10.9.2",
"tsup": "^8.3.5",
"typedoc": "^0.26.10",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/core/DisTubeVoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ export class DisTubeVoice extends TypedEmitter<DisTubeVoiceEvents> {
* Play a {@link DisTubeStream}
* @param dtStream - DisTubeStream
*/
play(dtStream: DisTubeStream) {
if (!checkEncryptionLibraries()) {
async play(dtStream: DisTubeStream) {
if (!(await checkEncryptionLibraries())) {
dtStream.kill();
throw new DisTubeError("ENCRYPTION_LIBRARIES_MISSING");
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/manager/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class QueueManager extends GuildIdManager<Queue> {
const dtStream = new DisTubeStream(stream.url, streamOptions);
dtStream.on("debug", data => this.emit(Events.FFMPEG_DEBUG, `[${queue.id}] ${data}`));
this.debug(`[${queue.id}] Started playing: ${willPlaySong}`);
queue.voice.play(dtStream);
await queue.voice.play(dtStream);
if (emitPlaySong) this.emit(Events.PLAY_SONG, queue, song);
} catch (e: any) {
this.#handlePlayingError(queue, e);
Expand Down
5 changes: 2 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,10 @@ export function isNsfwChannel(channel?: GuildTextBasedChannel): boolean {
export type Falsy = undefined | null | false | 0 | "";
export const isTruthy = <T>(x: T | Falsy): x is T => Boolean(x);

export const checkEncryptionLibraries = () => {
export const checkEncryptionLibraries = async () => {
for (const lib of ["sodium-native", "sodium", "libsodium-wrappers", "tweetnacl"]) {
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require(lib);
await import(lib);
return true;
} catch {}
}
Expand Down

0 comments on commit c96c812

Please sign in to comment.