Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

owo #1

Closed
wants to merge 96 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
be32bbc
really really really messy implementation of prism
amishshah Dec 28, 2016
8cf520d
update streamDispatcher
amishshah Dec 28, 2016
8e75b47
add back seek option
amishshah Dec 28, 2016
0a47d0e
Remove old stuff
amishshah Dec 28, 2016
4294d26
Add playFile back to voice connection
amishshah Dec 28, 2016
00254f3
Make voice return streamdispatcher
amishshah Dec 28, 2016
e7824d6
Fix weird audio playback bug between subsequent streams on an AudioPl…
amishshah Dec 28, 2016
e64d9c6
fix odd bug
amishshah Dec 28, 2016
18e04d6
Delete stream setups after they have ended or errored
amishshah Dec 29, 2016
e1d01ed
Merge branch 'indev' into indev-prism
amishshah Dec 29, 2016
627a887
change error emission logic
amishshah Dec 29, 2016
1452fa5
Merge branch 'indev' into indev-prism
amishshah Dec 29, 2016
4541b3e
Simplify check in StreamDispatcher and add test voice bot
amishshah Dec 29, 2016
f8440ad
Merge branch 'indev' into indev-prism
amishshah Dec 29, 2016
e9af3f0
Merge branch 'indev' into indev-prism
amishshah Dec 29, 2016
72a99f9
start work with broadcast streams
amishshah Dec 29, 2016
ad18b05
Reset what is playing
amishshah Dec 29, 2016
1260557
Add VoiceBroadcast.pause and VoiceBroadcast.resume
amishshah Dec 29, 2016
c6f1705
Remove unused fs import
amishshah Dec 29, 2016
77548c1
Add missing type
Gawdl3y Dec 30, 2016
89cea57
Add prism-media dependency
Gawdl3y Dec 30, 2016
b5f51d6
Merge branch 'master' into indev-prism
Gawdl3y Dec 30, 2016
2f630a0
AudioPlayer now destroys all dispatchers on closing, Broadcasts are a…
amishshah Dec 30, 2016
bf4010e
Simplify broadcast creation
amishshah Dec 30, 2016
91fc6cc
VoiceBroadcasting much more efficient
amishshah Dec 30, 2016
22a6ded
Defer some creations
amishshah Dec 30, 2016
90ca422
undo that
amishshah Dec 30, 2016
0a6d71d
try this fix idk
amishshah Dec 30, 2016
fb1d0a3
fix eslint
amishshah Dec 30, 2016
3109acc
improve broadcasting performance
amishshah Dec 30, 2016
f31a372
StreamDispatcher documentation
amishshah Dec 30, 2016
221e7f8
Voice Connection docs
amishshah Dec 30, 2016
69ccc75
more voice docs
amishshah Dec 30, 2016
56e0129
Merge branch 'master' into indev-prism
amishshah Dec 30, 2016
d13c48b
more tiny voice docs
amishshah Dec 30, 2016
e275313
Reorganise VoiceBroadcast dispatchers and also add new events
amishshah Dec 30, 2016
ac62a58
Merge branch 'master' into indev-prism
amishshah Dec 30, 2016
eacbfbd
Add VoiceBroadcast#playArbitraryInput and VoiceConnection#playArbitra…
amishshah Dec 30, 2016
91e0a81
Add playArbitraryInput
amishshah Dec 30, 2016
8d8ac78
start voice topics
amishshah Dec 30, 2016
814c4e8
Merge branch 'master' into indev-prism
Gawdl3y Dec 30, 2016
bac599b
Merge branch 'master' into indev-prism
Gawdl3y Jan 7, 2017
bace8bc
make broadcast not suck as much
amishshah Jan 7, 2017
fcd7cf1
stop destructive ending of broadcasts
amishshah Jan 7, 2017
dc64001
Fix some stream bugs
amishshah Jan 7, 2017
0df17b1
Add broadcast.destroy();
amishshah Jan 7, 2017
de0ba9f
change error to debug
amishshah Jan 7, 2017
9f8289e
don't process empty sets
amishshah Jan 7, 2017
3b1264a
Fix Buffer deprecation stuff
amishshah Jan 7, 2017
adbd95a
Fix VoiceBroadcaster per-dispatcher volume (#1073)
aemino Jan 8, 2017
391b618
Merge branch 'indev-prism' of https://github.com/hydrabolt/discord.js…
amishshah Jan 8, 2017
b502690
Remove DMChannel.bulkDelete and GroupDMChannel.bulkDelete
amishshah Jan 9, 2017
f7a4dee
Merge branch 'master' into indev-prism
amishshah Jan 13, 2017
098ad19
Merge branch 'master' into indev-prism
amishshah Jan 14, 2017
ba465bc
Merge branch 'master' into indev-prism
amishshah Jan 15, 2017
b13fdcc
Merged master into indev-prism
Gawdl3y Jan 19, 2017
9a6cb64
VoiceReceiver: multiple streams fix (#1132)
aemino Jan 26, 2017
6fae179
Added try catch so that decode errors aren't fatal (#1146)
Fiddlekins Jan 29, 2017
7ed58f5
Added Opus stream support, added volume interface (#1102)
aemino Jan 29, 2017
78dafb9
Properly check whether an Opus engine exists (#1150)
aemino Jan 30, 2017
e8ac184
Merge branch 'master' into indev-prism
Feb 1, 2017
02c23a8
Merge branch 'master' into indev-prism
Feb 1, 2017
4994474
Sodium (#1172)
macdja38 Feb 6, 2017
d6f17a9
Merge branch 'master' into indev-prism
Gawdl3y Feb 6, 2017
0f6fcee
Update voice webpack exclusions
Gawdl3y Feb 6, 2017
a90bd83
Add sodium to optional packages list
Gawdl3y Feb 6, 2017
b91f8f2
Fix resolveBuffer file failure behaviour
Gawdl3y Feb 15, 2017
8d620ac
Update typings
Gawdl3y Feb 16, 2017
63ffd8a
Clarify bufferutil scenario a bit
Gawdl3y Feb 16, 2017
7232531
Move all util methods into class
Gawdl3y Feb 16, 2017
05bba9b
Remove old comment part
Gawdl3y Feb 18, 2017
12136f8
Welcome example (#1194)
Feb 18, 2017
1273bb4
Doc fixes (#1197)
Feb 19, 2017
d870b27
Message#member should be a nullable. (#1205)
hkwu Feb 21, 2017
f2a6c1d
Improve Client docs a bit more
Gawdl3y Feb 21, 2017
d4a8491
Add timeout/interval methods to WebhookClient (fixes #1181), and clea…
devsnek Feb 21, 2017
db5259c
Add RichEmbed#attachFile (#1202)
zajrik Feb 21, 2017
8d1bc30
Clean up dd6dd6f
Gawdl3y Feb 21, 2017
b0338df
Add more required permissions to Guild#addMember
Gawdl3y Feb 21, 2017
d09dfa4
Capitalize channel type constants (#1209)
aemino Feb 22, 2017
61e12c6
Add support for more OAuth features (#1203)
devsnek Feb 22, 2017
f01b3f9
Update typings submodule (#1206)
zajrik Feb 22, 2017
eb069d0
Added volumeChange event to VoiceInterface (#1207)
aemino Feb 22, 2017
566135d
move permission stuff to the resolver (#1185)
devsnek Feb 22, 2017
7fd94c2
VoiceConnection rework (#1183)
aemino Feb 22, 2017
f068010
Implement 'Modify Guild Channel Positions' (#1198)
cas-c Feb 22, 2017
5c2086b
Allow presence updating to allow null games (#1186)
JoschuaSchneider Feb 22, 2017
4c9d8d6
add lots of group dm features (#1208)
devsnek Feb 22, 2017
8a2ec43
Merge branch 'master' into indev-prism
amishshah Feb 22, 2017
b55e692
merge fix
amishshah Feb 22, 2017
bf25caf
Updated VoiceConnection to use new Util class (#1210)
aemino Feb 22, 2017
15240cf
Fix contributing link on docs site, link node.js
Gawdl3y Feb 23, 2017
af3d478
Add a word
Gawdl3y Feb 23, 2017
70b35c8
Merge branch 'indev-prism'
amishshah Feb 23, 2017
53209fb
update typings
amishshah Feb 23, 2017
76637ed
Fix VoiceDispatcher docs (#1214)
aemino Feb 24, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</div>

## About
discord.js is a powerful node.js module that allows you to interact with the
discord.js is a powerful [node.js](https://nodejs.org) module that allows you to interact with the
[Discord API](https://discordapp.com/developers/docs/intro) very easily.

- Object-oriented
Expand All @@ -27,7 +27,7 @@ discord.js is a powerful node.js module that allows you to interact with the

## Installation
**Node.js 6.0.0 or newer is required.**
Ignore any warnings about unmet peer dependencies, as they're optional.
Ignore any warnings about unmet peer dependencies, as they're all optional.

Without voice support: `npm install discord.js --save`
With voice support ([node-opus](https://www.npmjs.com/package/node-opus)): `npm install discord.js node-opus --save`
Expand All @@ -39,8 +39,9 @@ Using opusscript is only recommended for development environments where node-opu
For production bots, using node-opus should be considered a necessity, especially if they're going to be running on multiple servers.

### Optional packages
- [bufferutil](https://www.npmjs.com/package/bufferutil) to greatly speed up the `ws` WebSocket connection (`npm install bufferutil --save`)
- [bufferutil](https://www.npmjs.com/package/bufferutil) to greatly speed up the WebSocket when *not* using uws (`npm install bufferutil --save`)
- [erlpack](https://github.com/hammerandchisel/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install hammerandchisel/erlpack --save`)
- [sodium](https://www.npmjs.com/package/sodium) for faster voice packet encryption/decryption (`npm install sodium --save`)
- [uws](https://www.npmjs.com/package/uws) for a much faster WebSocket connection (`npm install uws --save`)
**Note:** This package does not handle disconnects entirely correctly, which causes automatic reconnection to Discord to not function.
If you use this package, it may be wise to destroy + recreate the client entirely or restart the process upon disconnect.
Expand Down Expand Up @@ -77,7 +78,7 @@ A bot template using discord.js can be generated using [generator-discordbot](ht
## Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
[documentation](https://discord.js.org/#/docs).
See [the contribution guide](CONTRIBUTING.md) if you'd like to submit a PR.
See [the contribution guide](https://github.com/hydrabolt/discord.js/blob/master/CONTRIBUTING.md) if you'd like to submit a PR.

## Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// import the discord.js module
const Discord = require('discord.js');

// create an instance of a Discord Client, and call it bot
// create an instance of a Discord Client
const client = new Discord.Client();

// the token of your bot - https://discordapp.com/developers/applications/me
Expand Down
33 changes: 33 additions & 0 deletions docs/examples/greeting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
A bot that welcomes new guild members when they join
*/

// import the discord.js module
const Discord = require('discord.js');

// create an instance of a Discord Client
const client = new Discord.Client();

// the token of your bot - https://discordapp.com/developers/applications/me
const token = 'your bot token here';

// the ID of the channel in which the bot will greet new users
const channelID = 'your channel ID here';

// the ready event is vital, it means that your bot will only start reacting to information
// from Discord _after_ ready is emitted.
client.on('ready', () => {
console.log('I am ready!');
});

// create an event listener for new guild members
client.on('guildMemberAdd', member => {
// get the channel by its ID
const channel = client.channels.get(channelID);

// send the message, mentioning the member
channel.sendMessage(`Welcome to the server, ${member}!`);
});

// log our bot in
client.login(token);
9 changes: 5 additions & 4 deletions docs/general/welcome.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Welcome to the discord.js v11 documentation.
v11 contains loads of new and improved features, optimisations, and bug fixes.

## About
discord.js is a powerful node.js module that allows you to interact with the
discord.js is a powerful [node.js](https://nodejs.org) module that allows you to interact with the
[Discord API](https://discordapp.com/developers/docs/intro) very easily.

- Object-oriented
Expand All @@ -31,7 +31,7 @@ discord.js is a powerful node.js module that allows you to interact with the

## Installation
**Node.js 6.0.0 or newer is required.**
Ignore any warnings about unmet peer dependencies, as they're optional.
Ignore any warnings about unmet peer dependencies, as they're all optional.

Without voice support: `npm install discord.js --save`
With voice support ([node-opus](https://www.npmjs.com/package/node-opus)): `npm install discord.js node-opus --save`
Expand All @@ -43,8 +43,9 @@ Using opusscript is only recommended for development environments where node-opu
For production bots, using node-opus should be considered a necessity, especially if they're going to be running on multiple servers.

### Optional packages
- [bufferutil](https://www.npmjs.com/package/bufferutil) to greatly speed up the `ws` WebSocket connection (`npm install bufferutil --save`)
- [bufferutil](https://www.npmjs.com/package/bufferutil) to greatly speed up the WebSocket when *not* using uws (`npm install bufferutil --save`)
- [erlpack](https://github.com/hammerandchisel/erlpack) for significantly faster WebSocket data (de)serialisation (`npm install hammerandchisel/erlpack --save`)
- [sodium](https://www.npmjs.com/package/sodium) for faster voice packet encryption/decryption (`npm install sodium --save`)
- [uws](https://www.npmjs.com/package/uws) for a much faster WebSocket connection (`npm install uws --save`)
**Note:** This package does not handle disconnects entirely correctly, which causes automatic reconnection to Discord to not function.
If you use this package, it may be wise to destroy + recreate the client entirely or restart the process upon disconnect.
Expand Down Expand Up @@ -81,7 +82,7 @@ A bot template using discord.js can be generated using [generator-discordbot](ht
## Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
[documentation](https://discord.js.org/#/docs).
See [the contribution guide](CONTRIBUTING.md) if you'd like to submit a PR.
See [the contribution guide](https://github.com/hydrabolt/discord.js/blob/master/CONTRIBUTING.md) if you'd like to submit a PR.

## Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle
Expand Down
4 changes: 4 additions & 0 deletions docs/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
path: faq.md
- name: Topics
files:
- name: Voice
path: voice.md
- name: Web builds
path: web.md
- name: Examples
Expand All @@ -16,5 +18,7 @@
path: ping.js
- name: Avatars
path: avatars.js
- name: Server greeting
path: greeting.js
- name: Webhook
path: webhook.js
109 changes: 109 additions & 0 deletions docs/topics/voice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Introduction to Voice
Voice in discord.js can be used for many things, such as music bots, recording or relaying audio.

In discord.js, you can use voice by connecting to a `VoiceChannel` to obtain a `VoiceConnection`, where you can start streaming and receiving audio.

To get started, make sure you have:
* ffmpeg - `npm install --global ffmpeg-binaries`
* an opus encoder, choose one from below:
* `npm install opusscript`
* `npm install node-opus`
* a good network connection

## Joining a voice channel
The example below reacts to a message and joins the sender's voice channel, catching any errors. This is important
as it allows us to obtain a `VoiceConnection` that we can start to stream audio with

```js
const Discord = require('discord.js');
const client = new Discord.Client();

client.login('token here');

client.on('message', message => {
// voice only works in guilds, if the message does not come from a guild,
// we ignore it
if (!message.guild) return;

if (message.content === '/join') {
// only try to join the sender's voice channel if they are in one themselves
if (message.member.voiceChannel) {
message.member.voiceChannel.join()
.then(connection => { // connection is an instance of VoiceConnection
message.reply('I have successfully connected to the channel!');
})
.catch(console.log);
} else {
message.reply('You need to join a voice channel first!');
}
}
});
```

## Streaming to a Voice Channel
In the previous example, we looked at how to join a voice channel in order to obtain a `VoiceConnection`. Now that we
have obtained a voice connection, we can start streaming audio to it. The following example shows how to stream an mp3
file:

**Playing a file:**
```js
// to play a file, we need to give an absolute path to it
const dispatcher = connection.playFile('C:/Users/Discord/Desktop/myfile.mp3');
```

Your file doesn't have to be just an mp3; ffmpeg can convert videos and audios of many formats.

The `dispatcher` variable is an instance of a `StreamDispatcher`, which manages streaming a specific resource to a voice
channel. We can do many things with the dispatcher, such as finding out when the stream ends or changing the volume:

```js
dispatcher.on('end', () => {
// the song has finished
});

dispatcher.on('error', e => {
// catch any errors that may arise
console.log(e);
});

dispatcher.setVolume(0.5); // set the volume to 50%
dispatcher.setVolume(1); // set the volume back to 100%

console.log(dispatcher.time); // the time in milliseconds that the stream dispatcher has been playing for

dispatcher.pause(); // pause the stream
dispatcher.resume(); // carry on playing

dispatcher.end(); // end the dispatcher, emits 'end' event
```

If you have an existing [ReadableStream](https://nodejs.org/api/stream.html#stream_readable_streams),
this can also be used:

**Playing a ReadableStream:**
```js
connection.playStream(myReadableStream);

// if you don't want to use absolute paths, you can use
// fs.createReadStream to circumvent it

const fs = require('fs');
const stream = fs.createReadStream('./test.mp3');
connection.playStream(stream);
```

It's important to note that creating a readable stream to a file is less efficient than simply using `connection.playFile()`.

**Playing anything else:**

For anything else, such as a URL to a file, you can use `connection.playArbitraryInput()`. You should consult the [ffmpeg protocol documentation](https://ffmpeg.org/ffmpeg-protocols.html) to see what you can use this for.

```js
// play an mp3 from a URL
connection.playArbitraryInput('http://mysite.com/sound.mp3');
```

Again, playing a file from a URL like this is more performant than creating a ReadableStream to the file.

## Advanced Topics
soon:tm:
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@types/node": "^7.0.0",
"long": "^3.2.0",
"pako": "^1.0.0",
"prism-media": "hydrabolt/prism-media",
"superagent": "^3.4.0",
"tweetnacl": "^0.14.0",
"ws": "^2.0.0"
Expand All @@ -44,6 +45,7 @@
"erlpack": "hammerandchisel/erlpack",
"node-opus": "^0.2.0",
"opusscript": "^0.0.2",
"sodium": "^2.0.1",
"uws": "^0.12.0"
},
"devDependencies": {
Expand All @@ -60,9 +62,11 @@
"ws": false,
"uws": false,
"erlpack": false,
"prism-media": false,
"opusscript": false,
"node-opus": false,
"tweetnacl": false,
"sodium": false,
"src/sharding/Shard.js": false,
"src/sharding/ShardClientUtil.js": false,
"src/sharding/ShardingManager.js": false,
Expand All @@ -75,12 +79,13 @@
"src/client/voice/pcm/ConverterEngineList.js": false,
"src/client/voice/pcm/FfmpegConverterEngine.js": false,
"src/client/voice/player/AudioPlayer.js": false,
"src/client/voice/player/BasePlayer.js": false,
"src/client/voice/player/DefaultPlayer.js": false,
"src/client/voice/receiver/VoiceReadable.js": false,
"src/client/voice/receiver/VoiceReceiver.js": false,
"src/client/voice/util/Secretbox.js": false,
"src/client/voice/util/SecretKey.js": false,
"src/client/voice/util/VolumeInterface.js": false,
"src/client/voice/ClientVoiceManager.js": false,
"src/client/voice/VoiceBroadcast.js": false,
"src/client/voice/VoiceConnection.js": false,
"src/client/voice/VoiceUDPClient.js": false,
"src/client/voice/VoiceWebSocket.js": false
Expand Down
Loading