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

Properly cancel and reset ongoing streams when unmounting #1206

Merged
merged 1 commit into from
Apr 13, 2022
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
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/components/Audios.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import '@skjnldsv/vue-plyr/dist/vue-plyr.css'
import logger from '../services/logger'

Vue.use(VuePlyr)

Expand All @@ -62,6 +63,8 @@ export default {
options() {
return {
autoplay: this.active === true,
// Used to reset the audio streams https://github.com/sampotts/plyr#javascript-1
blankVideo: '/blank.aac',
szaimen marked this conversation as resolved.
Show resolved Hide resolved
controls: ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'settings'],
loadSprite: false,
}
Expand Down Expand Up @@ -92,6 +95,14 @@ export default {
})
},

beforeDestroy() {
// Force stop any ongoing request
logger.debug('Closing audio stream', { filename: this.filename })
this.$refs.audio.pause()
this.player.stop()
this.player.destroy()
},

methods: {
donePlaying() {
this.$refs.audio.autoplay = false
Expand Down
11 changes: 11 additions & 0 deletions src/components/Videos.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import Vue from 'vue'
import VuePlyr from '@skjnldsv/vue-plyr'
import '@skjnldsv/vue-plyr/dist/vue-plyr.css'
import logger from '../services/logger'

const liveExt = ['jpg', 'jpeg', 'png']
const liveExtRegex = new RegExp(`\\.(${liveExt.join('|')})$`, 'i')
Expand Down Expand Up @@ -82,6 +83,8 @@ export default {
options() {
return {
autoplay: this.active === true,
// Used to reset the video streams https://github.com/sampotts/plyr#javascript-1
blankVideo: '/blank.mp4',
controls: ['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'fullscreen'],
loadSprite: false,
}
Expand Down Expand Up @@ -112,6 +115,14 @@ export default {
})
},

beforeDestroy() {
// Force stop any ongoing request
logger.debug('Closing video stream', { filename: this.filename })
this.$refs.video.pause()
this.player.stop()
this.player.destroy()
},

methods: {
// Updates the dimensions of the modal
updateVideoSize() {
Expand Down
2 changes: 1 addition & 1 deletion src/views/Viewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export default {
file(path) {
// we got a valid path! Load file...
if (path.trim() !== '') {
logger.info('Opening viewer for file ', path)
logger.info('Opening viewer for file ', { path })
this.openFile(path)
} else {
// path is empty, we're closing!
Expand Down