Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Ensure Module global bridge is initialized before main bootstrap logic runs.
import "./module.js";
import { loadModules } from "./loader.js";
import { io } from "./socketclient.js";
import { Translator } from "./translator.js";

let modules = [];
Expand Down Expand Up @@ -593,17 +594,14 @@
createDomObjects();

// Setup global socket listener for RELOAD event (watch mode)
const ioClient = globalThis.io;
if (typeof ioClient !== "undefined") {
const socket = ioClient("/", {
path: `${config.basePath || "/"}socket.io`
});

socket.on("RELOAD", () => {
Log.warn("Reload notification received from server");
window.location.reload(true);
});
}
const socket = io("/", {
path: `${config.basePath || "/"}socket.io`
});
Comment thread
KristjanESPERANTO marked this conversation as resolved.
Dismissed

socket.on("RELOAD", () => {
Log.warn("Reload notification received from server");
window.location.reload(true);
});

if (config.reloadAfterServerRestart) {
setInterval(async () => {
Expand Down
9 changes: 8 additions & 1 deletion js/socketclient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// eslint-disable-next-line import-x/no-unresolved -- Socket.IO serves this module at runtime.
const { io } = await import(/* @vite-ignore */ "/socket.io/socket.io.esm.min.js");
const socketIo = await import(/* @vite-ignore */ "/socket.io/socket.io.esm.min.js");
const { io } = socketIo;

if (typeof io !== "function") {
throw new Error("Socket.IO client did not provide a callable io export.");
}

export { io };

export const MMSocket = function (moduleName) {
if (typeof moduleName !== "string") {
Expand Down
1 change: 1 addition & 0 deletions tests/utils/vitest-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Module = require("node:module");
const path = require("node:path");

vi.doMock(path.resolve(__dirname, "../..", "js", "socketclient.js"), () => ({
io () {},
MMSocket () {}
}));

Expand Down