Polyfill WebSocket on Node

This commit is contained in:
Andras Schmelczer 2025-03-28 21:27:09 +00:00
parent fcd0cb84fe
commit 85648c9466
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
5 changed files with 1427 additions and 272 deletions

View file

@ -249,6 +249,15 @@ export class Syncer {
const wsUri = new URL(settings.remoteUri);
wsUri.protocol = wsUri.protocol === "https" ? "wss" : "ws";
wsUri.pathname = `/vaults/${settings.vaultName}/ws`;
if (
typeof globalThis !== "undefined" &&
typeof globalThis.WebSocket === "undefined"
) {
// polyfill for WebSocket in Node.js
globalThis.WebSocket = require("ws");
}
this.applyRemoteChangesWebSocket = new WebSocket(wsUri);
this.applyRemoteChangesWebSocket.onmessage = (event): void =>