mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-20 19:24:43 +12:00
websocket opened whilst logging in
This commit is contained in:
parent
9ce332563b
commit
4b5e229df9
1 changed files with 21 additions and 11 deletions
32
index.js
32
index.js
|
@ -138,6 +138,8 @@ exports.Client.prototype.login = function( email, password ) {
|
|||
|
||||
var time = Date.now();
|
||||
|
||||
self.connectWebsocket();
|
||||
|
||||
Internal.XHR.login( email, password, function( err, token ) {
|
||||
|
||||
if ( err ) {
|
||||
|
@ -148,8 +150,8 @@ exports.Client.prototype.login = function( email, password ) {
|
|||
} else {
|
||||
self.token = token;
|
||||
self.loggedIn = true;
|
||||
self.connectWebsocket();
|
||||
console.log("Took "+ (Date.now() - time) +" ms to login!");
|
||||
self.websocket.sendData();
|
||||
}
|
||||
|
||||
} );
|
||||
|
@ -173,6 +175,8 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||
|
||||
var time = Date.now();
|
||||
|
||||
var sentInitData = false;
|
||||
|
||||
this.websocket = new WebSocket( Endpoints.WEBSOCKET_HUB );
|
||||
this.websocket.onclose = function( e ) {
|
||||
self.triggerEvent( "disconnected", [ {
|
||||
|
@ -347,20 +351,26 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||
}
|
||||
this.websocket.onopen = function() {
|
||||
|
||||
var connDat = {
|
||||
op: 2,
|
||||
d: {
|
||||
token: self.token,
|
||||
v: 2
|
||||
}
|
||||
};
|
||||
this.sendData();
|
||||
|
||||
connDat.d.properties = Internal.WebSocket.properties;
|
||||
|
||||
this.sendPacket( connDat );
|
||||
console.log("Took "+ (Date.now() - time) +" ms to open WS connection!");
|
||||
time = Date.now();
|
||||
}
|
||||
this.websocket.sendData = function(){
|
||||
if(this.readyState == 1 && !sentInitData && self.token){
|
||||
sentInitData = true;
|
||||
var connDat = {
|
||||
op: 2,
|
||||
d: {
|
||||
token: self.token,
|
||||
v: 2
|
||||
}
|
||||
};
|
||||
|
||||
connDat.d.properties = Internal.WebSocket.properties;
|
||||
this.sendPacket( connDat );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.Client.prototype.logout = function( callback ) {
|
||||
|
|
Loading…
Reference in a new issue