diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-05-28 15:11:46 -0400 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-05-28 15:11:46 -0400 |
commit | 22cd4f90a10cd8174a8f6520d045c5da4d0b5066 (patch) | |
tree | dcaaf9526c3b10b3b80b1d2b4452f2e555801d1d /extension/src/continueIdeClient.ts | |
parent | 78513ba9a63635a777262806793394131ad43744 (diff) | |
download | sncontinue-22cd4f90a10cd8174a8f6520d045c5da4d0b5066.tar.gz sncontinue-22cd4f90a10cd8174a8f6520d045c5da4d0b5066.tar.bz2 sncontinue-22cd4f90a10cd8174a8f6520d045c5da4d0b5066.zip |
First load fail error fixed
Diffstat (limited to 'extension/src/continueIdeClient.ts')
-rw-r--r-- | extension/src/continueIdeClient.ts | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/extension/src/continueIdeClient.ts b/extension/src/continueIdeClient.ts index 6c65415f..35eb668d 100644 --- a/extension/src/continueIdeClient.ts +++ b/extension/src/continueIdeClient.ts @@ -66,18 +66,22 @@ class IdeProtocolClient { } async isConnected() { - if (this._ws === null) { - this._ws = new WebSocket(this._serverUrl); - } - // On open, return a promise - if (this._ws!.readyState === WebSocket.OPEN) { - return; - } - return new Promise((resolve, reject) => { - this._ws!.onopen = () => { - resolve(null); + if (this._ws === null || this._ws.readyState !== WebSocket.OPEN) { + let ws = new WebSocket(this._serverUrl); + ws.onclose = () => { + this._ws = null; }; - }); + ws.on("message", (data: any) => { + this.handleMessage(JSON.parse(data)); + }); + this._ws = ws; + + return new Promise((resolve, reject) => { + ws.addEventListener("open", () => { + resolve(null); + }); + }); + } } async startCore() { |