Skip to content

Commit

Permalink
fix: event name incompabilities
Browse files Browse the repository at this point in the history
This commit fixes incompabilities due to internal Node.js behaviors while emitting an event called "end".
  • Loading branch information
ThePedroo committed Apr 9, 2024
1 parent ed60efb commit 73b6587
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ client.ws.on('VOICE_SERVER_UPDATE', (data) => {
endpoint: buffer.endpoint
})

stream.on('end', () => stream.emit('finishBuffering')) /* Allow it to end once it finds null */
connection.connect(() => connection.play(stream))
}
})
Expand Down
4 changes: 4 additions & 0 deletions docs/Connection/play.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ Nothing.

- Instead of requiring the stream to end with 0, it now requires the stream to emit the `end` event when it finished buffering.

### 2.0.2

- Due to incompabilities with Node.js with `end` event, now it was renamed to `finishBuffering`.

</details>
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Connection extends EventEmitter {

this.ws = new WebSocket(`wss://${this.voiceServer.endpoint}/?v=4`, {
headers: {
'User-Agent': 'DiscordBot (https://github.com/PerformanC/voice, 2.0.1)'
'User-Agent': 'DiscordBot (https://github.com/PerformanC/voice, 2.0.2)'
}
})

Expand Down Expand Up @@ -417,7 +417,7 @@ class Connection extends EventEmitter {
if (chunk) this.sendAudioChunk(packetBuffer, chunk)
}, OPUS_FRAME_DURATION)

this.audioStream.once('end', () => shouldStop = true)
this.audioStream.once('finishBuffering', () => shouldStop = true)
}

_destroyConnection(code, reason) {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performanc/voice",
"version": "2.0.1",
"version": "2.0.2",
"description": "Performant Discord voice API client for ES6 Node.js",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit 73b6587

Please sign in to comment.