fix https connection

This commit is contained in:
Hayden 2023-08-23 12:27:34 -05:00
parent 9fa17bec90
commit a3cce59a2a
No known key found for this signature in database
GPG key ID: 17CF79474E257545

View file

@ -13,7 +13,12 @@ let socket: WebSocket | null = null;
const listeners = new Map<ServerEvent, (() => void)[]>(); const listeners = new Map<ServerEvent, (() => void)[]>();
function connect(onmessage: (m: EventMessage) => void) { function connect(onmessage: (m: EventMessage) => void) {
const ws = new WebSocket(`ws://${window.location.host}/api/v1/ws/events`); let protocol = "ws";
if (window.location.protocol === "https:") {
protocol = "wss";
}
const ws = new WebSocket(`${protocol}://${window.location.host}/api/v1/ws/events`);
ws.onopen = () => { ws.onopen = () => {
console.debug("connected to server"); console.debug("connected to server");