Skip to content

Commit

Permalink
#369 Refresh vector layers, also some WEBSOCKET_ROOT_PATH (#370) (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
tariqksoliman committed May 1, 2023
1 parent 9cbe4ef commit 9ba5072
Show file tree
Hide file tree
Showing 11 changed files with 599 additions and 433 deletions.
4 changes: 4 additions & 0 deletions API/Backend/Config/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ let setup = {
process.env.NODE_ENV === "development"
? ""
: process.env.ROOT_PATH || "",
WEBSOCKET_ROOT_PATH:
process.env.NODE_ENV === "development"
? ""
: process.env.WEBSOCKET_ROOT_PATH || "",
});
}
);
Expand Down
104 changes: 45 additions & 59 deletions API/websocket.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
const WebSocket = require('isomorphic-ws');
const WebSocket = require("isomorphic-ws");
const logger = require("./logger");

const websocket = {
wss: null,
init: function (server) {
logger(
"info",
"Trying to init websocket...",
"websocket",
null,
""
);

if (!server === null) {
logger(
"websocket_error",
"server parameter not defined.",
"error",
null,
""
);
return null
}

logger(
"info",
"Server is valid so still trying to init websocket...",
"websocket",
null,
""
);

const wss = new WebSocket.Server({ server });
websocket.wss = wss;

// Broadcast to all clients
wss.broadcast = function broadcast(data, isBinary) {
wss.clients.forEach(client => {
if (client.readyState === WebSocket.OPEN && data !== undefined) {
client.send(data, { binary: isBinary });
}
});
};

wss.on('connection', (ws) => {
ws.on('message', (message) => {
wss.broadcast(message);
});
});

wss.on('close', () => {
logger(
"info",
"Websocket disconnected...",
"websocket",
null,
""
);
websocket.wss = null
});
wss: null,
init: function (server) {
logger("info", "Trying to init websocket...", "websocket", null, "");

if (!server === null) {
logger(
"websocket_error",
"server parameter not defined.",
"error",
null,
""
);
return null;
}
}

logger(
"info",
"Server is valid so still trying to init websocket...",
"websocket",
null,
""
);
const wss = new WebSocket.Server({ server });
websocket.wss = wss;

// Broadcast to all clients
wss.broadcast = function broadcast(data, isBinary) {
wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN && data !== undefined) {
client.send(data, { binary: isBinary });
}
});
};

wss.on("connection", (ws) => {
ws.on("message", (message) => {
wss.broadcast(message);
});
});

wss.on("close", () => {
logger("info", "Websocket disconnected...", "websocket", null, "");
websocket.wss = null;
});
},
};

module.exports = { websocket };
4 changes: 4 additions & 0 deletions configuration/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ function getClientEnvironment(publicUrl) {
(process.env.NODE_ENV || "development") === "development"
? ""
: process.env.ROOT_PATH || "",
WEBSOCKET_ROOT_PATH:
(process.env.NODE_ENV || "development") === "development"
? ""
: process.env.WEBSOCKET_ROOT_PATH || "",
// We support configuring the sockjs pathname during development.
// These settings let a developer run multiple simultaneous projects.
// They are used as the connection `hostname`, `pathname` and `port`
Expand Down
4 changes: 4 additions & 0 deletions docs/pages/Setup/ENVs/ENVs.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Sets "SameSite=None; Secure" on the login cookie. Useful when using AUTH=local a

Set MMGIS to be deployed under a subpath. For example if serving at the subpath 'https://{domain}/path/where/I/serve/mmgis' is desired, set `ROOT_PATH=/path/where/I/serve/mmgis`. If no subpath, leave blank. | string | default `""`

#### `WEBSOCKET_ROOT_PATH=`

Overrides ROOT_PATH's use when the client connects via websocket. Websocket url: `${ws_protocol}://${window.location.host}${WEBSOCKET_ROOT_PATH || ROOT_PATH || ''}/` | string | default `""`

#### `CLEARANCE_NUMBER=`

Sets a clearance for the website | string | default `CL##-####`
Expand Down
Loading

0 comments on commit 9ba5072

Please sign in to comment.