Skip to content

Commit

Permalink
fixed js streaming
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked committed Jul 16, 2019
1 parent 2bad978 commit 0636114
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions www/aarlo-glance.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ class AarloGlance extends LitElement {
}
}

constructor() {
super();
this._img = null;
this._stream = null;
this._video = null;
}

static get outerStyleTemplate() {
return html`
<style>
Expand Down Expand Up @@ -473,24 +480,28 @@ class AarloGlance extends LitElement {
`;
}

_didRender(_props, _changedProps, _prevProps) {
if ( this._stream ) {
var video = this.shadowRoot.getElementById( 'stream-' + this._cameraId )
if ( Hls.isSupported() ) {
this._hls = new Hls();
this._hls.loadSource( this._stream )
this._hls.attachMedia(video);
this._hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
else if ( video.canPlayType('application/vnd.apple.mpegurl') ) {
video.src = this._stream
video.addEventListener('loadedmetadata',function() {
video.play();
});
}
}
updated(changedProperties) {
changedProperties.forEach( (oldValue, propName) => {
if ( propName == '_stream' && oldValue == null ) {
if ( this._stream ) {
var video = this.shadowRoot.getElementById( 'stream-' + this._cameraId )
if ( Hls.isSupported() ) {
this._hls = new Hls();
this._hls.loadSource( this._stream )
this._hls.attachMedia(video);
this._hls.on(Hls.Events.MANIFEST_PARSED,function() {
video.play();
});
}
else if ( video.canPlayType('application/vnd.apple.mpegurl') ) {
video.src = this._stream
video.addEventListener('loadedmetadata',function() {
video.play();
});
}
}
}
});
}

set hass( hass ) {
Expand Down

0 comments on commit 0636114

Please sign in to comment.