H
H
Hazrat Hajikerimov2019-12-16 16:18:58
JavaScript
Hazrat Hajikerimov, 2019-12-16 16:18:58

Problems with audio playback and websocket messages?

Greetings, I have encountered difficulties in optimizing Google Chrome, namely, if you switch from the application tab to another tab and stay there for a while, then playing sound on a websocket message does not work.
According to Google, there are generally 2 troubles:
1) Chrome, starting from version 57, began to actively suppress ...
2) Exactly a year ago (December 2018) Google Chrome updated the rules for playing sounds
Based on this, I implemented the following in my application:
1) Our message is also duplicated in the firebase for notifications, respectively, I hung up the handler in the service workers and with new push notifications I send a message to the application via postMessage to play sound, this method was advised in the article on Habré, but it also does not work if you switch to another tab for a while
2) Sometimes I noticed that postMessage successfully sent data about the new notification to the handler in the tab, but there is an error caught by try catch and with a link to https: //developers.google.com/web/updates/2017/09/...
3) I found a hack on stackoverflow, if you add an audio file and loop it, then Chrome will not suppress its work in the background, I don’t know how much yet the solution is relevant, it resembles the situation with iOS of older versions, when the same method was used, as noted in the comment to the article on Habré
. This is where the question comes from, why does this work on VKontakte (notifications of new messages), how to implement it, who faced it? plz share your solution

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lev Zabudkin, 2020-01-16
@zabudkin

Damn, just keep the activity in the tab and no chrome, firefox, opera and others will ignore the tab in any way.
On SetTimeOut, perform actions, as all social networks and radio online and YouTube do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question