Compare commits

...

4 Commits

Author SHA1 Message Date
iCrawl
8a7abc9f06 chore(Release): version upgrade 2020-11-26 00:03:06 +01:00
monbrey
a6b922f8ae fix(MessageReaction): set MessageReaction#me in patch method (#5047) 2020-11-25 23:57:03 +01:00
Amish Shah
5328648f45 fix(Voice*): filter out silent audio from video users (#5035) 2020-11-25 23:56:55 +01:00
izexi
f8b0c01c26 fix(GuildTemplate): 'guild' getter (#5040) 2020-11-25 23:56:41 +01:00
7 changed files with 52 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "discord.js",
"version": "12.5.0",
"version": "12.5.1",
"description": "A powerful library for interacting with the Discord API",
"main": "./src/index",
"types": "./typings/index.d.ts",

View File

@@ -473,7 +473,11 @@ class VoiceConnection extends EventEmitter {
}
onStartSpeaking({ user_id, ssrc, speaking }) {
this.ssrcMap.set(+ssrc, { userID: user_id, speaking: speaking });
this.ssrcMap.set(+ssrc, {
...(this.ssrcMap.get(+ssrc) || {}),
userID: user_id,
speaking: speaking,
});
}
/**

View File

@@ -189,7 +189,11 @@ class VoiceWebSocket extends EventEmitter {
this.emit('sessionDescription', packet.d);
break;
case VoiceOPCodes.CLIENT_CONNECT:
this.connection.ssrcMap.set(+packet.d.audio_ssrc, { userID: packet.d.user_id, speaking: 0 });
this.connection.ssrcMap.set(+packet.d.audio_ssrc, {
userID: packet.d.user_id,
speaking: 0,
hasVideo: Boolean(packet.d.video_ssrc),
});
break;
case VoiceOPCodes.CLIENT_DISCONNECT:
const streamInfo = this.connection.receiver && this.connection.receiver.packets.streams.get(packet.d.user_id);

View File

@@ -1,7 +1,9 @@
'use strict';
const EventEmitter = require('events');
const Speaking = require('../../../util/Speaking');
const secretbox = require('../util/Secretbox');
const { SILENCE_FRAME } = require('../util/Silence');
// The delay between packets when a user is considered to have stopped speaking
// https://github.com/discordjs/discord.js/issues/3524#issuecomment-540373200
@@ -84,12 +86,30 @@ class PacketHandler extends EventEmitter {
const userStat = this.connection.ssrcMap.get(ssrc);
if (!userStat) return;
let opusPacket;
const streamInfo = this.streams.get(userStat.userID);
// If the user is in video, we need to check if the packet is just silence
if (userStat.hasVideo) {
opusPacket = this.parseBuffer(buffer);
if (opusPacket instanceof Error) {
// Only emit an error if we were actively receiving packets from this user
if (streamInfo) {
this.emit('error', opusPacket);
return;
}
}
if (SILENCE_FRAME.equals(opusPacket)) {
// If this is a silence frame, pretend we never received it
return;
}
}
let speakingTimeout = this.speakingTimeouts.get(ssrc);
if (typeof speakingTimeout === 'undefined') {
// Ensure at least the speaking bit is set.
// As the object is by reference, it's only needed once per client re-connect.
if (userStat.speaking === 0) {
userStat.speaking = 1;
userStat.speaking = Speaking.FLAGS.SPEAKING;
}
this.connection.onSpeaking({ user_id: userStat.userID, ssrc: ssrc, speaking: userStat.speaking });
speakingTimeout = this.receiver.connection.client.setTimeout(() => {
@@ -106,15 +126,17 @@ class PacketHandler extends EventEmitter {
speakingTimeout.refresh();
}
let stream = this.streams.get(userStat.userID);
if (!stream) return;
stream = stream.stream;
const opusPacket = this.parseBuffer(buffer);
if (opusPacket instanceof Error) {
this.emit('error', opusPacket);
return;
if (streamInfo) {
const { stream } = streamInfo;
if (!opusPacket) {
opusPacket = this.parseBuffer(buffer);
if (opusPacket instanceof Error) {
this.emit('error', opusPacket);
return;
}
}
stream.push(opusPacket);
}
stream.push(opusPacket);
}
}

View File

@@ -10,4 +10,6 @@ class Silence extends Readable {
}
}
Silence.SILENCE_FRAME = SILENCE_FRAME;
module.exports = Silence;

View File

@@ -198,8 +198,9 @@ class GuildTemplate extends Base {
* @readonly
*/
get guild() {
return this.client.guilds.get(this.guildID) || null;
return this.client.guilds.cache.get(this.guildID) || null;
}
/**
* The URL of this template
* @type {string}

View File

@@ -28,12 +28,6 @@ class MessageReaction {
*/
this.message = message;
/**
* Whether the client has given this reaction
* @type {boolean}
*/
this.me = data.me;
/**
* A manager of the users that have given this reaction
* @type {ReactionUserManager}
@@ -54,6 +48,12 @@ class MessageReaction {
*/
this.count = data.count;
}
/**
* Whether the client has given this reaction
* @type {boolean}
*/
this.me = data.me;
}
/**