use correct scheme in prod mode

This commit is contained in:
dusk 2023-05-05 11:49:00 +03:00
parent 90dff5ed7b
commit 913b0df0b0
Signed by: dusk
GPG Key ID: 1D8F8FAF2294D6EA
2 changed files with 8 additions and 5 deletions

View File

@ -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) => {

View File

@ -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<TrackWithId | null>(null);