Skip to content

Commit

Permalink
Merge pull request #24 from kripton/ChannelSwitch
Browse files Browse the repository at this point in the history
Channel switch
  • Loading branch information
Gielert authored Oct 23, 2020
2 parents d67ceec + fa61b9b commit 2f71188
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
"author": "Michiel",
"license": "MIT",
"dependencies": {
"bluebird": "^3.5.1",
"@discordjs/opus": "^0.3.2",
"bluebird": "^3.7.2",
"fluent-ffmpeg": "^2.1.2",
"node-opus": "^0.3.0",
"protobufjs": "^6.8.6"
"protobufjs": "^6.9.0"
},
"devDependencies": {
"chai": "^4.1.2",
"gulp": "^3.9.1",
"istanbul": "^0.4.5",
"jsdoc-to-markdown": "^4.0.1",
"mocha": "^5.1.1"
"chai": "^4.2.0",
"gulp": "^4.0.2",
"nyc": "^15.1.0",
"jsdoc-to-markdown": "^6.0.1",
"mocha": "^8.0.1"
}
}
13 changes: 13 additions & 0 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ class Client extends EventEmitter {
return this.user.channel.sendMessage(message, recursive)
}

/**
* Switches to another channel
* @param {Number} id The id of the channel to switch to
* @return {Promise<>}
*/
switchChannel(id) {
if (this.channels.has(id)) {
return this.connection.writeProto('UserState', {session: this.user.session, actor: this.user.session , channelId: id})
} else {
return Promise.reject('ChannelId unknown')
}
}

mute() {
this.connection.writeProto('UserState', {session: this.user.session, actor: this.user.session , selfMute: true})
}
Expand Down
10 changes: 5 additions & 5 deletions src/Connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const tls = require('tls');
const Protobuf = require('./Protobuf')
const Promise = require('bluebird')
const EventEmitter = require('events').EventEmitter
const OpusEncoder = require('node-opus').OpusEncoder
const OpusEncoder = require('@discordjs/opus').OpusEncoder
const Constants = require('./Constants')
const Util = require('./Util')

Expand All @@ -11,7 +11,7 @@ class Connection extends EventEmitter {
super()

this.options = options;
this.opusEncoder = new OpusEncoder(Constants.sampleRate)
this.opusEncoder = new OpusEncoder(Constants.Audio.sampleRate, 1)
this.currentEncoder = this.opusEncoder
this.codec = Connection.codec().Opus
this.voiceSequence = 0
Expand Down Expand Up @@ -72,7 +72,7 @@ class Connection extends EventEmitter {
}

_writeHeader(type, data) {
const header = new Buffer(6)
const header = Buffer.alloc(6)
header.writeUInt16BE(type, 0)
header.writeUInt32BE(data, 2)
this._writePacket(header)
Expand Down Expand Up @@ -102,7 +102,7 @@ class Connection extends EventEmitter {

const sequenceVarint = Util.toVarint(voiceSequence)

const voiceHeader = new Buffer(1 + sequenceVarint.length)
const voiceHeader = Buffer.alloc(1 + sequenceVarint.length)
voiceHeader[0] = typeTarget
sequenceVarint.value.copy(voiceHeader, 1, 0)
let header
Expand All @@ -122,7 +122,7 @@ class Connection extends EventEmitter {
throw new TypeError('Celt is not supported')
}

const frame = new Buffer(header.length + packet.length)
const frame = Buffer.alloc(header.length + packet.length)
header.copy(frame, 0)

packet.copy(frame, header.length)
Expand Down
4 changes: 2 additions & 2 deletions src/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Util {
var arr = [];
if( i < 0 ) {
i = ~i;
if( i <= 0x3 ) { return new Buffer([ 0xFC | i ]); }
if( i <= 0x3 ) { return Buffer.from([ 0xFC | i ]); }

arr.push( 0xF8 );
}
Expand Down Expand Up @@ -37,7 +37,7 @@ class Util {
}

return {
value: new Buffer( arr ),
value: Buffer.from( arr ),
length: arr.length
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/voice/DispatchStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DispatchStream extends WritableStream {
}

_createFrameBuffer() {
return new Buffer(Constants.Audio.frameSize * 2)
return Buffer.alloc(Constants.Audio.frameSize * 2)
}

_processAudioBuffer() {
Expand Down

0 comments on commit 2f71188

Please sign in to comment.