Skip to content

Commit

Permalink
fix(voice): avoid bitwise overflow error (#1323)
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 authored Mar 27, 2022
1 parent 072db2e commit 52db153
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/voice/SharedStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class SharedStream extends EventEmitter {

_incrementTimestamps(val) {
for(const vc of this.voiceConnections.values()) {
vc.timestamp = (vc.timestamp + val) & 0xFFFFFFFF;
vc.timestamp = (vc.timestamp + val) >>> 0;
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/voice/VoiceConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ class VoiceConnection extends EventEmitter {
* @arg {Number} [frameSize] The size (in samples) of the Opus audio frame
*/
sendAudioFrame(frame, frameSize = this.frameSize) {
this.timestamp = (this.timestamp + frameSize) & 0xFFFFFFFF;
this.timestamp = (this.timestamp + frameSize) >>> 0;
this.sequence = (this.sequence + 1) & 0xFFFF;

return this._sendAudioFrame(frame);
Expand Down Expand Up @@ -790,7 +790,7 @@ class VoiceConnection extends EventEmitter {
this.setSpeaking(0);
}
this.current.pausedTime += 4 * this.current.options.frameDuration;
this.timestamp = (this.timestamp + 3 * this.current.options.frameSize) & 0xFFFFFFFF;
this.timestamp = (this.timestamp + 3 * this.current.options.frameSize) >>> 0;
this.current.timeout = setTimeout(this._send, 4 * this.current.options.frameDuration);
return;
} else {
Expand Down

0 comments on commit 52db153

Please sign in to comment.