Compare commits

...

2 Commits

Author SHA1 Message Date
Jack Hadrill 8561b9c6c6 Clear wire statistics update interval on unmount
continuous-integration/drone/push Build is passing Details
2021-01-06 04:40:40 +00:00
Jack Hadrill 734e791045 Change wire statistics update interval 2021-01-06 04:40:10 +00:00
2 changed files with 16 additions and 5 deletions

View File

@ -59,6 +59,7 @@ export default {
const toast = useToast() const toast = useToast()
const trackers = inject('trackers') const trackers = inject('trackers')
var webTorrent = null var webTorrent = null
var wireUpdateHandle = null
const player = ref(null) const player = ref(null)
const video = reactive({ const video = reactive({
file: null, file: null,
@ -85,6 +86,9 @@ export default {
if (webTorrent) { if (webTorrent) {
webTorrent.destroy() webTorrent.destroy()
} }
if (wireUpdateHandle) {
clearInterval(wireUpdateHandle)
}
}) })
const onFilesSelected = (f) => { const onFilesSelected = (f) => {
@ -117,14 +121,16 @@ export default {
torrent.on('upload', bytes => { torrent.on('upload', bytes => {
state.uploaded += bytes state.uploaded += bytes
updateWireStatistics()
}) })
torrent.on('wire', wire => { torrent.on('wire', wire => {
updateWireStatistics()
toast.add({ severity: 'info', summary: 'New watcher', detail: 'Someone has joined your screen.', life: 3000 }) toast.add({ severity: 'info', summary: 'New watcher', detail: 'Someone has joined your screen.', life: 3000 })
}) })
wireUpdateHandle = setInterval(() => {
updateWireStatistics()
}, 200)
toast.add({ severity: 'success', summary: 'Video added', detail: `You are now sharing ${video.name}`, life: 5000 }) toast.add({ severity: 'success', summary: 'Video added', detail: `You are now sharing ${video.name}`, life: 5000 })
}) })
} }

View File

@ -65,6 +65,7 @@ export default {
const toast = useToast() const toast = useToast()
const trackers = inject('trackers') const trackers = inject('trackers')
var webTorrent = null var webTorrent = null
var wireUpdateHandle = null
const player = ref(null) const player = ref(null)
const progress = ref() const progress = ref()
const video = reactive({ const video = reactive({
@ -100,12 +101,14 @@ export default {
if (webTorrent) { if (webTorrent) {
webTorrent.destroy() webTorrent.destroy()
} }
if (wireUpdateHandle) {
clearInterval(wireUpdateHandle)
}
}) })
const downloadVideo = (infoHash) => { const downloadVideo = (infoHash) => {
webTorrent.add(infoHash, { announce: trackers }, torrent => { webTorrent.add(infoHash, { announce: trackers }, torrent => {
torrent.on('wire', () => { torrent.on('wire', () => {
updateWireStatistics()
toast.add({ severity: 'info', summary: 'New watcher', detail: 'Someone has joined your screen.', life: 3000 }) toast.add({ severity: 'info', summary: 'New watcher', detail: 'Someone has joined your screen.', life: 3000 })
}) })
@ -114,7 +117,6 @@ export default {
}) })
torrent.on('upload', bytes => { torrent.on('upload', bytes => {
updateWireStatistics()
}) })
torrent.on('download', bytes => { torrent.on('download', bytes => {
@ -124,7 +126,6 @@ export default {
} }
state.downloaded += bytes state.downloaded += bytes
progress.value = state.downloaded / video.size * 100 progress.value = state.downloaded / video.size * 100
updateWireStatistics()
}) })
}) })
} }
@ -148,6 +149,10 @@ export default {
}) })
file.renderTo(player.value) file.renderTo(player.value)
wireUpdateHandle = setInterval(() => {
updateWireStatistics()
}, 200)
} }
const updateWireStatistics = () => { const updateWireStatistics = () => {