Skip to content

Commit

Permalink
_
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyHamachi committed Feb 17, 2024
1 parent dceda60 commit 8ce05aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
18 changes: 8 additions & 10 deletions src/js/websocket.awaitable.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,15 @@ export class AwaitbleWebSocket {
this.socket.addEventListener("close", this.onClose);
this.socket.addEventListener("error", this.onError);
this.socket.messagePool = {};
}

async waitOpen() {
let _this = this;
let R = new Promise((resolve, reject) => {
setInterval(() => {
if (_this.socket.isOpen) {
resolve();
return new Promise((resolve, reject) => {
let interval_id = setInterval(() => {
if (this.socket.isOpen) {
resolve(this);
clearInterval(interval_id);
}
}, 10);
});
return R;
}

async send(message) {
Expand Down Expand Up @@ -51,11 +48,12 @@ export class AwaitbleWebSocket {
}
}
onClose(event) {
log(event);
// this -> this.socket
this.isOpen = false;
}
onError(event) {
log(event);
// this -> this.socket
this.isOpen = false;
}

}
3 changes: 1 addition & 2 deletions src/tab/js/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@ window.BlueFoxScript = BlueFoxScript;


let start_ws = async () => {
let webSocket = new AwaitbleWebSocket("ws://127.0.0.1:8888");
await webSocket.waitOpen();
let webSocket = await (new AwaitbleWebSocket("ws://127.0.0.1:8888"));

let webSocketMessageHandler = {
"getFileTree": async (data) => {
Expand Down

0 comments on commit 8ce05aa

Please sign in to comment.