constructor(user, chosenServer) {
		super(user);

		this.connectionType = 'WS';

		let addr = chosenServer.endpoint;
		this._debug(`Connecting to WebSocket CM ${addr}`);
		this.stream = new WS13.WebSocket(`wss://${addr}/cmsocket/`, {
			pingInterval: 30000,
			proxyTimeout: this.user.options.proxyTimeout,
			connection: {
				localAddress: this.user.options.localAddress,
				agent: this.user._getProxyAgent()
			}
		});

		// Set up the connection timeout
		this.stream.setTimeout(this.user._connectTimeout);

		this.stream.on('debug', msg => this._debug(msg, true));
		this.stream.on('message', this._readMessage.bind(this));

		this.stream.on('disconnected', (code, reason, initiatedByUs) => {
			if (this._disconnected) {
				return;
			}

			this._disconnected = true;
			this._debug(`WebSocket closed by ${initiatedByUs ? 'us' : 'remote'} with code ${code} and reason "${reason}"`);
			this.user._handleConnectionClose(this);
		});

		this.stream.on('error', (err) => {
			if (this._disconnected) {
				return;
			}

			this._disconnected = true;
			this._debug('WebSocket disconnected with error: ' + err.message);

			if (err.proxyConnecting || err.constructor.name == 'SocksClientError') {
				// This error happened while connecting to the proxy
				this.user._cleanupClosedConnection();
				this.user.emit('error', err);
			} else {
				this.user._handleConnectionClose(this);
			}
		});

		this.stream.on('connected', () => {
			this._debug('WebSocket connection success; now logging in');
			this.stream.setTimeout(0); // Disable timeout
			this.user._sendLogOn();
		});

		this.stream.on('timeout', () => {
			if (this._disconnected) {
				return;
			}

			this._disconnected = true;
			this._debug('WS connection timed out');
			this.user._connectTimeout = Math.min(this.user._connectTimeout * 2, 10000); // 10 seconds max
			this.stream.disconnect();
			this.user._doConnection();
		});
	}
@param {SteamUser} user
@param {CmServer} chosenServer