mirror of
https://github.com/danog/telegram-tt.git
synced 2025-01-22 05:11:55 +01:00
Notifications: Fix missing sound in Yandex Browser (#1504)
This commit is contained in:
parent
e37326ca64
commit
671d888641
@ -4,6 +4,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no, viewport-fit=cover">
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no, viewport-fit=cover">
|
||||||
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
|
<meta name="mobile-web-app-title" content="Telegram WebZ">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="apple-mobile-web-app-title" content="Telegram WebZ">
|
<meta name="apple-mobile-web-app-title" content="Telegram WebZ">
|
||||||
<meta name="application-name" content="Telegram WebZ">
|
<meta name="application-name" content="Telegram WebZ">
|
||||||
|
@ -80,12 +80,18 @@ function getNotificationData(data: PushData): NotificationData {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function playNotificationSound(id: number) {
|
async function getClients() {
|
||||||
|
const appUrl = new URL(self.registration.scope).origin;
|
||||||
const clients = await self.clients.matchAll({ type: 'window' }) as WindowClient[];
|
const clients = await self.clients.matchAll({ type: 'window' }) as WindowClient[];
|
||||||
const clientsInScope = clients.filter((client) => client.url === self.registration.scope);
|
return clients.filter((client) => {
|
||||||
const client = clientsInScope[0];
|
return new URL(client.url).origin === appUrl;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function playNotificationSound(id: number) {
|
||||||
|
const clients = await getClients();
|
||||||
|
const client = clients[0];
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
if (clientsInScope.length === 0) return;
|
|
||||||
client.postMessage({
|
client.postMessage({
|
||||||
type: 'playNotificationSound',
|
type: 'playNotificationSound',
|
||||||
payload: { id },
|
payload: { id },
|
||||||
@ -191,15 +197,12 @@ export function handleNotificationClick(e: NotificationEvent) {
|
|||||||
e.notification.close(); // Android needs explicit close.
|
e.notification.close(); // Android needs explicit close.
|
||||||
const { data } = e.notification;
|
const { data } = e.notification;
|
||||||
const notifyClients = async () => {
|
const notifyClients = async () => {
|
||||||
const clients = await self.clients.matchAll({ type: 'window' }) as WindowClient[];
|
const clients = await getClients();
|
||||||
const clientsInScope = clients.filter((client) => {
|
await Promise.all(clients.map((client) => {
|
||||||
return new URL(client.url).origin === appUrl;
|
|
||||||
});
|
|
||||||
await Promise.all(clientsInScope.map((client) => {
|
|
||||||
clickBuffer[client.id] = data;
|
clickBuffer[client.id] = data;
|
||||||
return focusChatMessage(client, data);
|
return focusChatMessage(client, data);
|
||||||
}));
|
}));
|
||||||
if (!self.clients.openWindow || clientsInScope.length > 0) return undefined;
|
if (!self.clients.openWindow || clients.length > 0) return undefined;
|
||||||
// Store notification data for default client (fix for android)
|
// Store notification data for default client (fix for android)
|
||||||
clickBuffer[0] = data;
|
clickBuffer[0] = data;
|
||||||
// If there is no opened client we need to open one and wait until it is fully loaded
|
// If there is no opened client we need to open one and wait until it is fully loaded
|
||||||
|
Loading…
x
Reference in New Issue
Block a user