Skip to content

Commit

Permalink
Merge pull request #356 from Renumics/fix/websocket-path
Browse files Browse the repository at this point in the history
Fix websocket path
  • Loading branch information
druzsan authored Nov 13, 2023
2 parents 519dd29 + d7a2f88 commit 9757856
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 3 additions & 6 deletions src/services/websocket/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ class Connection {
messageQueue: string[];
onmessage?: (data: unknown) => void;

constructor(host: string, port: string) {
constructor(host: string, port: string, basePath: string) {
this.messageQueue = [];
if (globalThis.location.protocol === 'https:') {
this.url = `wss://${host}:${port}/api/ws`;
} else {
this.url = `ws://${host}:${port}/api/ws`;
}
const protocol = globalThis.location.protocol === 'https:' ? 'wss:' : 'ws:';
this.url = `${protocol}//${host}:${port}${basePath}api/ws`;
this.#connect();
}

Expand Down
7 changes: 4 additions & 3 deletions src/services/websocket/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export class WebsocketService {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
messageHandlers: Map<string, MessageHandler>;

constructor(host: string, port: string) {
constructor(host: string, port: string, basePath: string) {
this.messageHandlers = new Map();
this.connection = new Connection(host, port);
this.connection = new Connection(host, port, basePath);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this.connection.onmessage = (message: any) => {
const messageHandler = this.messageHandlers.get(message.type);
Expand All @@ -35,7 +35,8 @@ export class WebsocketService {

const websocketService = new WebsocketService(
globalThis.location.hostname,
globalThis.location.port
globalThis.location.port,
globalThis.location.pathname
);

websocketService.registerMessageHandler('error', (problem: Problem) => {
Expand Down

0 comments on commit 9757856

Please sign in to comment.