mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
tinify webpacks (#1975)
* tinify webpack * meme * fix long version * more changes * even smoler * fix up logic * fix build * undo changes to user agent manager because its not webpack'd anymore * the heck * fix stupid * clean up browser rules * typo
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const browser = typeof window !== 'undefined';
|
||||
const { browser } = require('./util/Constants');
|
||||
const zlib = require('zlib');
|
||||
const querystring = require('querystring');
|
||||
|
||||
@@ -23,16 +23,21 @@ exports.pack = erlpack ? erlpack.pack : JSON.stringify;
|
||||
|
||||
exports.unpack = data => {
|
||||
if (Array.isArray(data)) data = Buffer.concat(data);
|
||||
if (data instanceof ArrayBuffer) data = Buffer.from(new Uint8Array(data));
|
||||
if (!browser && data instanceof ArrayBuffer) data = Buffer.from(new Uint8Array(data));
|
||||
|
||||
if (erlpack && typeof data !== 'string') return erlpack.unpack(data);
|
||||
else if (data instanceof Buffer) data = zlib.inflateSync(data).toString();
|
||||
if (erlpack && typeof data !== 'string') {
|
||||
return erlpack.unpack(data);
|
||||
} else if (data instanceof ArrayBuffer || (!browser && data instanceof Buffer)) {
|
||||
data = zlib.inflateSync(data).toString();
|
||||
}
|
||||
return JSON.parse(data);
|
||||
};
|
||||
|
||||
exports.create = (gateway, query = {}, ...args) => {
|
||||
const [g, q] = gateway.split('?');
|
||||
query.encoding = exports.encoding;
|
||||
const ws = new exports.WebSocket(`${gateway}?${querystring.stringify(query)}`, ...args);
|
||||
if (q) query = Object.assign(querystring.parse(q), query);
|
||||
const ws = new exports.WebSocket(`${g}?${querystring.stringify(query)}`, ...args);
|
||||
if (browser) ws.binaryType = 'arraybuffer';
|
||||
return ws;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user