Set bitrate for voice channels support (#363)

* Set bitrate for voice channels

* Docs for bitrate settings and values
This commit is contained in:
Nicholas Tay
2016-05-23 10:53:52 +10:00
committed by abalabahaha
parent fe1d0bb595
commit bea1663052
8 changed files with 96 additions and 11 deletions

View File

@@ -989,6 +989,12 @@ export default class Client extends EventEmitter {
.then(dataCallback(callback), errorCallback(callback));
}
// def setChannelBitrate
setChannelBitrate(channel, kbitrate, callback = (/*err, {}*/) => { }) {
return this.internal.setChannelBitrate(channel, kbitrate)
.then(dataCallback(callback), errorCallback(callback));
}
// def updateChannel
updateChannel(channel, data, callback = (/*err, {}*/) => { }) {
return this.internal.updateChannel(channel, data)

View File

@@ -1374,6 +1374,27 @@ export default class InternalClient {
});
}
//def setChannelBitrate
setChannelBitrate(channel, kbitrate) {
kbitrate = kbitrate || 64; // default 64kbps
if (kbitrate < 8 || kbitrate > 96)
return Promise.reject(new Error("Bitrate must be between 8-96kbps"));
return this.resolver.resolveChannel(channel).then(channel => {
if (channel.type !== "voice")
return Promise.reject(new Error("Channel must be a voice channel"));
return this.apiRequest("patch", Endpoints.CHANNEL(channel.id), true, {
name: channel.name,
user_limit: channel.userLimit,
position: channel.position,
bitrate: kbitrate * 1000 // in bps
})
.then(() => channel.bitrate = kbitrate);
});
}
//def updateChannel
updateChannel(chann, data) {
return this.setChannelNameAndTopic(chann, data.name, data.topic);

View File

@@ -9,6 +9,8 @@ export default class VoiceChannel extends ServerChannel{
super(data, client, server);
this.members = data.members || new Cache();
this.userLimit = data.user_limit || 0;
this._bitrate = data.bitrate || 64000; // incase somebody wants to access the bps value???
this.bitrate = Math.round(this._bitrate / 1000); // store as kbps
}
join(callback = function () { }) {
@@ -18,4 +20,8 @@ export default class VoiceChannel extends ServerChannel{
setUserLimit() {
return this.client.setChannelUserLimit.apply(this.client, [this, arguments]);
}
setBitrate() {
return this.client.setChannelBitrate.apply(this.client, reg(this, arguments));
}
}