mirror of
https://github.com/owncast/owncast.git
synced 2025-11-04 05:17:27 +08:00
fix(notifications): do not support browser notifications for local servers
This commit is contained in:
@ -17,6 +17,10 @@ const NotificationsNotSupported = () => (
|
|||||||
<div>Browser notifications are not supported in your browser.</div>
|
<div>Browser notifications are not supported in your browser.</div>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const NotificationsNotSupportedLocal = () => (
|
||||||
|
<div>Browser notifications are not supported for local servers.</div>
|
||||||
|
);
|
||||||
|
|
||||||
export type PermissionPopupPreviewProps = {
|
export type PermissionPopupPreviewProps = {
|
||||||
start: () => void;
|
start: () => void;
|
||||||
};
|
};
|
||||||
@ -106,6 +110,10 @@ export const BrowserNotifyModal = () => {
|
|||||||
setBrowserPushPermissionsPending(false);
|
setBrowserPushPermissionsPending(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (window.location.hostname === 'localhost') {
|
||||||
|
return <NotificationsNotSupportedLocal />;
|
||||||
|
}
|
||||||
|
|
||||||
if (!browserPushSupported) {
|
if (!browserPushSupported) {
|
||||||
return <NotificationsNotSupported />;
|
return <NotificationsNotSupported />;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
export async function saveNotificationRegistration(channel, destination, accessToken) {
|
export async function saveNotificationRegistration(channel, destination, accessToken) {
|
||||||
|
console.log('saveNotificationRegistration');
|
||||||
const URL_REGISTER_NOTIFICATION = `/api/notifications/register`;
|
const URL_REGISTER_NOTIFICATION = `/api/notifications/register`;
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
@ -9,11 +10,7 @@ export async function saveNotificationRegistration(channel, destination, accessT
|
|||||||
body: JSON.stringify({ channel, destination }),
|
body: JSON.stringify({ channel, destination }),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
await fetch(`${URL_REGISTER_NOTIFICATION}?accessToken=${accessToken}`, options);
|
||||||
await fetch(`${URL_REGISTER_NOTIFICATION}?accessToken=${accessToken}`, options);
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isPushNotificationSupported() {
|
export function isPushNotificationSupported() {
|
||||||
@ -27,6 +24,7 @@ function urlBase64ToUint8Array(base64String: string) {
|
|||||||
const rawData = window.atob(base64);
|
const rawData = window.atob(base64);
|
||||||
const outputArray = new Uint8Array(rawData.length);
|
const outputArray = new Uint8Array(rawData.length);
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-plusplus
|
||||||
for (let i = 0; i < rawData.length; ++i) {
|
for (let i = 0; i < rawData.length; ++i) {
|
||||||
outputArray[i] = rawData.charCodeAt(i);
|
outputArray[i] = rawData.charCodeAt(i);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user