Added optional compression

This commit is contained in:
hydrabolt
2015-10-26 20:18:09 +00:00
parent c89633b72f
commit 5bb0ce141f
3 changed files with 39 additions and 8 deletions

View File

@@ -14,6 +14,7 @@ var Invite = require("./invite.js");
var PMChannel = require("./PMChannel.js");
var ServerPermissions = require("./ServerPermissions.js");
var gameMap = require("../ref/gameMap.json");
var zlib;
//node modules
var request = require("superagent");
@@ -37,7 +38,13 @@ var Client = (function () {
further efforts will be made to connect.
*/
this.options = options;
this.options.queue = this.options.queue;
this.options.compress = options.compress;
if (this.options.compress) {
// only require zlib if necessary
zlib = require("zlib");
}
this.token = token;
this.state = 0;
this.websocket = null;
@@ -1024,6 +1031,12 @@ var Client = (function () {
//message
this.websocket.onmessage = function (e) {
if (e.type === "Binary") {
if (!zlib) zlib = require("zlib");
e.data = zlib.inflateSync(e.data).toString();
}
var dat = false,
data = {};
@@ -1661,7 +1674,7 @@ var Client = (function () {
//def trySendConnData
Client.prototype.trySendConnData = function trySendConnData() {
var self = this;
if (this.token && !this.alreadySentData) {
this.alreadySentData = true;
@@ -1677,7 +1690,8 @@ var Client = (function () {
"$device": "discord.js",
"$referrer": "",
"$referring_domain": ""
}
},
compress: self.options.compress
}
};
this.websocket.send(JSON.stringify(data));