@cloudgaming/rpc
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -11,2 +11,3 @@ "use strict"; | ||
const RETRY_TIMEOUT_BASE = 1000; | ||
const CONNECT_TIMEOUT = 10000; | ||
class Client extends class { | ||
@@ -132,2 +133,15 @@ } { | ||
await new Promise((resolve, reject) => { | ||
const ws = this.websocket; | ||
const onTimeout = () => { | ||
cleanUp(); | ||
debug('connect timeout'); | ||
try { | ||
ws.addEventListener('open', () => ws.close()); | ||
ws.close(); | ||
} | ||
catch { | ||
// just ignore | ||
} | ||
reject(new Error('Connection Timeout')); | ||
}; | ||
const onOpen = () => { | ||
@@ -144,7 +158,8 @@ cleanUp(); | ||
}; | ||
const ws = this.websocket; | ||
function cleanUp() { | ||
clearTimeout(timeout); | ||
ws.removeEventListener('open', onOpen); | ||
ws.removeEventListener('error', onReject); | ||
} | ||
const timeout = setTimeout(onTimeout, CONNECT_TIMEOUT); | ||
this.websocket.addEventListener('open', onOpen); | ||
@@ -151,0 +166,0 @@ this.websocket.addEventListener('error', onReject); |
{ | ||
"name": "@cloudgaming/rpc", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "type": "commonjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39523
615