From 17db535839e8a7b4b60fd025b647e0b540e1bd59 Mon Sep 17 00:00:00 2001 From: Chris McCord Date: Mon, 8 Nov 2021 14:32:40 -0500 Subject: [PATCH] Move audio enabling entirely to client --- assets/js/app.js | 9 +++++---- lib/live_beats_web/live/live_helpers.ex | 7 ++++++- lib/live_beats_web/live/player_live.ex | 25 +++++++++---------------- 3 files changed, 20 insertions(+), 21 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index 2185384..88df096 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -5,6 +5,10 @@ import topbar from "../vendor/topbar" let nowSeconds = () => Math.round(Date.now() / 1000) +let execJS = (selector, attr) => { + document.querySelectorAll(selector).forEach(el => liveSocket.execJS(el, el.getAttribute(attr))) +} + let Hooks = {} Hooks.Progress = { @@ -60,10 +64,7 @@ Hooks.AudioPlayer = { this.player.play().then(() => { if(sync){ this.player.currentTime = nowSeconds() - this.playbackBeganAt } this.progressTimer = setInterval(() => this.updateProgress(), 100) - this.pushEvent("audio-accepted", {}) - }, error => { - this.pushEvent("audio-rejected", {}) - }) + }, error => execJS("#enable-audio", "data-js-show")) }, pause(){ diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex index 375fcdf..115a2a8 100644 --- a/lib/live_beats_web/live/live_helpers.ex +++ b/lib/live_beats_web/live/live_helpers.ex @@ -151,9 +151,10 @@ defmodule LiveBeatsWeb.LiveHelpers do |> assign_new(:title, fn -> [] end) |> assign_new(:confirm, fn -> [] end) |> assign_new(:cancel, fn -> [] end) + |> assign_rest(~w(id show patch_to redirect_to on_cancel on_confirm title confirm cancel)a) ~H""" -