mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
Fixed memory leaks
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
"use strict";
|
||||
/*
|
||||
Major credit to izy521 who is the creator of
|
||||
https://github.com/izy521/discord.io,
|
||||
|
||||
without his help voice chat in discord.js would not have
|
||||
been possible!
|
||||
*/
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
@@ -42,9 +49,17 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
this.playing = false;
|
||||
this.streamTime = 0;
|
||||
this.streamProc = null;
|
||||
this.KAI = null;
|
||||
this.init();
|
||||
}
|
||||
|
||||
VoiceConnection.prototype.destroy = function destroy() {
|
||||
this.stopPlaying();
|
||||
if (this.KAI) clearInterval(this.KAI);
|
||||
this.vWS.close();
|
||||
this.udp.close();
|
||||
};
|
||||
|
||||
VoiceConnection.prototype.stopPlaying = function stopPlaying() {
|
||||
this.playing = false;
|
||||
this.playingIntent = null;
|
||||
@@ -123,7 +138,7 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
|
||||
VoiceConnection.prototype.setSpeaking = function setSpeaking(value) {
|
||||
this.playing = value;
|
||||
this.vWS.send(JSON.stringify({
|
||||
if (this.vWS.readyState === WebSocket.OPEN) this.vWS.send(JSON.stringify({
|
||||
op: 5,
|
||||
d: {
|
||||
speaking: value,
|
||||
@@ -138,7 +153,7 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
var self = this;
|
||||
self.playing = true;
|
||||
try {
|
||||
self.udp.send(packet, 0, packet.length, self.vWSData.port, self.endpoint, callback);
|
||||
if (self.vWS.readyState === WebSocket.OPEN) self.udp.send(packet, 0, packet.length, self.vWSData.port, self.endpoint, callback);
|
||||
} catch (e) {
|
||||
self.playing = false;
|
||||
callback(e);
|
||||
@@ -252,11 +267,12 @@ var VoiceConnection = (function (_EventEmitter) {
|
||||
self.vWSData = data.d;
|
||||
|
||||
KAI = setInterval(function () {
|
||||
vWS.send(JSON.stringify({
|
||||
if (vWS.readyState === WebSocket.OPEN) vWS.send(JSON.stringify({
|
||||
op: 3,
|
||||
d: null
|
||||
}));
|
||||
}, data.d.heartbeat_interval);
|
||||
self.KAI = KAI;
|
||||
|
||||
var udpPacket = new Buffer(70);
|
||||
udpPacket.writeUIntBE(data.d.ssrc, 0, 4);
|
||||
|
||||
Reference in New Issue
Block a user