From d6e3492c339646d30f1b8473b7e772d6b9180156 Mon Sep 17 00:00:00 2001 From: Callum Ellis Date: Wed, 13 Mar 2024 23:08:04 +0000 Subject: [PATCH] Added tap_action support --- custom_components/webrtc/www/webrtc-camera.js | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/custom_components/webrtc/www/webrtc-camera.js b/custom_components/webrtc/www/webrtc-camera.js index c751ec9..2cf8e6b 100644 --- a/custom_components/webrtc/www/webrtc-camera.js +++ b/custom_components/webrtc/www/webrtc-camera.js @@ -260,10 +260,34 @@ class WebRTCCamera extends VideoRTC { const mode = this.querySelector('.mode'); mode.addEventListener('click', () => this.nextStream(true)); + const player = this.querySelector('.player'); + + // Tap action + player.addEventListener('click', e => { + if (this.config.tap_action && this.config.tap_action.action) { + this.handleAction("tap", this.config); + e.preventDefault(); + } + }); + if (this.config.muted) this.video.muted = true; if (this.config.poster_remote) this.video.poster = this.config.poster; } + handleAction(action, config) { + const event = new Event("hass-action", { + bubbles: true, + composed: true, + }); + + event.detail = { + config: config, + action: action + } + + this.dispatchEvent(event); + } + renderDigitalPTZ() { if (this.config.digital_ptz === false) return; new DigitalPTZ(