diff --git a/src/comms.ts b/src/comms.ts index aea42e9..f52286c 100644 --- a/src/comms.ts +++ b/src/comms.ts @@ -1,3 +1,4 @@ +import { dev } from '$app/environment'; import type { TrackWithId } from "./types"; const API_VERSION: number = 20; @@ -16,8 +17,6 @@ interface Message { type MessageType = 'request' | 'response' | 'broadcast'; type RequestCallback = (arg0: Message | null) => void; -type Category = 'album' | 'artist' | 'album_artist' | 'genre' | 'playlist'; - interface Callbacks { onDisconnect: (authenticated: boolean, reason: string) => void; onConnect: (initial: Message) => void; @@ -52,7 +51,8 @@ export class MetadataCommunicator { connect(address: string, password: string) { this.close(); - this.ws = new WebSocket(`ws://${address}`); + const scheme = dev ? "ws" : "wss"; + this.ws = new WebSocket(`${scheme}://${address}`); this.ws.addEventListener('open', (event) => { this.makeRequest("authenticate", 'request', { password }, (msg) => { diff --git a/src/stores.ts b/src/stores.ts index 764a4db..dccf6c4 100644 --- a/src/stores.ts +++ b/src/stores.ts @@ -1,5 +1,6 @@ import { get, writable } from 'svelte/store'; import { type ResourceId, type Track, type TrackId, type TrackWithId, LoopKind } from './types'; +import { dev } from '$app/environment'; function writableStorage(key: string, defaultValue: string) { const store = writable(localStorage.getItem(key) ?? defaultValue); @@ -11,11 +12,13 @@ export const address = writableStorage("address", "127.0.0.1:5505"); export const token = writableStorage("token", ""); export function makeThumbnailUrl(id: ResourceId) { - return `http://${get(address)}/thumbnail/${id}?token=${get(token)}`; + const scheme = dev ? "http" : "https"; + return `${scheme}://${get(address)}/thumbnail/${id}?token=${get(token)}`; } export function makeAudioUrl(id: TrackId) { - return `http://${get(address)}/audio/external_id/${id}?token=${get(token)}`; + const scheme = dev ? "http" : "https"; + return `${scheme}://${get(address)}/audio/external_id/${id}?token=${get(token)}`; } export const currentTrack = writable(null);