mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
Fix the webdists, this fixes #170.
Particular problems and how they were resolved:
- The `fs-extra` module, used exclusively by TokenCacher, didn't have a browser version. I rewrote TokenCacher to not use fs-extra (see fdd4cfc7cc)
- TokenCacher wouldn't work in the browser anyway due to lack of a file system. I made a shim (`Util/TokenCacher-shim.js`) that implements all TokenCacher functionality as null implementations, this causes `login` to always make a request.
- Compressed packets couldn't be parsed because neither node's Buffers nor zlib were working correctly. Initially I tried to make a browser-only parser class that parses compressed `Blob` packets, but this didn't work out, so I just disabled compression by default.
This commit is contained in:
@@ -57,7 +57,7 @@ var Client = (function (_EventEmitter) {
|
||||
|
||||
_EventEmitter.call(this);
|
||||
this.options = options || {};
|
||||
this.options.compress = options.compress || true;
|
||||
this.options.compress = options.compress || !process.browser;
|
||||
this.options.revive = options.revive || false;
|
||||
this.options.rate_limit_as_error = options.rate_limit_as_error || false;
|
||||
this.internal = new _InternalClient2["default"](this);
|
||||
|
||||
29
lib/Util/TokenCacher-shim.js
Normal file
29
lib/Util/TokenCacher-shim.js
Normal file
@@ -0,0 +1,29 @@
|
||||
// Shim for the token cacher in the browser.
|
||||
"use strict";
|
||||
|
||||
exports.__esModule = true;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var TokenCacher = (function () {
|
||||
function TokenCacher() {
|
||||
_classCallCheck(this, TokenCacher);
|
||||
}
|
||||
|
||||
TokenCacher.prototype.setToken = function setToken() {};
|
||||
|
||||
TokenCacher.prototype.save = function save() {};
|
||||
|
||||
TokenCacher.prototype.getToken = function getToken() {
|
||||
return null;
|
||||
};
|
||||
|
||||
TokenCacher.prototype.init = function init(ind) {
|
||||
this.done = true;
|
||||
};
|
||||
|
||||
return TokenCacher;
|
||||
})();
|
||||
|
||||
exports["default"] = TokenCacher;
|
||||
module.exports = exports["default"];
|
||||
@@ -44,5 +44,9 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=0.12.7"
|
||||
},
|
||||
"browser": {
|
||||
"./src/Util/TokenCacher.js": "./src/Util/TokenCacher-shim.js",
|
||||
"./lib/Util/TokenCacher.js": "./lib/Util/TokenCacher-shim.js"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export default class Client extends EventEmitter {
|
||||
constructor(options = {}) {
|
||||
super();
|
||||
this.options = options || {};
|
||||
this.options.compress = options.compress || true;
|
||||
this.options.compress = options.compress || (!process.browser);
|
||||
this.options.revive = options.revive || false;
|
||||
this.options.rate_limit_as_error = options.rate_limit_as_error || false;
|
||||
this.internal = new InternalClient(this);
|
||||
|
||||
19
src/Util/TokenCacher-shim.js
Normal file
19
src/Util/TokenCacher-shim.js
Normal file
@@ -0,0 +1,19 @@
|
||||
// Shim for the token cacher in the browser.
|
||||
export default class TokenCacher {
|
||||
constructor() {
|
||||
}
|
||||
|
||||
setToken() {
|
||||
}
|
||||
|
||||
save() {
|
||||
}
|
||||
|
||||
getToken() {
|
||||
return null;
|
||||
}
|
||||
|
||||
init(ind) {
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user