Skip to content

Commit

Permalink
fix(ui): pusher (#3040)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahargl authored Jan 16, 2025
1 parent aa6d237 commit c536b23
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
24 changes: 10 additions & 14 deletions keep-ui/utils/hooks/usePusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export const useWebsocket = () => {
channelName = `private-${session?.tenantId}`;
console.log("useWebsocket: Creating new Pusher instance");
try {
const isRelativeHostAndNotLocal =
configData.PUSHER_HOST &&
!configData.PUSHER_HOST.includes("://") &&
!["localhost", "127.0.0.1"].includes(configData.PUSHER_HOST);
// check if the pusher host is relative (e.g. /websocket)
const isRelative =
configData.PUSHER_HOST && configData.PUSHER_HOST.startsWith("/");

// if relative, get the relative port:
let port = configData.PUSHER_PORT;
if (isRelativeHostAndNotLocal) {
if (isRelative) {
// Handle case where port is empty string (default ports 80/443)
if (window.location.port) {
port = parseInt(window.location.port, 10);
Expand All @@ -42,17 +41,13 @@ export const useWebsocket = () => {
}
}

console.log(
"useWebsocket: isRelativeHostAndNotLocal:",
isRelativeHostAndNotLocal
);
console.log("useWebsocket: isRelativeHostAndNotLocal:", isRelative);

var pusherOptions: PusherOptions = {
wsHost: isRelativeHostAndNotLocal
? window.location.hostname
: configData.PUSHER_HOST,
wsPath: isRelativeHostAndNotLocal ? configData.PUSHER_HOST : "",
wsPort: isRelativeHostAndNotLocal ? port : configData.PUSHER_PORT,
wsHost: isRelative ? window.location.hostname : configData.PUSHER_HOST,
// in case its relative, use path e.g. "/websocket"
wsPath: isRelative ? configData.PUSHER_HOST : "",
wsPort: isRelative ? port : configData.PUSHER_PORT,
forceTLS: window.location.protocol === "https:",
disableStats: true,
enabledTransports: ["ws", "wss"],
Expand All @@ -77,6 +72,7 @@ export const useWebsocket = () => {
});

PUSHER.connection.bind("error", (err: any) => {
void err; // No-op line for debugger target
console.error("useWebsocket: Pusher connection error:", err);
});

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "keep"
version = "0.34.5"
version = "0.34.6"
description = "Alerting. for developers, by developers."
authors = ["Keep Alerting LTD"]
packages = [{include = "keep"}]
Expand Down

0 comments on commit c536b23

Please sign in to comment.