mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Set bitrate for voice channels support (#363)
* Set bitrate for voice channels * Docs for bitrate settings and values
This commit is contained in:
committed by
abalabahaha
parent
fe1d0bb595
commit
bea1663052
@@ -543,6 +543,16 @@ Sets the user limit of a voice channel
|
||||
- **callback** - `function` taking the following:
|
||||
- **error** - error if any occurred
|
||||
|
||||
setChannelBitrate(channel, bitrate, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Sets the bitrate of a voice channel
|
||||
|
||||
- **channel** - A `Channel Resolvable`_
|
||||
- **bitrate** - A `Number`, bitrate (in kb/s) (8 - 96)
|
||||
- **callback** - `function` taking the following:
|
||||
- **error** - error if any occurred
|
||||
|
||||
startTyping(channel, `callback`)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -23,6 +23,11 @@ userLimit
|
||||
|
||||
The maximum amount of users that can connect to the voice channel. If it's 0, there is no limit
|
||||
|
||||
bitrate
|
||||
~~~~~~~~
|
||||
|
||||
The bitrate of the voice channel (in kb/s).
|
||||
|
||||
Functions
|
||||
---------
|
||||
|
||||
|
||||
@@ -977,6 +977,14 @@ var Client = (function (_EventEmitter) {
|
||||
return this.internal.setChannelUserLimit(channel, limit).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
// def setChannelBitrate
|
||||
|
||||
Client.prototype.setChannelBitrate = function setChannelBitrate(channel, kbitrate) {
|
||||
var callback = arguments.length <= 2 || arguments[2] === undefined ? function () /*err, {}*/{} : arguments[2];
|
||||
|
||||
return this.internal.setChannelBitrate(channel, kbitrate).then(dataCallback(callback), errorCallback(callback));
|
||||
};
|
||||
|
||||
// def updateChannel
|
||||
|
||||
Client.prototype.updateChannel = function updateChannel(channel, data) {
|
||||
|
||||
@@ -1638,6 +1638,29 @@ var InternalClient = (function () {
|
||||
});
|
||||
};
|
||||
|
||||
//def setChannelBitrate
|
||||
|
||||
InternalClient.prototype.setChannelBitrate = function setChannelBitrate(channel, kbitrate) {
|
||||
var _this42 = this;
|
||||
|
||||
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(function (channel) {
|
||||
if (channel.type !== "voice") return Promise.reject(new Error("Channel must be a voice channel"));
|
||||
|
||||
return _this42.apiRequest("patch", _Constants.Endpoints.CHANNEL(channel.id), true, {
|
||||
name: channel.name,
|
||||
user_limit: channel.userLimit,
|
||||
position: channel.position,
|
||||
bitrate: kbitrate * 1000 // in bps
|
||||
}).then(function () {
|
||||
return channel.bitrate = kbitrate;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
//def updateChannel
|
||||
|
||||
InternalClient.prototype.updateChannel = function updateChannel(chann, data) {
|
||||
@@ -1690,7 +1713,7 @@ var InternalClient = (function () {
|
||||
};
|
||||
|
||||
InternalClient.prototype.createWS = function createWS(url) {
|
||||
var _this42 = this;
|
||||
var _this43 = this;
|
||||
|
||||
var self = this;
|
||||
var client = self.client;
|
||||
@@ -1724,14 +1747,14 @@ var InternalClient = (function () {
|
||||
this.websocket.onclose = function (code) {
|
||||
self.websocket = null;
|
||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
self.disconnected(_this42.client.options.autoReconnect);
|
||||
self.disconnected(_this43.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onerror = function (e) {
|
||||
client.emit("error", e);
|
||||
self.websocket = null;
|
||||
self.state = _ConnectionState2["default"].DISCONNECTED;
|
||||
self.disconnected(_this42.client.options.autoReconnect);
|
||||
self.disconnected(_this43.client.options.autoReconnect);
|
||||
};
|
||||
|
||||
this.websocket.onmessage = function (e) {
|
||||
@@ -1760,11 +1783,11 @@ var InternalClient = (function () {
|
||||
|
||||
self.user = self.users.add(new _StructuresUser2["default"](data.user, client));
|
||||
|
||||
_this42.forceFetchCount = {};
|
||||
_this42.forceFetchQueue = [];
|
||||
_this42.forceFetchLength = 1;
|
||||
_this42.autoReconnectInterval = 1000;
|
||||
_this42.sessionID = data.session_id;
|
||||
_this43.forceFetchCount = {};
|
||||
_this43.forceFetchQueue = [];
|
||||
_this43.forceFetchLength = 1;
|
||||
_this43.autoReconnectInterval = 1000;
|
||||
_this43.sessionID = data.session_id;
|
||||
|
||||
data.guilds.forEach(function (server) {
|
||||
if (!server.unavailable) {
|
||||
@@ -2207,7 +2230,7 @@ var InternalClient = (function () {
|
||||
data.id = data.id || user.id;
|
||||
data.avatar = data.avatar || user.avatar;
|
||||
data.discriminator = data.discriminator || user.discriminator;
|
||||
_this42.email = data.email || _this42.email;
|
||||
_this43.email = data.email || _this43.email;
|
||||
|
||||
var presenceUser = new _StructuresUser2["default"](data, client);
|
||||
|
||||
@@ -2349,7 +2372,7 @@ var InternalClient = (function () {
|
||||
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_ADD:
|
||||
if (_this42.user.bot) {
|
||||
if (_this43.user.bot) {
|
||||
return;
|
||||
}
|
||||
if (data.type === 1) {
|
||||
@@ -2380,7 +2403,7 @@ var InternalClient = (function () {
|
||||
}
|
||||
break;
|
||||
case _Constants.PacketType.FRIEND_REMOVE:
|
||||
if (_this42.user.bot) {
|
||||
if (_this43.user.bot) {
|
||||
return;
|
||||
}
|
||||
var user = self.friends.get("id", data.id);
|
||||
|
||||
@@ -27,6 +27,8 @@ var VoiceChannel = (function (_ServerChannel) {
|
||||
_ServerChannel.call(this, data, client, server);
|
||||
this.members = data.members || new _UtilCache2["default"]();
|
||||
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
|
||||
}
|
||||
|
||||
VoiceChannel.prototype.join = function join() {
|
||||
@@ -39,6 +41,10 @@ var VoiceChannel = (function (_ServerChannel) {
|
||||
return this.client.setChannelUserLimit.apply(this.client, [this, arguments]);
|
||||
};
|
||||
|
||||
VoiceChannel.prototype.setBitrate = function setBitrate() {
|
||||
return this.client.setChannelBitrate.apply(this.client, _UtilArgumentRegulariser.reg(this, arguments));
|
||||
};
|
||||
|
||||
return VoiceChannel;
|
||||
})(_ServerChannel3["default"]);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user