mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Reimplement broadcast (un)subscribe events
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const EventEmitter = require('events');
|
||||
const BroadcastAudioPlayer = require('./player/BroadcastAudioPlayer');
|
||||
const DispatcherSet = require('./util/DispatcherSet');
|
||||
|
||||
/**
|
||||
* A voice broadcast can be played across multiple voice connections for improved shared-stream efficiency.
|
||||
@@ -23,7 +24,7 @@ class VoiceBroadcast extends EventEmitter {
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = client;
|
||||
this.dispatchers = new Set();
|
||||
this.dispatchers = new DispatcherSet(this);
|
||||
this.player = new BroadcastAudioPlayer(this);
|
||||
}
|
||||
|
||||
|
||||
40
src/client/voice/util/DispatcherSet.js
Normal file
40
src/client/voice/util/DispatcherSet.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { Events } = require('../../../util/Constants');
|
||||
|
||||
/**
|
||||
* A "store" for handling broadcast dispatcher (un)subscription
|
||||
* @private
|
||||
*/
|
||||
class DispatcherSet extends Set {
|
||||
constructor(broadcast) {
|
||||
super();
|
||||
/**
|
||||
* The broadcast that this set belongs to
|
||||
* @type {VoiceBroadcast}
|
||||
*/
|
||||
this.broadcast = broadcast;
|
||||
}
|
||||
|
||||
add(dispatcher) {
|
||||
super.add(dispatcher);
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher subscribes to the broadcast.
|
||||
* @event VoiceBroadcast#subscribe
|
||||
* @param {StreamDispatcher} dispatcher The subscribed dispatcher
|
||||
*/
|
||||
this.broadcast.emit(Events.VOICE_BROADCAST_SUBSCRIBE, dispatcher);
|
||||
return this;
|
||||
}
|
||||
|
||||
delete(dispatcher) {
|
||||
const ret = super.delete(dispatcher);
|
||||
/**
|
||||
* Emitted whenever a stream dispatcher unsubscribes to the broadcast.
|
||||
* @event VoiceBroadcast#unsubscribe
|
||||
* @param {StreamDispatcher} dispatcher The unsubscribed dispatcher
|
||||
*/
|
||||
if (ret) this.broadcast.emit(Events.VOICE_BROADCAST_UNSUBSCRIBE, dispatcher);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DispatcherSet;
|
||||
@@ -234,6 +234,8 @@ exports.Events = {
|
||||
USER_GUILD_SETTINGS_UPDATE: 'clientUserGuildSettingsUpdate',
|
||||
PRESENCE_UPDATE: 'presenceUpdate',
|
||||
VOICE_STATE_UPDATE: 'voiceStateUpdate',
|
||||
VOICE_BROADCAST_SUBSCRIBE: 'subscribe',
|
||||
VOICE_BROADCAST_UNSUBSCRIBE: 'unsubscribe',
|
||||
TYPING_START: 'typingStart',
|
||||
TYPING_STOP: 'typingStop',
|
||||
DISCONNECT: 'disconnect',
|
||||
|
||||
Reference in New Issue
Block a user