42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
// General Sockethub client configuration. Dashtab talks to a single Sockethub
|
|
// server for every integration that needs it; the server URL is stored once in
|
|
// the `settings` namespace under `SOCKETHUB_URL_KEY`.
|
|
|
|
// Default server used when the user has not chosen another. This is also the
|
|
// instance we test against.
|
|
export const DEFAULT_SOCKETHUB_URL = 'https://sockethub.kosmos.org';
|
|
|
|
// Socket.IO path advertised by the Sockethub service descriptor.
|
|
export const SOCKETHUB_SOCKET_PATH = '/sockethub';
|
|
|
|
// How long to wait for the client to finish schema initialization after the
|
|
// socket connects.
|
|
export const SOCKETHUB_INIT_TIMEOUT = 10000;
|
|
|
|
// Storage namespace/key for the configured server URL.
|
|
export const SOCKETHUB_SETTINGS_NAMESPACE = 'settings';
|
|
export const SOCKETHUB_URL_KEY = 'sockethub-url';
|
|
|
|
// Platform ids that the calendar integration relies on.
|
|
export const CALDAV_PLATFORM = 'caldav';
|
|
|
|
// Normalizes a user-entered Sockethub URL to a bare origin. A missing scheme
|
|
// defaults to https; anything with whitespace or without a host is rejected.
|
|
export function normalizeSockethubUrl(input) {
|
|
let value = (input ?? '').trim();
|
|
|
|
if (!value || /\s/.test(value)) {
|
|
return null;
|
|
}
|
|
|
|
if (!/^https?:\/\//i.test(value)) {
|
|
value = `https://${value}`;
|
|
}
|
|
|
|
try {
|
|
return new URL(value).origin;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|