MCPcopy
hub / github.com/MagicMirrorOrg/MagicMirror / setSocketIO

Method setSocketIO

js/node_helper.js:103–127  ·  view source on GitHub ↗
(io)

Source from the content-addressed store, hash-verified

101 * argument io Socket.io - The Socket io object.
102 */
103 setSocketIO (io) {
104 this.io = io;
105
106 Log.log(`Connecting socket for: ${this.name}`);
107
108 io.of(this.name).on("connection", (socket) => {
109 // register catch all.
110 socket.onAny((notification, payload) => {
111 if (config?.hideConfigSecrets && payload && typeof payload === "object") {
112 try {
113 // Calculate exactly which secrets this module is allowed to receive
114 const allowedSecrets = getAllowedSecrets(this.name);
115 // Expand only these safe, module-specific secrets in the payload
116 const payloadStr = replaceSecretPlaceholder(JSON.stringify(payload), allowedSecrets);
117 this.socketNotificationReceived(notification, JSON.parse(payloadStr));
118 } catch (e) {
119 Log.error("Error substituting variables in payload: ", e);
120 this.socketNotificationReceived(notification, payload);
121 }
122 } else {
123 this.socketNotificationReceived(notification, payload);
124 }
125 });
126 });
127 }
128
129 /**
130 * Check the status of a fetch response.

Callers 1

AppFunction · 0.80

Calls 4

getAllowedSecretsFunction · 0.85
replaceSecretPlaceholderFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected