Skip to content

Commit

Permalink
Merge pull request #31 from kripton/voiceTargets
Browse files Browse the repository at this point in the history
Voice targets
  • Loading branch information
Gielert authored Oct 26, 2020
2 parents 58cf5bb + 25a0ec3 commit 2a911a1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
27 changes: 27 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<Number>} 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<any>}
*/
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})
}
Expand Down
4 changes: 3 additions & 1 deletion src/voice/DispatchStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions src/voice/Dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down

0 comments on commit 2a911a1

Please sign in to comment.