discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
328 stars 112 forks source link

feat(VoiceReceive)!: improve usability #136

Closed amishshah closed 2 years ago

amishshah commented 3 years ago

Please describe the changes this PR makes and why it should be merged:

Resolves #92, #95, #96

This PR makes voice receive actually usable!


Example usage:

const voiceConnection = joinChannel({ ...options, selfDeaf: false });

voiceConnection.receiver.speaking.on('start', userId => console.log(`User ${userId} started speaking`));
voiceConnection.receiver.speaking.on('stop', userId => console.log(`User ${userId} stopped speaking`));

// A Readable object mode stream of Opus packets
// Will only end when the voice connection is destroyed
voiceConnection.receiver.subscribe(userId);

// A Readable object mode stream of Opus packets
// Will end when the voice connection is destroyed, or the user has not said anything for 100ms
voiceConnection.receiver.subscribe(userId, {
  end: {
    behavior: EndBehaviorType.AfterSilence,
    duration: 100,
  },
});

Status and versioning classification:

codecov[bot] commented 2 years ago

Codecov Report

Merging #136 (31b09d9) into main (636f54f) will increase coverage by 1.08%. The diff coverage is 98.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #136      +/-   ##
==========================================
+ Coverage   72.75%   73.84%   +1.08%     
==========================================
  Files          20       21       +1     
  Lines         903      906       +3     
  Branches      216      221       +5     
==========================================
+ Hits          657      669      +12     
+ Misses        244      235       -9     
  Partials        2        2              
Impacted Files Coverage Δ
src/VoiceConnection.ts 86.84% <96.00%> (+1.02%) :arrow_up:
src/receive/AudioReceiveStream.ts 100.00% <100.00%> (ø)
src/receive/SSRCMap.ts 100.00% <100.00%> (ø)
src/receive/SpeakingMap.ts 100.00% <100.00%> (ø)
src/receive/VoiceReceiver.ts 100.00% <100.00%> (+10.20%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 636f54f...31b09d9. Read the comment docs.