mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
websocket opened whilst logging in
This commit is contained in:
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 ) {
|
||||
|
||||
Reference in New Issue
Block a user