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

feat!: LT code for transmit #2

Merged
merged 31 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
52ccf44
wip: use lt for scanning
antfu Oct 2, 2024
7dd6536
chore: update
antfu Oct 2, 2024
423b11a
feat: it worked
antfu Oct 3, 2024
58b2ddc
feat: improve degree distribution
antfu Oct 3, 2024
dc0a048
fix: fix ui
antfu Oct 3, 2024
4ee1560
feat: improve decode
antfu Oct 3, 2024
1c2923a
feat: optimize decode
antfu Oct 3, 2024
b4618f4
fix: don't wrap info
antfu Oct 3, 2024
59fab97
feat: improve scan perf
antfu Oct 3, 2024
1c11549
feat: add info for scan
antfu Oct 3, 2024
a72cf02
chore: add checksum
antfu Oct 3, 2024
c585719
feat: ui show block indices
LittleSound Oct 3, 2024
bb14ada
fix(ui): meter
nekomeowww Oct 3, 2024
49dc658
style: shorter code width
nekomeowww Oct 3, 2024
63b04c2
feat(ui): no signal error handling
nekomeowww Oct 3, 2024
438df67
fix: NaN issue
nekomeowww Oct 3, 2024
3526a30
Merge branch 'main' into feat/use-lt
antfu Oct 3, 2024
fb1a3ff
refactor: delete unused bandwidth
nekomeowww Oct 3, 2024
ba82d94
feat: inspect ui
LittleSound Oct 3, 2024
dba2305
fix: checksum calculation
antfu Oct 3, 2024
88791a9
feat: collapsable panel
LittleSound Oct 3, 2024
78ff2ff
refactor: lt code api
antfu Oct 3, 2024
0617ec5
feat: a progress bar that is not accurate but feels comfortable.
LittleSound Oct 3, 2024
ab2c012
refactor: correct way to implement timeseries for bytes rate
nekomeowww Oct 3, 2024
273a115
refactor: rename to timeseries
nekomeowww Oct 3, 2024
c281d4a
fix: missing property length, renamed to bytes
nekomeowww Oct 3, 2024
4d44c3a
chore: add failed test
antfu Oct 3, 2024
d496590
chore: lint
antfu Oct 3, 2024
eba7898
refactor
antfu Oct 3, 2024
cb3f710
refactor: split files
antfu Oct 3, 2024
bce74b9
fix: lint
nekomeowww Oct 3, 2024
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
31 changes: 31 additions & 0 deletions app/components/Collapsable.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script lang="ts" setup>
import { watchEffect } from 'vue'

const props = defineProps<{
default?: boolean
label?: string
}>()
const isVisible = defineModel<boolean>({ default: false })
watchEffect(() => {
if (props.default != null) {
isVisible.value = !!props.default
}
})
</script>

<template>
<div flex="~ col" border="~ gray/25 rounded-lg" divide="y dashed gray/25" max-w-150 of-hidden shadow-sm>
<button
flex items-center justify-between px2 py1 text-sm
@click="isVisible = !isVisible"
>
<span>
<slot name="label">
{{ props.label ?? 'Inspect' }}
</slot></span> <span op50>{{ isVisible ? '▲' : '▼' }}</span>
</button>
<div v-if="isVisible">
<slot />
</div>
</div>
</template>
67 changes: 35 additions & 32 deletions app/components/Generate.vue
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
<script lang="ts" setup>
import { encode, renderSVG } from 'uqr'
import type { EncodedBlock } from '~~/utils/lt-codes'
import { blockToBinary, createEncoder } from '~~/utils/lt-codes'
import { fromUint8Array } from 'js-base64'
import { renderSVG } from 'uqr'

const props = withDefaults(defineProps<{
data: string[]
data: Uint8Array
speed: number
}>(), {
speed: 250,
})

const ecc = 'L' as const
const minVersion = computed(() => encode(props.data[0]! || '', { ecc }).version)
const svgList = computed(() => props.data.map(content => renderSVG(content, {
border: 1,
ecc,
minVersion: minVersion.value,
})))
const activeIndex = ref(0)
watch(() => props.data, () => activeIndex.value = 0)
const count = ref(0)
const encoder = createEncoder(props.data, 1000)
const svg = ref<string>()
const block = shallowRef<EncodedBlock>()

let intervalId: any
function initInterval() {
intervalId = setInterval(() => {
activeIndex.value = (activeIndex.value + 1) % svgList.value.length
}, props.speed)
}
watch(() => props.speed, () => {
intervalId && clearInterval(intervalId)
initInterval()
}, { immediate: true })
onUnmounted(() => intervalId && clearInterval(intervalId))
const renderTime = ref(0)
const framePerSecond = computed(() => 1000 / renderTime.value)

onMounted(() => {
let frame = performance.now()

useIntervalFn(() => {
count.value++
const data = encoder.fountain().next().value
block.value = data
const binary = blockToBinary(data)
const str = fromUint8Array(binary)
svg.value = renderSVG(str, { border: 1 })
const now = performance.now()
renderTime.value = now - frame
frame = now
}, () => props.speed)
})
</script>

<template>
<div flex flex-col items-center>
<p mb-4>
{{ activeIndex }}/{{ svgList.length }}
<div flex flex-col items-center pb-20>
<p mb-4 w-full of-x-auto ws-nowrap font-mono>
Indices: {{ block?.indices }}<br>
Total: {{ block?.k }}<br>
Bytes: {{ ((block?.bytes || 0) / 1024).toFixed(2) }} KB<br>
Bitrate: {{ ((block?.bytes || 0) / 1024 * framePerSecond).toFixed(2) }} Kbps<br>
Frame Count: {{ count }}<br>
FPS: {{ framePerSecond.toFixed(2) }}
</p>
<div class="relative h-full w-full">
<div
class="arc aspect-square" absolute inset-0
:style="{ '--deg': `${(activeIndex + 1) * 360 / svgList.length}deg` }"
/>
<div
v-for="svg, idx of svgList"
:key="idx"
:class="{ hidden: idx !== activeIndex }"
class="aspect-square [&>svg]:h-full [&>svg]:w-full"
h-full w-full
v-html="svg"
Expand Down
Loading
Loading