sonda/android/www/server.js
tgiachi ba10b8ef7b feat(android): add an Android app
A Capacitor shell that opens a Sonda server in a WebView. It asks for the
address of the server the first time and remembers it, trusts the certificate
authorities installed on the phone, and keeps a notification with the
controls so that the music goes on with the screen off.

Fixes #47
2026-11-17 10:41:39 +01:00

16 lines
612 B
JavaScript

/** Turns what was typed into the address of a Sonda server, or null when it is not one. */
export function normalizeAddress(input) {
const text = String(input ?? '').trim()
if (text === '') return null
const withScheme = /^[a-z][a-z0-9+.-]*:\/\//i.test(text) ? text : `https://${text}`
let url
try {
url = new URL(withScheme)
} catch {
return null
}
if (url.protocol !== 'https:' && url.protocol !== 'http:') return null
if (url.hostname === '') return null
// The app lives at the root of the server: a path, a query or a fragment typed by mistake is dropped.
return url.origin
}