This commit is contained in:
Travis CI 2016-12-30 18:23:30 +00:00
parent c1b9c61081
commit fa473f5655
2 changed files with 53 additions and 17 deletions

View file

@ -11397,6 +11397,10 @@ class Client extends EventEmitter {
return typeof window !== 'undefined';
}
/**
* Creates a new voice broadcast
* @returns {VoiceBroadcast} the created broadcast
*/
createVoiceBroadcast() {
const broadcast = new VoiceBroadcast(this);
this.broadcasts.push(broadcast);
@ -23006,7 +23010,7 @@ const ffmpegArguments = [
];
/**
* A voice broadcast that can be played across multiple voice connections
* A voice broadcast can be played across multiple voice connections for improved shared-stream efficiency.
* @extends {EventEmitter}
*/
class VoiceBroadcast extends EventEmitter {
@ -23017,7 +23021,7 @@ class VoiceBroadcast extends EventEmitter {
* @type {Client}
*/
this.client = client;
this.dispatchers = new Collection();
this._dispatchers = new Collection();
/**
* The audio transcoder that this broadcast uses
* @type {Prism}
@ -23037,6 +23041,18 @@ class VoiceBroadcast extends EventEmitter {
this._volume = 1;
}
/**
* An array of subscribed dispatchers
* @type {StreamDispatcher[]}
*/
get dispatchers() {
let d = [];
for (const container of this._dispatchers.values()) {
d = d.concat(Array.from(container.values()));
}
return d;
}
applyVolume(buffer, volume) {
volume = volume || this._volume;
if (volume === 1) return buffer;
@ -23090,30 +23106,42 @@ class VoiceBroadcast extends EventEmitter {
}
unregisterDispatcher(dispatcher, old) {
let container = this.dispatchers.get(old || dispatcher.volume);
/**
* Emitted whenever a Stream Dispatcher unsubscribes from the broadcast
* @event VoiceBroadcast#unsubscribe
* @param {dispatcher} the dispatcher that unsubscribed
*/
this.emit('unsubscribe', dispatcher);
let container = this._dispatchers.get(old || dispatcher.volume);
if (container) {
if (container.delete(dispatcher)) return;
}
for (container of this.dispatchers.values()) {
for (container of this._dispatchers.values()) {
container.delete(dispatcher);
}
}
registerDispatcher(dispatcher) {
if (!this.dispatchers.has(dispatcher.volume)) {
this.dispatchers.set(dispatcher.volume, new Set());
if (!this._dispatchers.has(dispatcher.volume)) {
this._dispatchers.set(dispatcher.volume, new Set());
}
const container = this.dispatchers.get(dispatcher.volume);
const container = this._dispatchers.get(dispatcher.volume);
if (!container.has(dispatcher)) {
container.add(dispatcher);
dispatcher.once('end', () => this.unregisterDispatcher(dispatcher));
dispatcher.on('volumeChange', (o, n) => {
this.unregisterDispatcher(dispatcher, o);
if (!this.dispatchers.has(n)) {
this.dispatchers.set(n, new Set());
if (!this._dispatchers.has(n)) {
this._dispatchers.set(n, new Set());
}
this.dispatchers.get(n).add(dispatcher);
this._dispatchers.get(n).add(dispatcher);
});
/**
* Emitted whenever a stream dispatcher subscribes to the broadcast
* @event VoiceBroadcast#subscribe
* @param {StreamDispatcher} dispatcher the subscribed dispatcher
*/
this.emit('subscribe', dispatcher);
}
}
@ -23191,7 +23219,14 @@ class VoiceBroadcast extends EventEmitter {
*/
else this.emit('warn', e);
});
transcoder.once('end', () => this.killCurrentTranscoder());
/**
* Emitted once the broadcast (the audio stream) ends
* @event VoiceBroadcast#end
*/
transcoder.once('end', () => {
this.emit('end');
this.killCurrentTranscoder();
});
this.currentTranscoder = {
transcoder,
options,
@ -23208,6 +23243,7 @@ class VoiceBroadcast extends EventEmitter {
*/
playConvertedStream(stream, { seek = 0, volume = 1, passes = 1 } = {}) {
this.killCurrentTranscoder();
stream.once('end', () => this.emit('end'));
const options = { seek, volume, passes, stream };
this.currentTranscoder = { options };
stream.once('readable', () => this._startPlaying());
@ -23218,7 +23254,7 @@ class VoiceBroadcast extends EventEmitter {
* Pauses the entire broadcast - all dispatchers also pause
*/
pause() {
for (const container of this.dispatchers.values()) {
for (const container of this._dispatchers.values()) {
for (const dispatcher of container.values()) {
dispatcher.pause();
}
@ -23230,7 +23266,7 @@ class VoiceBroadcast extends EventEmitter {
* Resumes the entire broadcast - all dispatchers also resume
*/
resume() {
for (const container of this.dispatchers.values()) {
for (const container of this._dispatchers.values()) {
for (const dispatcher of container.values()) {
dispatcher.resume();
}
@ -23259,7 +23295,7 @@ class VoiceBroadcast extends EventEmitter {
buffer = this.applyVolume(buffer);
for (const x of this.dispatchers.entries()) {
for (const x of this._dispatchers.entries()) {
setImmediate(() => {
const [volume, container] = x;
const opusPacket = this.opusEncoder.encode(this.applyVolume(buffer, volume));
@ -23275,7 +23311,7 @@ class VoiceBroadcast extends EventEmitter {
*/
end() {
this.killCurrentTranscoder();
for (const container of this.dispatchers.values()) {
for (const container of this._dispatchers.values()) {
for (const dispatcher of container.values()) {
dispatcher.destroy('end', 'broadcast ended');
}

File diff suppressed because one or more lines are too long