Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
dispatcher updates
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Apr 20, 2022
1 parent 296efd9 commit dd265be
Show file tree
Hide file tree
Showing 11 changed files with 477 additions and 34 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,26 @@ client.on("messageCreate", message => {
client.login("XXX");
```

See **[https://github.com/discord-player/voice-recorder-example](https://github.com/discord-player/voice-recorder-example)** for a complete voice recorder example.
> See **[https://github.com/discord-player/voice-recorder-example](https://github.com/discord-player/voice-recorder-example)** for a complete voice recorder example.
### Smooth Volume

This feature enables smooth volume transition.

> This library will attempt to polyfill smooth volume api by default. This can be disabled by setting `DARTJS_DISABLE_INJECTION` in env.
**Example:**

```js
// injecting manually
require("dartjs").injectSmoothVolume();

// Set smoothness before playing
dispatcher.play(stream, {
// use whatever value feels better
volumeSmoothness: 0.08
});

// setting smoothness on-the-fly
dispatcher.setVolumeSmoothness(0.08)
```
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dartjs",
"version": "1.1.1",
"version": "1.2.0",
"description": "Very simple framework that provides discord.js v12 voice interface",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down Expand Up @@ -34,7 +34,9 @@
"v13",
"discord.js-v12-voice",
"discord.js-v13-voice",
"discord.js-v12-voice-v13"
"discord.js-v12-voice-v13",
"polyfill",
"discord-player"
],
"author": "DevAndromeda",
"license": "MIT",
Expand All @@ -43,6 +45,7 @@
},
"homepage": "https://github.com/DevAndromeda/typescript-template#readme",
"devDependencies": {
"@discordjs/opus": "^0.7.0",
"@favware/rollup-type-bundler": "^1.0.3",
"@types/node": "^16.7.1",
"@typescript-eslint/eslint-plugin": "^4.29.2",
Expand All @@ -58,7 +61,7 @@
"tweetnacl": "^1.0.3",
"typescript": "^4.3.5",
"youtube-sr": "^4.1.13",
"ytdl-core": "^4.10.1"
"ytdl-core": "^4.11.0"
},
"dependencies": {
"@discordjs/voice": "^0.8.0"
Expand Down
4 changes: 4 additions & 0 deletions src/Utils/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ export function wait(duration: number) {
setTimeout(resolve, duration).unref();
});
}

export function randomId() {
return `${Date.now()}::${Math.random().toString(32)}`;
}
21 changes: 15 additions & 6 deletions src/core/DartVoiceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export default class DartVoiceManager {
public connections = new Collection<Snowflake, VoiceConnection>();
public constructor(public readonly client: Client) {}

/**
* Join a voice channel
* @param channel The voice based channel
* @param options Join config
*/
public async join(channel: GuildVoiceChannelResolvable, options?: VoiceJoinConfig) {
const vc = this.client.channels.resolve(channel ?? "");
if (!vc || !vc.isVoice()) throw new Error("Voice channel was not provided!");
Expand All @@ -16,12 +21,7 @@ export default class DartVoiceManager {
}

if (this.connections.has(vc.guildId)) {
if (this.connections.get(vc.guildId).channel.id !== vc.id) {
return await this.updateChannel(this.connections.get(vc.guildId), vc);
} else {
const connection = this.connections.get(vc.guildId);
return connection;
}
return await this.updateChannel(this.connections.get(vc.guildId), vc);
} else {
const connection = await VoiceConnection.createConnection(vc, this, options);
this.connections.set(vc.guildId, connection);
Expand All @@ -30,6 +30,10 @@ export default class DartVoiceManager {
}
}

/**
* Leave a voice channel
* @param channel The voice channel
*/
public leave(channel: GuildVoiceChannelResolvable) {
const vc = this.client.channels.resolve(channel ?? "");
if (!vc || !vc.isVoice()) throw new Error("Voice channel was not provided!");
Expand All @@ -46,6 +50,11 @@ export default class DartVoiceManager {
this.connections.delete(vc.guildId);
}

/**
* Update voice connection
* @param connection The voice connection
* @param channel The new voice channel
*/
public async updateChannel(connection: VoiceConnection, channel: VoiceChannels) {
const vc = await VoiceConnection.joinChannel(channel);
connection.voice = vc;
Expand Down
Loading

0 comments on commit dd265be

Please sign in to comment.