Fix statistics update method
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
02f789f90d
commit
2a63fe02ad
|
@ -4,13 +4,9 @@
|
||||||
Wire statistics
|
Wire statistics
|
||||||
</template>
|
</template>
|
||||||
<template #content>
|
<template #content>
|
||||||
<DataTable :value="wireStatistics" sortField="peerId" :autoLayout="true">
|
<DataTable :value="wireStatistics" :sortField="sortField" :sortOrder="sortOrder" :autoLayout="true">
|
||||||
<Column field="peerId" header="Wire ID"></Column>
|
<Column field="id" header="Wire ID" :sortable="true" />
|
||||||
<Column field="remoteAddress" header="Remote address"></Column>
|
<Column v-for="(column, index) of columns" :field="column.field" :header="column.header" :key="column.field + '_' + index" :sortable="true" />
|
||||||
<Column field="uploadSpeed" header="Upload speed"></Column>
|
|
||||||
<Column field="uploaded" header="Uploaded"></Column>
|
|
||||||
<Column field="downloadSpeed" header="Download speed"></Column>
|
|
||||||
<Column field="downloaded" header="Downloaded"></Column>
|
|
||||||
</DataTable>
|
</DataTable>
|
||||||
</template>
|
</template>
|
||||||
</Card>
|
</Card>
|
||||||
|
@ -22,6 +18,26 @@ export default {
|
||||||
wireStatistics: {
|
wireStatistics: {
|
||||||
type: Object,
|
type: Object,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
sortField: {
|
||||||
|
type: String,
|
||||||
|
default: 'id'
|
||||||
|
},
|
||||||
|
sortOrder: {
|
||||||
|
type: Number,
|
||||||
|
default: -1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setup () {
|
||||||
|
const columns = [
|
||||||
|
{ field: 'remoteAddress', header: 'Remote address' },
|
||||||
|
{ field: 'uploadSpeed', header: 'Upload speed' },
|
||||||
|
{ field: 'uploaded', header: 'Uploaded' },
|
||||||
|
{ field: 'downloadSpeed', header: 'Download speed' },
|
||||||
|
{ field: 'downloaded', header: 'Downloaded' }
|
||||||
|
]
|
||||||
|
return {
|
||||||
|
columns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
import sha1 from 'sha-1'
|
|
||||||
import prettyBytes from 'pretty-bytes'
|
import prettyBytes from 'pretty-bytes'
|
||||||
|
import sha1 from 'sha-1'
|
||||||
|
|
||||||
const generateWireStatistics = (wires) => {
|
const updateWireStatistics = (wires, wireStatistics) => {
|
||||||
return wires.map(wire => ({
|
wires.forEach(wire => {
|
||||||
peerId: sha1(wire.peerId).toString().substring(0, 5),
|
if (!wireStatistics.some(w => w.wire === wire)) {
|
||||||
remoteAddress: wire.remoteAddress,
|
wireStatistics.push({
|
||||||
uploadSpeed: prettyBytes(wire.uploadSpeed()) + 'ps',
|
id: sha1(wire.peerId).toString().substring(0, 5),
|
||||||
uploaded: prettyBytes(wire.uploaded),
|
remoteAddress: wire.remoteAddress,
|
||||||
downloadSpeed: prettyBytes(wire.downloadSpeed()) + 'ps',
|
wire: wire
|
||||||
downloaded: prettyBytes(wire.downloaded)
|
})
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
|
wireStatistics.forEach(wireStatistic => {
|
||||||
|
var wire = wireStatistic.wire
|
||||||
|
wireStatistic.uploaded = prettyBytes(wire.uploaded)
|
||||||
|
wireStatistic.downloaded = prettyBytes(wire.downloaded)
|
||||||
|
wireStatistic.uploadSpeed = prettyBytes(wire.uploadSpeed()) + 'ps'
|
||||||
|
wireStatistic.downloadSpeed = prettyBytes(wire.downloadSpeed()) + 'ps'
|
||||||
|
})
|
||||||
|
window.w = wireStatistics
|
||||||
}
|
}
|
||||||
|
|
||||||
export default generateWireStatistics
|
export default updateWireStatistics
|
||||||
|
|
|
@ -42,7 +42,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Card>
|
</Card>
|
||||||
<WireStatistics :wireStatistics="wireStatistics"/>
|
<WireStatistics :wireStatistics="wireStatistics" sortField="uploaded" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ import { useToast } from 'primevue/usetoast'
|
||||||
import prettyBytes from 'pretty-bytes'
|
import prettyBytes from 'pretty-bytes'
|
||||||
import prettyMilliseconds from 'pretty-ms'
|
import prettyMilliseconds from 'pretty-ms'
|
||||||
import WebTorrent from 'webtorrent/webtorrent.min.js'
|
import WebTorrent from 'webtorrent/webtorrent.min.js'
|
||||||
import generateWireStatistics from '@/helpers/wire-statistics'
|
import updateWireStatistics from '@/helpers/wire-statistics'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup () {
|
setup () {
|
||||||
|
@ -129,18 +129,15 @@ export default {
|
||||||
})
|
})
|
||||||
|
|
||||||
wireUpdateHandle = setInterval(() => {
|
wireUpdateHandle = setInterval(() => {
|
||||||
updateWireStatistics()
|
updateWireStatistics(state.wires, wireStatistics)
|
||||||
}, 200)
|
window.w = wireStatistics
|
||||||
|
wireStatistics.set()
|
||||||
|
}, 250)
|
||||||
|
|
||||||
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 })
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateWireStatistics = () => {
|
|
||||||
var newWireStatistics = generateWireStatistics(state.wires)
|
|
||||||
wireStatistics.splice.apply(wireStatistics, [0, newWireStatistics.length].concat(newWireStatistics))
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
onFilesSelected,
|
onFilesSelected,
|
||||||
player,
|
player,
|
||||||
|
@ -151,9 +148,3 @@ export default {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
#infoHash {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</Card>
|
</Card>
|
||||||
<WireStatistics :wireStatistics="wireStatistics"/>
|
<WireStatistics :wireStatistics="wireStatistics" sortField="downloaded" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ import { useToast } from 'primevue/usetoast'
|
||||||
import prettyBytes from 'pretty-bytes'
|
import prettyBytes from 'pretty-bytes'
|
||||||
import prettyMilliseconds from 'pretty-ms'
|
import prettyMilliseconds from 'pretty-ms'
|
||||||
import WebTorrent from 'webtorrent/webtorrent.min.js'
|
import WebTorrent from 'webtorrent/webtorrent.min.js'
|
||||||
import generateWireStatistics from '@/helpers/wire-statistics'
|
import updateWireStatistics from '@/helpers/wire-statistics'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
|
@ -152,13 +152,9 @@ export default {
|
||||||
file.renderTo(player.value)
|
file.renderTo(player.value)
|
||||||
|
|
||||||
wireUpdateHandle = setInterval(() => {
|
wireUpdateHandle = setInterval(() => {
|
||||||
updateWireStatistics()
|
window.w = wireStatistics
|
||||||
}, 200)
|
updateWireStatistics(state.wires, wireStatistics)
|
||||||
}
|
}, 250)
|
||||||
|
|
||||||
const updateWireStatistics = () => {
|
|
||||||
var newWireStatistics = generateWireStatistics(state.wires)
|
|
||||||
wireStatistics.splice.apply(wireStatistics, [0, newWireStatistics.length].concat(newWireStatistics))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue