Read the statement by Michael Teeuw here.
Show calendar based on IP Address accessed
-
@MMRIZE and that module calls its own rest call publishes the address in its getDom() result, with id= on div
and then cal module can use synchronous document.getElementsById()
to get that value.
-
so the little module is
https://github.com/sdetweil/getip
and it does correctly return the ip address of the client… tested from 4 different systems to the same MM…
see later post for final solution
-
-
I tried your code, but find that once I include getip module in config.js, I am not seeing any output for calendar. Is this the expected output. Without getip module, I find that client_ip = document.getElementById("getip is returning null.Please advice
-
@Spinstersee later post
-
@Spinster
By the way, which client are you using? Electron? Or Browser? -
@MMRIZE Browser as of now.
I also tried using express ipfilter, but the problem is I don’t know how to use it in module.js, it is throwing error saying ipfilter not known etc
-
@Spinster well, here is a working example, in addition to the other code already
watch out if using address AND MM host system not included. as it won’t show either…
one could make the ipaddress in cal a list (of ip addresses) similar to what @MMRIZE does…
I don’t like adding the extra block,
just add the var to the thing that matters…see later post
-
@Spinster
Withgetip
of @sdetweil andMMM-ModuleMonkeyPatch
, I did it. (You don’t have to modify the original source code for future-proof.)Example.
Server is running on192.168.178.63
and I run 2 clients on192.168.178.22
and192.168.178.63
.
Both 2 clients can show different set of calendars.{ module: "MMM-ModuleMonkeyPatch", config: { patches: [ { module: "calendar", method: "socketNotificationReceived", patch: async function (original, args) { const [ notification, payload ] = args if (notification === "CALENDAR_EVENTS") { const calendarName = this.config.calendars.find((cal) => cal.url === payload?.url)?.name const r = await fetch('http://192.168.178.63:8080/modules/getip') const ip = JSON.parse(await r.text())?.[ 'address' ] ?? null if (!this.config.clientMap?.[ ip ]?.includes(calendarName)) { return original(notification, { ...payload, events: [] }) } } return original(notification, payload) } } ] } }, { module: "getip", }, { module: "calendar", header: "US Holidays", position: "top_left", config: { clientMap: { "192.168.178.63": [ "cal1", "cal2", "cal3" ], "192.168.178.22": ["cal3", "cal4", "cal5"] }, calendars: [ { url: "...", name: "cal1", }, { url: "...", name: "cal2", }, { url: "...", name: "cal3", }, { url: "...", name: "cal4", }, { url: "...", name: "cal5", } ] } },
TO Improve
Whenever notificationCALENDAR_EVENTS
coming,getip
is called. After first execution, to store IP on thelocalStorage
orcookie
would be better. -
@sdetweil will express ipfilter be useful? Similar to whitelist, can we try something