Skip to content
Open
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
13 changes: 13 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,19 @@ export default defineConfig([
"sort-keys": "off"
}
},
{
files: [
"js/main.js",
"js/module.js",
"js/loader.js",
"js/socketclient.js",
"js/translator.js"
],
rules: {
// Browser ESM entry files must always include the file extension in relative imports.
"import-x/extensions": ["error", "always"]
}
},
{
files: ["**/*.js"],
ignores: [
Expand Down
2 changes: 0 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
<div class="region fullscreen above"><div class="container"></div></div>
<script type="text/javascript" src="socket.io/socket.io.js"></script>
<script type="text/javascript" src="node_modules/nunjucks/browser/nunjucks.min.js"></script>
<script type="text/javascript" src="js/defaults.js"></script>
<script type="text/javascript" src="js/vendor.js"></script>
<script type="text/javascript" src="defaultmodules/defaultmodules.js"></script>
<script type="text/javascript" src="defaultmodules/utils.js"></script>
Expand All @@ -52,7 +51,6 @@
<script type="text/javascript" src="config/basepath.js"></script>
<script type="text/javascript" src="js/animateCSS.js"></script>
<script type="text/javascript" src="js/positions.js"></script>
<script type="module" src="js/module.js"></script>
<script type="module" src="js/main.js"></script>
</body>
</html>
11 changes: 6 additions & 5 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global addAnimateCSS, removeAnimateCSS, AnimateCSSIn, AnimateCSSOut, modulePositions, io */
/* global addAnimateCSS, removeAnimateCSS, AnimateCSSIn, AnimateCSSOut, modulePositions */

// eslint-disable-next-line import-x/extensions
// Ensure Module global bridge is initialized before main bootstrap logic runs.
import "./module.js";
import { loadModules } from "./loader.js";
// eslint-disable-next-line import-x/extensions
import { Translator } from "./translator.js";

let modules = [];
Expand Down Expand Up @@ -593,8 +593,9 @@ export const MM = {
createDomObjects();

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

Expand Down
11 changes: 4 additions & 7 deletions js/module.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/* global nunjucks */

// eslint-disable-next-line import-x/extensions
import { loadFileForModule } from "./loader.js";
// eslint-disable-next-line import-x/extensions
import { MMSocket } from "./socketclient.js";
// eslint-disable-next-line import-x/extensions
import { Translator } from "./translator.js";

/*
Expand Down Expand Up @@ -166,13 +161,15 @@ export class Module {
return this._nunjucksEnvironment;
}

this._nunjucksEnvironment = new nunjucks.Environment(new nunjucks.WebLoader(this.file(""), { async: true }), {
const nunjucksEngine = globalThis.nunjucks;

this._nunjucksEnvironment = new nunjucksEngine.Environment(new nunjucksEngine.WebLoader(this.file(""), { async: true }), {
trimBlocks: true,
lstripBlocks: true
});

this._nunjucksEnvironment.addFilter("translate", (str, variables) => {
return nunjucks.runtime.markSafe(this.translate(str, variables));
return nunjucksEngine.runtime.markSafe(this.translate(str, variables));
});

return this._nunjucksEnvironment;
Expand Down
14 changes: 7 additions & 7 deletions js/socketclient.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* global io */

export const MMSocket = function (moduleName) {
if (typeof moduleName !== "string") {
throw new Error("Please set the module name for the MMSocket.");
}

const ioClient = globalThis.io;
if (typeof ioClient !== "function") {
throw new Error("socket.io client is not available.");
}

this.moduleName = moduleName;

// Private Methods
let base = "/";
if (typeof config !== "undefined" && typeof config.basePath !== "undefined") {
base = config.basePath;
}
this.socket = io(`/${this.moduleName}`, {
const base = globalThis.config?.basePath ?? "/";
this.socket = ioClient(`/${this.moduleName}`, {
path: `${base}socket.io`,
pingInterval: 120000, // send pings every 2 mins
pingTimeout: 120000 // wait up to 2 mins for a pong
Expand Down