Compare commits

...

2 Commits

Author SHA1 Message Date
Delaney Gillilan efd7eac185 fix local cert updates 2024-06-10 16:32:10 -07:00
Delaney Gillilan edf277e9d4 initial commit 2024-06-10 16:12:31 -07:00
3 changed files with 68 additions and 1 deletions

5
.gitignore vendored
View File

@ -3,4 +3,7 @@ node_modules
site_bin
.task
*_templ.go
*_templ.go
*.crt
*.key

View File

@ -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}}

View File

@ -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()
}
}
},
}