mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 03:53:29 +01:00
Merge pull request #9 from hydrabolt/speedboosts
pull impressive startup speed boost
This commit is contained in:
17
index.js
17
index.js
@@ -136,6 +136,8 @@ exports.Client.prototype.login = function( email, password ) {
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
self.connectWebsocket();
|
||||||
|
|
||||||
Internal.XHR.login( email, password, function( err, token ) {
|
Internal.XHR.login( email, password, function( err, token ) {
|
||||||
|
|
||||||
if ( err ) {
|
if ( err ) {
|
||||||
@@ -143,10 +145,11 @@ exports.Client.prototype.login = function( email, password ) {
|
|||||||
reason: "failed to log in",
|
reason: "failed to log in",
|
||||||
error: err
|
error: err
|
||||||
} ] );
|
} ] );
|
||||||
|
self.websocket.close();
|
||||||
} else {
|
} else {
|
||||||
self.token = token;
|
self.token = token;
|
||||||
|
self.websocket.sendData();
|
||||||
self.loggedIn = true;
|
self.loggedIn = true;
|
||||||
self.connectWebsocket();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
@@ -168,6 +171,8 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
var sentInitData = false;
|
||||||
|
|
||||||
this.websocket = new WebSocket( Endpoints.WEBSOCKET_HUB );
|
this.websocket = new WebSocket( Endpoints.WEBSOCKET_HUB );
|
||||||
this.websocket.onclose = function( e ) {
|
this.websocket.onclose = function( e ) {
|
||||||
self.triggerEvent( "disconnected", [ {
|
self.triggerEvent( "disconnected", [ {
|
||||||
@@ -210,7 +215,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
|
|
||||||
self.cacheServer( _server, function( server ) {
|
self.cacheServer( _server, function( server ) {
|
||||||
cached++;
|
cached++;
|
||||||
if ( cached >= toCache ) {
|
if ( cached === toCache ) {
|
||||||
self.ready = true;
|
self.ready = true;
|
||||||
self.triggerEvent( "ready" );
|
self.triggerEvent( "ready" );
|
||||||
}
|
}
|
||||||
@@ -337,6 +342,12 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
}
|
}
|
||||||
this.websocket.onopen = function() {
|
this.websocket.onopen = function() {
|
||||||
|
|
||||||
|
this.sendData("onopen");
|
||||||
|
|
||||||
|
}
|
||||||
|
this.websocket.sendData = function(why){
|
||||||
|
if(this.readyState == 1 && !sentInitData && self.token){
|
||||||
|
sentInitData = true;
|
||||||
var connDat = {
|
var connDat = {
|
||||||
op: 2,
|
op: 2,
|
||||||
d: {
|
d: {
|
||||||
@@ -346,10 +357,10 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
connDat.d.properties = Internal.WebSocket.properties;
|
connDat.d.properties = Internal.WebSocket.properties;
|
||||||
|
|
||||||
this.sendPacket( connDat );
|
this.sendPacket( connDat );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
exports.Client.prototype.logout = function( callback ) {
|
exports.Client.prototype.logout = function( callback ) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user