Compare commits
2 Commits
develop
...
web-transp
Author | SHA1 | Date |
---|---|---|
![]() |
efd7eac185 | |
![]() |
edf277e9d4 |
|
@ -3,4 +3,7 @@ node_modules
|
|||
|
||||
site_bin
|
||||
.task
|
||||
*_templ.go
|
||||
*_templ.go
|
||||
|
||||
*.crt
|
||||
*.key
|
|
@ -16,6 +16,13 @@ tasks:
|
|||
- go install github.com/a-h/templ/cmd/templ@latest
|
||||
- go install github.com/go-task/task/v3/cmd/task@latest
|
||||
|
||||
localcert:
|
||||
cmds:
|
||||
- sudo apt install ca-certificates
|
||||
- openssl req -x509 -out localhost.crt -keyout localhost.key -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' -extensions EXT -config <( printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
|
||||
- sudo cp localhost.crt /usr/local/share/ca-certificates
|
||||
- sudo update-ca-certificates
|
||||
|
||||
version:
|
||||
cmds:
|
||||
- echo {{.VERSION}}
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
import { AttributeContext, AttributePlugin } from '../types'
|
||||
|
||||
// Sets the value of the element
|
||||
export const WebTransportPlugin: AttributePlugin = {
|
||||
prefix: 'transport',
|
||||
mustHaveEmptyKey: true,
|
||||
mustNotEmptyExpression: true,
|
||||
allowedModifiers: new Set(['throughput', 'latency', 'pooled', 'unreliable']),
|
||||
|
||||
onLoad: (ctx: AttributeContext) => {
|
||||
let wt: WebTransport | null = null
|
||||
|
||||
const fn = async () => {
|
||||
const { expressionFn } = ctx
|
||||
const url = expressionFn(ctx)
|
||||
|
||||
const opts: WebTransportOptions = {
|
||||
congestionControl: 'default',
|
||||
allowPooling: false,
|
||||
requireUnreliable: false,
|
||||
}
|
||||
if (ctx.modifiers.has('pooled')) {
|
||||
opts.allowPooling = true
|
||||
}
|
||||
if (ctx.modifiers.has('unreliable')) {
|
||||
opts.requireUnreliable = true
|
||||
}
|
||||
if (ctx.modifiers.has('throughput')) {
|
||||
opts.congestionControl = 'throughput'
|
||||
}
|
||||
if (ctx.modifiers.has('latency')) {
|
||||
opts.congestionControl = 'low-latency'
|
||||
}
|
||||
|
||||
wt = new WebTransport(url, opts)
|
||||
await wt.ready
|
||||
|
||||
const { readable, writable } = await wt.createBidirectionalStream()
|
||||
const reader = readable.getReader()
|
||||
const writer = writable.getWriter()
|
||||
|
||||
// this needs obvious work to be useful
|
||||
writer.write(new TextEncoder().encode('Hello, World!'))
|
||||
reader.read().then((result) => {
|
||||
console.log('Received:', new TextDecoder().decode(result.value!))
|
||||
})
|
||||
}
|
||||
|
||||
fn()
|
||||
|
||||
return () => {
|
||||
if (wt) {
|
||||
wt.close()
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
Loading…
Reference in New Issue