Merge remote-tracking branch 'origin/main' into quiche

This commit is contained in:
Luke Curley 2023-04-13 13:36:51 -07:00
commit 3f5bc39ffc
6 changed files with 28 additions and 23 deletions

View File

@ -17,4 +17,4 @@ go run filippo.io/mkcert -ecdsa -install
go run filippo.io/mkcert -ecdsa -days 10 -cert-file "$CRT" -key-file "$KEY" localhost 127.0.0.1 ::1 go run filippo.io/mkcert -ecdsa -days 10 -cert-file "$CRT" -key-file "$KEY" localhost 127.0.0.1 ::1
# Compute the sha256 fingerprint of the certificate for WebTransport # Compute the sha256 fingerprint of the certificate for WebTransport
openssl x509 -in "$CRT" -outform der | openssl dgst -sha256 > ../player/src/transport/fingerprint.hex openssl x509 -in "$CRT" -outform der | openssl dgst -sha256 > ../player/fingerprint.hex

1
player/.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules node_modules
.parcel-cache .parcel-cache
dist dist
fingerprint.hex

View File

@ -1,5 +1,14 @@
import Player from "./player" import Player from "./player"
// @ts-ignore embed the certificate fingerprint using bundler
import fingerprintHex from 'bundle-text:../fingerprint.hex';
// Convert the hex to binary.
let fingerprint = [];
for (let c = 0; c < fingerprintHex.length-1; c += 2) {
fingerprint.push(parseInt(fingerprintHex.substring(c, c+2), 16));
}
const params = new URLSearchParams(window.location.search) const params = new URLSearchParams(window.location.search)
const url = params.get("url") || "https://localhost:4443/watch" const url = params.get("url") || "https://localhost:4443/watch"
@ -7,6 +16,10 @@ const canvas = document.querySelector<HTMLCanvasElement>("canvas#video")!
const player = new Player({ const player = new Player({
url: url, url: url,
fingerprint: { // TODO remove when Chrome accepts the system CA
"algorithm": "sha-256",
"value": new Uint8Array(fingerprint),
},
canvas: canvas, canvas: canvas,
}) })

View File

@ -4,6 +4,7 @@ import Video from "../video"
export interface PlayerInit { export interface PlayerInit {
url: string; url: string;
fingerprint?: WebTransportHash; // the certificate fingerprint, temporarily needed for local development
canvas: HTMLCanvasElement; canvas: HTMLCanvasElement;
} }
@ -20,6 +21,8 @@ export default class Player {
this.transport = new Transport({ this.transport = new Transport({
url: props.url, url: props.url,
fingerprint: props.fingerprint,
audio: this.audio, audio: this.audio,
video: this.video, video: this.video,
}) })
@ -29,10 +32,6 @@ export default class Player {
this.transport.close() this.transport.close()
} }
async connect(url: string) {
await this.transport.connect(url)
}
play() { play() {
this.audio.play({}) this.audio.play({})
//this.video.play() //this.video.play()

View File

@ -1 +0,0 @@
fingerprint.hex

View File

@ -5,11 +5,10 @@ import * as MP4 from "../mp4"
import Audio from "../audio" import Audio from "../audio"
import Video from "../video" import Video from "../video"
// @ts-ignore bundler embeds data
import fingerprint from 'bundle-text:./fingerprint.hex';
export interface TransportInit { export interface TransportInit {
url: string; url: string;
fingerprint?: WebTransportHash; // the certificate fingerprint, temporarily needed for local development
audio: Audio; audio: Audio;
video: Video; video: Video;
} }
@ -28,7 +27,7 @@ export default class Transport {
this.audio = props.audio; this.audio = props.audio;
this.video = props.video; this.video = props.video;
this.quic = this.connect(props.url) this.quic = this.connect(props)
// Create a unidirectional stream for all of our messages // Create a unidirectional stream for all of our messages
this.api = this.quic.then((q) => { this.api = this.quic.then((q) => {
@ -43,22 +42,16 @@ export default class Transport {
(await this.quic).close() (await this.quic).close()
} }
async connect(url: string): Promise<WebTransport> { // Helper function to make creating a promise easier
// Convert the hex to binary. private async connect(props: TransportInit): Promise<WebTransport> {
let hash = [];
for (let c = 0; c < fingerprint.length-1; c += 2) { let options: WebTransportOptions = {};
hash.push(parseInt(fingerprint.substring(c, c+2), 16)); if (props.fingerprint) {
options.serverCertificateHashes = [ props.fingerprint ]
} }
const quic = new WebTransport(url, { const quic = new WebTransport(props.url, options)
"serverCertificateHashes": [{
"algorithm": "sha-256",
"value": new Uint8Array(hash),
}]
})
await quic.ready await quic.ready
return quic return quic
} }