mirror of
https://github.com/penpot/penpot.git
synced 2025-05-10 04:56:39 +02:00
♻️ Refactor MockWebSocket
This commit is contained in:
parent
3bae6e4661
commit
572c6f02e2
3 changed files with 91 additions and 22 deletions
|
@ -11,20 +11,15 @@ window.WebSocket = class MockWebSocket extends EventTarget {
|
|||
}
|
||||
|
||||
static getByURL(url) {
|
||||
return this.#mocks.get(url);
|
||||
}
|
||||
|
||||
static waitForURL(url) {
|
||||
return new Promise((resolve) => {
|
||||
let intervalID = setInterval(() => {
|
||||
for (const [wsURL, ws] of this.#mocks) {
|
||||
if (wsURL.includes(url)) {
|
||||
clearInterval(intervalID);
|
||||
resolve(ws);
|
||||
}
|
||||
}
|
||||
}, 30);
|
||||
});
|
||||
if (this.#mocks.has(url)) {
|
||||
return this.#mocks.get(url);
|
||||
}
|
||||
for (const [wsURL, ws] of this.#mocks) {
|
||||
if (wsURL.includes(url)) {
|
||||
return ws;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
#url;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue