mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-23 03:50:09 +00:00
Compare commits
4 Commits
@discordjs
...
12.5.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8a7abc9f06 | ||
|
|
a6b922f8ae | ||
|
|
5328648f45 | ||
|
|
f8b0c01c26 |
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,4 +10,6 @@ class Silence extends Readable {
|
||||
}
|
||||
}
|
||||
|
||||
Silence.SILENCE_FRAME = SILENCE_FRAME;
|
||||
|
||||
module.exports = Silence;
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user