Start some docs crap

This commit is contained in:
Amish Shah
2017-10-26 14:17:56 +01:00
parent ac0cc9a009
commit f6959a848f
2 changed files with 25 additions and 9 deletions

View File

@@ -10,6 +10,11 @@ const TIMESTAMP_INC = (48000 / 100) * CHANNELS;
const nonce = Buffer.alloc(24); const nonce = Buffer.alloc(24);
nonce.fill(0); nonce.fill(0);
/**
* @external Stream.writable
* @see {@link https://nodejs.org/api/stream.html#stream_class_stream_writable}
*/
/** /**
* The class that sends voice packet data to the voice connection. * The class that sends voice packet data to the voice connection.
* ```js * ```js
@@ -20,6 +25,7 @@ nonce.fill(0);
* }); * });
* ``` * ```
* @implements {VolumeInterface} * @implements {VolumeInterface}
* @extends {stream.Writable}
*/ */
class StreamDispatcher extends Writable { class StreamDispatcher extends Writable {
constructor(player, streamOptions) { constructor(player, streamOptions) {
@@ -64,10 +70,16 @@ class StreamDispatcher extends Writable {
super._destroy(err, cb); super._destroy(err, cb);
} }
/**
* Pauses playback
*/
pause() { pause() {
this.pausedSince = Date.now(); this.pausedSince = Date.now();
} }
/**
* Resumes playback
*/
unpause() { unpause() {
this.pausedTime += Date.now() - this.pausedSince; this.pausedTime += Date.now() - this.pausedSince;
this.pausedSince = null; this.pausedSince = null;
@@ -90,11 +102,11 @@ class StreamDispatcher extends Writable {
_playChunk(chunk) { _playChunk(chunk) {
if (this.player.dispatcher !== this) return; if (this.player.dispatcher !== this) return;
this.setSpeaking(true); this._setSpeaking(true);
this.sendPacket(this.createPacket(this._sdata.sequence, this._sdata.timestamp, chunk)); this._sendPacket(this._createPacket(this._sdata.sequence, this._sdata.timestamp, chunk));
} }
createPacket(sequence, timestamp, buffer) { _createPacket(sequence, timestamp, buffer) {
const packetBuffer = Buffer.alloc(buffer.length + 28); const packetBuffer = Buffer.alloc(buffer.length + 28);
packetBuffer.fill(0); packetBuffer.fill(0);
packetBuffer[0] = 0x80; packetBuffer[0] = 0x80;
@@ -111,24 +123,24 @@ class StreamDispatcher extends Writable {
return packetBuffer; return packetBuffer;
} }
sendPacket(packet) { _sendPacket(packet) {
let repeats = 1; let repeats = 1;
/** /**
* Emitted whenever the dispatcher has debug information. * Emitted whenever the dispatcher has debug information.
* @event StreamDispatcher#debug * @event StreamDispatcher#debug
* @param {string} info The debug info * @param {string} info The debug info
*/ */
this.setSpeaking(true); this._setSpeaking(true);
while (repeats--) { while (repeats--) {
this.player.voiceConnection.sockets.udp.send(packet) this.player.voiceConnection.sockets.udp.send(packet)
.catch(e => { .catch(e => {
this.setSpeaking(false); this._setSpeaking(false);
this.emit('debug', `Failed to send a packet ${e}`); this.emit('debug', `Failed to send a packet ${e}`);
}); });
} }
} }
setSpeaking(value) { _setSpeaking(value) {
if (this.speaking === value) return; if (this.speaking === value) return;
if (this.player.voiceConnection.status !== VoiceStatus.CONNECTED) return; if (this.player.voiceConnection.status !== VoiceStatus.CONNECTED) return;
this.speaking = value; this.speaking = value;

View File

@@ -3,6 +3,8 @@
const Discord = require('../'); const Discord = require('../');
const ytdl = require('ytdl-core'); const ytdl = require('ytdl-core');
const prism = require('prism-media');
const fs = require('fs');
const client = new Discord.Client({ fetchAllMembers: false, apiRequestMethod: 'sequential' }); const client = new Discord.Client({ fetchAllMembers: false, apiRequestMethod: 'sequential' });
@@ -27,7 +29,9 @@ client.on('message', m => {
conn.player.on('error', (...e) => console.log('player', ...e)); conn.player.on('error', (...e) => console.log('player', ...e));
if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] }); if (!connections.has(m.guild.id)) connections.set(m.guild.id, { conn, queue: [] });
m.reply('ok!'); m.reply('ok!');
conn.playStream(ytdl('https://www.youtube.com/watch?v=i3Jv9fNPjgk')); const d = conn.playOpusStream(
fs.createReadStream('C:/users/amish/downloads/s.ogg').pipe(new prism.OggOpusDemuxer())
);
}); });
} else { } else {
m.reply('Specify a voice channel!'); m.reply('Specify a voice channel!');
@@ -37,7 +41,7 @@ client.on('message', m => {
const url = m.content.split(' ').slice(1).join(' ') const url = m.content.split(' ').slice(1).join(' ')
.replace(/</g, '') .replace(/</g, '')
.replace(/>/g, ''); .replace(/>/g, '');
const stream = ytdl(item.url, { filter: 'audioonly' }, { passes: 3 }); const stream = ytdl(url, { filter: 'audioonly' }, { passes: 3 });
m.guild.voiceConnection.playStream(stream); m.guild.voiceConnection.playStream(stream);
} }
} else if (m.content.startsWith('/skip')) { } else if (m.content.startsWith('/skip')) {