diff --git a/src/Client.js b/src/Client.js index 24a3def..42bc41f 100644 --- a/src/Client.js +++ b/src/Client.js @@ -160,6 +160,33 @@ class Client extends EventEmitter { } } + /** + * Set up a voiceTarget to be optionally used when sending voice data + * @param {Number} targetId The id for this voiceTarget. Must be between 4 and 30 + * @param {Array.} userIds Array of user sessions to send to. Can be empty. + * @param {Number} channelId ChannelId to send to. Ignored when userIds is not empty. + * @return {Promise} + */ + setupVoiceTarget(targetId, userIds, channelId) { + if (targetId < 4 || targetId > 30) { + return Promise.reject('targetId must be between 3 and 30') + } + + if (userIds.length) { + for (var idx in userIds) { + if (!this.users.has(userIds[idx])) { + return Promise.reject('userId ' + userIds[idx] + ' unknown') + } + } + return this.connection.writeProto('VoiceTarget', {id: targetId, targets: [{session: userIds}]}) + } else { + if (!this.channels.has(channelId)) { + return Promise.reject('ChannelId unknown') + } + return this.connection.writeProto('VoiceTarget', {id: targetId, targets: [{channelId: channelId}]}) + } + } + mute() { this.connection.writeProto('UserState', {session: this.user.session, actor: this.user.session , selfMute: true}) } diff --git a/src/voice/DispatchStream.js b/src/voice/DispatchStream.js index 49da300..1d16a22 100644 --- a/src/voice/DispatchStream.js +++ b/src/voice/DispatchStream.js @@ -3,7 +3,7 @@ const EventEmitter = require('events').EventEmitter const Constants = require('../Constants') class DispatchStream extends WritableStream { - constructor(connection) { + constructor(connection, voiceTarget) { super() this.connection = connection this.processObserver = new EventEmitter() @@ -13,6 +13,8 @@ class DispatchStream extends WritableStream { this.frameQueue = [] this.lastFrame = this._createFrameBuffer() + this.whisperId = voiceTarget + this._volume = 1 this.lastFrameWritten = 0 this.lastWrite = null diff --git a/src/voice/Dispatcher.js b/src/voice/Dispatcher.js index 3ee21a1..7ac66cc 100644 --- a/src/voice/Dispatcher.js +++ b/src/voice/Dispatcher.js @@ -9,16 +9,16 @@ class Dispatcher extends EventEmitter { this.connection = this.client.connection } - playFile(filename) { - this.play(filename) + playFile(filename, voiceTarget) { + this.play(filename, voiceTarget) } - playStream(stream) { - this.play(stream) + playStream(stream, voiceTarget) { + this.play(stream, voiceTarget) } - play(unknown) { - this.dispatchStream = new DispatchStream(this.connection) + play(unknown, voiceTarget) { + this.dispatchStream = new DispatchStream(this.connection, voiceTarget) this.dispatchStream.once('finish', () => { this.emit('end') })