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

Add supports custom shortcuts #169

Merged
merged 1 commit into from
Dec 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ poster: https://home-assistant.io/images/cast/splash.png # still image when str
intersection: 0.75 # auto pause stream when less than 75% of video element is in the screen, 50% by default
muted: false # disable sound, default true
ui: true # custom video controls, default false
shortcuts: # custom shortcuts, default none
- name: Record
icon: mdi:record-circle-outline
service: switch.toggle
service_data:
entity_id: switch.camera_record

background: true # run stream when not displayed (ex. for quick video loading), default false

ptz: # check full examples in wiki
Expand Down
36 changes: 36 additions & 0 deletions custom_components/webrtc/www/webrtc-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,31 @@ class WebRTCCamera extends HTMLElement {
spinner.style.display = 'none';
this.setPTZVisibility(true);
};

if (this.config.shortcuts && this.config.shortcuts.length > 0) {
this.renderShortcuts(card, this.config.shortcuts);
}
}

renderShortcuts(card, elements) {
const shortcuts = document.createElement('div');
shortcuts.className = 'shortcuts';

for (var i = 0; i < elements.length; i++) {
const element = elements[i];

const shortcut = document.createElement('ha-icon');
shortcut.className = 'shortcut shortcut-' + i;
shortcut.setAttribute('title', element.name);
shortcut.icon = element.icon;
shortcut.onclick = () => {
const [domain, name] = element.service.split('.');
this.hass.callService(domain, name, element.service_data || {});
};
shortcuts.appendChild(shortcut);
}

card.appendChild(shortcuts);
}

renderPTZ(card, hass) {
Expand Down Expand Up @@ -526,6 +551,17 @@ class WebRTCCamera extends HTMLElement {
cursor: default;
opacity: 0.4;
}
.shortcuts {
position: absolute;
top: 12px;
left: 0px;
}
.shortcuts > .shortcut {
margin-left: 12px;
position: relative;
display: inline-block;
opacity: .9;
}
`;
this.appendChild(style);

Expand Down