Fix protocol versions

This commit is contained in:
Amish Shah
2016-08-13 16:23:24 +01:00
parent c02d7808c1
commit a2f8680514
3 changed files with 10 additions and 5 deletions

View File

@@ -30,7 +30,10 @@ class RESTMethods {
getGateway() {
return new Promise((resolve, reject) => {
this.rest.makeRequest('get', Constants.Endpoints.gateway, true)
.then(res => resolve(res.url))
.then(res => {
this.rest.client.store.gateway = `${res.url}/?encoding=json&v=${this.rest.client.options.protocol_version}`;
resolve(this.rest.client.store.gateway);
})
.catch(reject);
});
}

View File

@@ -16,7 +16,6 @@ class WebSocketManager {
connect(gateway) {
this.status = Constants.Status.CONNECTING;
this.store.gateway = `${gateway}/?v=${this.client.options.protocol_version}`;
this.ws = new WebSocket(gateway);
this.ws.onopen = () => this.eventOpen();
this.ws.onclose = () => this.eventClose();
@@ -81,10 +80,14 @@ class WebSocketManager {
return this.eventError(Constants.Errors.BAD_WS_MESSAGE);
}
if (packet.op === 10) {
this.client.manager.setupKeepAlive(packet.d.heartbeat_interval);
}
return this.packetManager.handle(packet);
}
EventError() {
eventError() {
this.tryReconnect();
}
@@ -108,7 +111,7 @@ class WebSocketManager {
this.ws.close();
this.packetManager.handleQueue();
this.client.emit(Constants.Events.RECONNECTING);
this.connect(this.store.gateway);
this.connect(this.client.store.gateway);
}
}

View File

@@ -8,7 +8,6 @@ class ReadyHandler extends AbstractHandler {
handle(packet) {
const data = packet.d;
const client = this.packetManager.client;
client.manager.setupKeepAlive(data.heartbeat_interval);
client.store.user = client.store.add('users', new ClientUser(client, data.user));