Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes WebAudio sink not playing on Safari #1765

Merged
merged 4 commits into from
Mar 8, 2023

Conversation

digitaldan
Copy link
Contributor

@digitaldan digitaldan commented Mar 5, 2023

Fixes #1717.

Safari (and Chrome possibly as well) requires a user interaction after a web audio stream has been requested, which means audio will not play until at least one stream has been started and then the user clicks somewhere in the web app.
This implements a workaround (https://www.mattmontag.com/web/unlock-web-audio-in-safari-for-ios-and-macos) which unlocks and stores the AudioContext globally, so that after the first stream only a single interaction is required for the lifetime of that browser session.

…ires a user interaction after a web audio stream has been requested.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
@digitaldan digitaldan requested a review from a team as a code owner March 5, 2023 18:25
@digitaldan
Copy link
Contributor Author

This is my quick and dirty workaround for Safari being difficult.

Copy link
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much!!

I have tested this, works fine with openHAB's barking.mp3.
Does not work with the doorbell.mp3, my BrowserStack iOS debugger (thx @ghys) says Unhandled Promise Rejection: EncodingError: Decoding failed, but this is related to the encoding and we can't help there.

@digitaldan Is this ready for merging? It still has WIP.

@relativeci
Copy link

relativeci bot commented Mar 7, 2023

Job #851: Bundle Size — 16.25MiB (~+0.01%).

c83403e(current) vs 947418b main#850(baseline)

⚠️ Bundle contains 16 duplicate packages

Metrics (2 changes)
                 Current
Job #851
     Baseline
Job #850
Initial JS 1.86MiB(~-0.01%) 1.86MiB
Initial CSS 608.62KiB 608.62KiB
Cache Invalidation 90.64% 0%
Chunks 218 218
Assets 688 688
Modules 1706 1706
Duplicate Modules 82 82
Duplicate Code 1.72% 1.72%
Packages 138 138
Duplicate Packages 15 15
Total size by type (2 changes)
                 Current
Job #851
     Baseline
Job #850
CSS 857.89KiB 857.89KiB
Fonts 1.08MiB 1.08MiB
HTML 1.23KiB 1.23KiB
IMG 140.74KiB 140.74KiB
JS 9.2MiB (~-0.01%) 9.2MiB
Media 295.6KiB 295.6KiB
Other 4.71MiB (~+0.01%) 4.71MiB

View job #851 reportView main branch activity

@florian-h05 florian-h05 added bug Something isn't working main ui Main UI labels Mar 7, 2023
@florian-h05 florian-h05 added this to the 4.0 milestone Mar 7, 2023
@florian-h05 florian-h05 changed the title [mainui][WIP] Attempts a workaround to #1717 [mainui][WIP] Fixes WebAudio sink not playing on Safari Mar 7, 2023
@florian-h05 florian-h05 changed the title [mainui][WIP] Fixes WebAudio sink not playing on Safari [WIP] Fixes WebAudio sink not playing on Safari Mar 7, 2023
@digitaldan
Copy link
Contributor Author

Let me clean it up a bit, i believe there are some formatting violations, plus i want to make the variable naming more consistent. I kinda just threw it together to be honest ;-)

@florian-h05
Copy link
Contributor

I have fixed the linting errors, so you need to update before cleaning up.

@wborn
Copy link
Member

wborn commented Mar 7, 2023

When it's fixed and works, it would also be nice when the same changes are applied (in additional PRs) to HABPanel and Basic UI. Those UIs use very similar code for handling webaudio. 🙂

@florian-h05 florian-h05 added rebuild trigger a new Jenkins job and removed rebuild trigger a new Jenkins job labels Mar 8, 2023
@florian-h05
Copy link
Contributor

@digitaldan
How does the clean-up go? Can you please rebase if you work on this, I think Jenkins fails due to some core changes and this outdated branch.

@digitaldan
Copy link
Contributor Author

Unfortunately i'm having some trouble getting this working now on safari, i'll play a little more this afternoon.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
@digitaldan
Copy link
Contributor Author

Ok, all cleaned up. My Safari issues were my own (helps to point Safari at your dev server when testing). I'll look at updating the other UI's in separate PR.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
Copy link
Contributor

@florian-h05 florian-h05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much!
Works fine on my iPad.

@florian-h05 florian-h05 changed the title [WIP] Fixes WebAudio sink not playing on Safari Fixes WebAudio sink not playing on Safari Mar 8, 2023
@florian-h05 florian-h05 merged commit b90cbc4 into openhab:main Mar 8, 2023
florian-h05 pushed a commit that referenced this pull request Apr 6, 2023
Fixes #1717.

Safari (and Chrome possibly as well) requires a user interaction after a
web audio stream has been requested, which means audio will not play
until at least one stream has been started and then the user clicks
somewhere in the web app.
This implements a workaround
(https://www.mattmontag.com/web/unlock-web-audio-in-safari-for-ios-and-macos)
which unlocks and stores the AudioContext globally, so that after the
first stream only a single interaction is required for the lifetime of
that browser session.

Signed-off-by: Dan Cunningham <dan@digitaldan.com>
(cherry picked from commit b90cbc4)
@kaikreuzer kaikreuzer added the patch A PR that has been cherry-picked to a patch release branch label Apr 12, 2023
@kaikreuzer
Copy link
Member

@florian-h05 When cherry-picking commits to the patch release branches, please remember to add the "patch" label to the PR, because otherwise the fix is not picked up by the release notes script. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working main ui Main UI patch A PR that has been cherry-picked to a patch release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web Audio Sink on iOS devices not working
4 participants