@clevercloud/client
Advanced tools
Comparing version
# Clever Client changelog | ||
## 2.0.0-beta.4 (2019-08-28) | ||
- Fix SSE (add a timeout when opening a stream) | ||
## 2.0.0-beta.3 (2019-08-23) | ||
@@ -4,0 +8,0 @@ |
@@ -14,2 +14,4 @@ "use strict"; | ||
const OPEN_TIMEOUT = 3000; | ||
class AbstractLogsStream extends _streamAbstract.AbstractStream { | ||
@@ -91,4 +93,8 @@ constructor({ | ||
} = await this.prepareLogsSse(); | ||
const sse = this.createEventSource(url); | ||
const sse = this.createEventSource(url); // Sometimes, the EventSource is open but no messages are returned and no errors thrown | ||
// We wait for OPEN_TIMEOUT before considering the EventSource | ||
// if no message or error is received by then, we close the stream | ||
const openTimeoutId = setTimeout(doClose, OPEN_TIMEOUT); | ||
function doClose(reason) { | ||
@@ -100,2 +106,3 @@ sse.close(); | ||
sse.addEventListener('message', message => { | ||
clearTimeout(openTimeoutId); | ||
const parsedMessage = this.parseLogMessage(message); | ||
@@ -105,2 +112,3 @@ this.isPingMessage(parsedMessage) ? onPing(parsedMessage.heartbeat_delay_ms) : onMessage(parsedMessage); | ||
sse.addEventListener('error', err => { | ||
clearTimeout(openTimeoutId); | ||
this.isAuthErrorMessage(err) ? doClose(_streamAbstract.AUTHENTICATION_REASON) : doClose(); | ||
@@ -107,0 +115,0 @@ }); |
@@ -5,2 +5,4 @@ import { AbstractStream, AUTHENTICATION_REASON } from './stream.abstract.js'; | ||
const OPEN_TIMEOUT = 3000; | ||
export class AbstractLogsStream extends AbstractStream { | ||
@@ -79,2 +81,7 @@ | ||
// Sometimes, the EventSource is open but no messages are returned and no errors thrown | ||
// We wait for OPEN_TIMEOUT before considering the EventSource | ||
// if no message or error is received by then, we close the stream | ||
const openTimeoutId = setTimeout(doClose, OPEN_TIMEOUT); | ||
function doClose (reason) { | ||
@@ -86,2 +93,3 @@ sse.close(); | ||
sse.addEventListener('message', (message) => { | ||
clearTimeout(openTimeoutId); | ||
const parsedMessage = this.parseLogMessage(message); | ||
@@ -94,2 +102,3 @@ this.isPingMessage(parsedMessage) | ||
sse.addEventListener('error', (err) => { | ||
clearTimeout(openTimeoutId); | ||
this.isAuthErrorMessage(err) | ||
@@ -96,0 +105,0 @@ ? doClose(AUTHENTICATION_REASON) |
{ | ||
"name": "@clevercloud/client", | ||
"version": "2.0.0-beta.3", | ||
"version": "2.0.0-beta.4", | ||
"description": "JavaScript REST client and utils for Clever Cloud's API", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/CleverCloud/clever-client.js", |
358864
0.24%11755
0.11%