Skip to content

Commit

Permalink
Update JS deps
Browse files Browse the repository at this point in the history
  • Loading branch information
golles committed Apr 19, 2024
1 parent be50e80 commit 3f09ba9
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions www/webrtc-camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,21 @@ class WebRTCCamera extends VideoRTC {
}

saveScreenshot() {
const canvas = document.createElement('canvas');
canvas.width = this.video.videoWidth;
canvas.height = this.video.videoHeight;
canvas.getContext('2d').drawImage(this.video, 0, 0, canvas.width, canvas.height);
const a = document.createElement('a');

if (this.video.videoWidth && this.video.videoHeight) {
const canvas = document.createElement('canvas');
canvas.width = this.video.videoWidth;
canvas.height = this.video.videoHeight;
canvas.getContext('2d').drawImage(this.video, 0, 0, canvas.width, canvas.height);
a.href = canvas.toDataURL('image/jpeg');
} else if (this.video.poster && this.video.poster.startsWith('data:image/jpeg')) {
a.href = this.video.poster;
} else {
return;
}

const ts = new Date().toISOString().substring(0, 19).replaceAll('-', '').replaceAll(':', '');
const a = document.createElement('a');
a.href = canvas.toDataURL('image/jpeg');
a.download = `snapshot_${ts}.jpeg`;
a.click();
}
Expand Down Expand Up @@ -605,16 +612,16 @@ class WebRTCCamera extends VideoRTC {
const shortcuts = this.querySelector('.shortcuts');
shortcuts.addEventListener('click', ev => {
const value = services[ev.target.dataset.index];
if(value.more_info !== undefined) {
if (value.more_info !== undefined) {
const event = new Event('hass-more-info', {
bubbles: true,
cancelable: true,
composed: true,
});
event.detail = { entityId: value.more_info };
event.detail = {entityId: value.more_info};
ev.target.dispatchEvent(event);
}
if(value.service !== undefined) {
if (value.service !== undefined) {
const [domain, name] = value.service.split('.');
this.hass.callService(domain, name, value.service_data || {});
}
Expand Down

0 comments on commit 3f09ba9

Please sign in to comment.