mirror of
https://github.com/penpot/penpot.git
synced 2025-12-11 22:14:05 +01:00
♻️ Refactor MockWebSocket
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user