Separate websocket internals for RPC (#1893)

* websocket centralization

* more centralization

* whoops

* Update WebSocket.js
This commit is contained in:
Gus Caplan
2017-09-06 01:20:10 -05:00
committed by Amish Shah
parent f95ae4fcb7
commit 675e1eccb1
5 changed files with 51 additions and 68 deletions

View File

@@ -1,5 +1,4 @@
const Constants = require('../util/Constants');
const WebSocketConnection = require('./websocket/WebSocketConnection');
const { Error } = require('../errors');
/**
@@ -40,8 +39,7 @@ class ClientManager {
this.client.token = token;
const timeout = this.client.setTimeout(() => reject(new Error('TOKEN_INVALID')), 1000 * 300);
this.client.api.gateway.get().then(res => {
const protocolVersion = Constants.DefaultOptions.ws.version;
const gateway = `${res.url}/?v=${protocolVersion}&encoding=${WebSocketConnection.ENCODING}`;
const gateway = `${res.url}/`;
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
this.client.ws.connect(gateway);
this.client.ws.connection.once('close', event => {