Skip to content

Commit

Permalink
Silly workaround for apple devices
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasloven committed Jun 27, 2019
1 parent 3f133e4 commit acccacd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ The `media_player` entity also has some extra attributes presenting the current
| `userAgent` | The User Agent of the associated browser. |
| `currentUser` | The user currently logged in on the *device*. |

**NOTE: Because apple is apple; on iOS you need to touch the screen once after loading the frontend before any playback will work.**

## `browser_mod.command` service

Call the `browser_mod.command` service to control your *device* in various ways.
Expand Down
6 changes: 3 additions & 3 deletions custom_components/browser_mod/browser_mod.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ class BrowserMod {
document.querySelector("home-assistant").hassChanged(hass, hass);
}

playOnce(ev) {
if(window.browser_mod.playedOnce) return;
window.browser_mod.player.play();
window.browser_mod.playedOnce = true;
}

constructor() {
window.hassConnection.then((conn) => this.connect(conn.conn));
this.player = new Audio();
this.playedOnce = false;

const updater = this.update.bind(this);
this.player.addEventListener("ended", updater);
Expand All @@ -39,6 +46,7 @@ class BrowserMod {
this.player.addEventListener("volumechange", updater);
document.addEventListener("visibilitychange", updater);
window.addEventListener("location-changed", updater);
window.addEventListener("click", this.playOnce);
provideHass(this);
}

Expand Down

0 comments on commit acccacd

Please sign in to comment.