refactor(BitField): base class for Permissions, ActivityFlags, Speaking (#2765)

* abstract BitField from Permissions

* reduce useless code, improve docs

* add a ReadOnly identifier to the return type of Bitfield#freeze()

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-1.html#partial-readonly-record-and-pick

* fix the RangeError

* update docs, convert Speaking and ActivityFlags to bitfields

* fix some docs

* Fix Speaking BitField oops

* docs for oops

* more incorrect docs

* Fix incorrectly named property

* add new classes to index

* fix missing @extends docs

* default bitfield resolve to 0, and cleanup defaulting everywhere

Also removes GuildMember#missiongPermissions() alias that had incorrect behavior

* Breaking: Rename Overwrite allowed and denied to allow and deny

To be consistent with the api's naming

* fix setSpeaking usage to bitfields instead of booleans

* fix speaking bug in playChunk

* docs: Updated typings

* fix: BitFieldResolvable should use RecursiveArray

* bugfix/requested change

* typings: Cleanup (#2)

* typings: Fix BitField#{toArray,@@iterator} output type

* typings: correct PermissionOverwrites property names and nitpicks
This commit is contained in:
bdistin
2018-08-21 04:56:41 -05:00
committed by SpaceEEC
parent 6be8172539
commit c62f01f0e4
18 changed files with 339 additions and 242 deletions

View File

@@ -67,7 +67,7 @@ class StreamDispatcher extends Writable {
this.on('finish', () => {
// Still emitting end for backwards compatibility, probably remove it in the future!
this.emit('end');
this._setSpeaking(false);
this._setSpeaking(0);
});
if (typeof volume !== 'undefined') this.setVolume(volume);
@@ -131,7 +131,7 @@ class StreamDispatcher extends Writable {
this.streams.silence.pipe(this);
this._silence = true;
} else {
this._setSpeaking(false);
this._setSpeaking(0);
}
this.pausedSince = Date.now();
}
@@ -243,7 +243,6 @@ class StreamDispatcher extends Writable {
_playChunk(chunk) {
if (this.player.dispatcher !== this || !this.player.voiceConnection.authentication.secret_key) return;
this._setSpeaking(true);
this._sendPacket(this._createPacket(this._sdata.sequence, this._sdata.timestamp, chunk));
}
@@ -285,7 +284,7 @@ class StreamDispatcher extends Writable {
* @event StreamDispatcher#debug
* @param {string} info The debug info
*/
this._setSpeaking(true);
this._setSpeaking(1);
while (repeats--) {
if (!this.player.voiceConnection.sockets.udp) {
this.emit('debug', 'Failed to send a packet - no UDP socket');
@@ -293,7 +292,7 @@ class StreamDispatcher extends Writable {
}
this.player.voiceConnection.sockets.udp.send(packet)
.catch(e => {
this._setSpeaking(false);
this._setSpeaking(0);
this.emit('debug', `Failed to send a packet - ${e}`);
});
}