Skip to content

Commit 38bf006

Browse files
committed
ws/wss を自動で選ぶように
1 parent 13b0b2d commit 38bf006

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/services/websocket.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export enum ConnectionStatus {
1010
ERROR = "error",
1111
}
1212

13+
const protocol = location.protocol === "https:" ? "wss:" : "ws:";
14+
const defaultUrl = protocol + "//" + location.host + "/api/ws";
15+
1316
// WebSocket client class
1417
class WebSocketClient {
1518
private socket: WebSocket | null = null;
@@ -29,7 +32,7 @@ class WebSocketClient {
2932
);
3033

3134
// Connect to WebSocket server
32-
public connect(url: string = "ws://" + location.host + "/api/ws"): void {
35+
public connect(url: string = defaultUrl): void {
3336
if (this.socket && this.isConnected.value) {
3437
console.log("WebSocket already connected");
3538
return;

0 commit comments

Comments
 (0)