mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
Merge pull request #9 from hydrabolt/speedboosts
pull impressive startup speed boost
This commit is contained in:
33
index.js
33
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,17 +342,23 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
}
|
}
|
||||||
this.websocket.onopen = function() {
|
this.websocket.onopen = function() {
|
||||||
|
|
||||||
var connDat = {
|
this.sendData("onopen");
|
||||||
op: 2,
|
|
||||||
d: {
|
|
||||||
token: self.token,
|
|
||||||
v: 2
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
connDat.d.properties = Internal.WebSocket.properties;
|
}
|
||||||
|
this.websocket.sendData = function(why){
|
||||||
|
if(this.readyState == 1 && !sentInitData && self.token){
|
||||||
|
sentInitData = true;
|
||||||
|
var connDat = {
|
||||||
|
op: 2,
|
||||||
|
d: {
|
||||||
|
token: self.token,
|
||||||
|
v: 2
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.sendPacket( connDat );
|
connDat.d.properties = Internal.WebSocket.properties;
|
||||||
|
this.sendPacket( connDat );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user