Documentation
¶
Overview ¶
Package wtjs implements typed access to the browser javascript WebTransport API.
https://developer.mozilla.org/en-US/docs/Web/API/WebTransport
Index ¶
- func Bytes(v js.Value) []byte
- type BidirectionalStream
- type CertificateHash
- type CloseEvent
- type ReadResult
- type ReadableStream
- type ReadableStreamReader
- type ReceiveStream
- type WebTransport
- func (t WebTransport) Close(closeCode uint32, reason string) (err error)
- func (t WebTransport) Closed() (closed <-chan struct{}, closeEvent func() CloseEvent)
- func (t WebTransport) CreateBidirectionalStream() (created <-chan BidirectionalStream, failed <-chan error)
- func (t WebTransport) CreateUnidirectionalStream() (created <-chan WritableStream, failed <-chan error)
- func (t WebTransport) Datagrams() (ReadableStream, WritableStream)
- func (t WebTransport) IncomingBidirectionalStreams() ReadableStream
- func (t WebTransport) IncomingUnidirectionalStreams() ReadableStream
- func (t WebTransport) Ready() (ready <-chan struct{}, failed <-chan error)
- type WebTransportError
- type WritableStream
- type WritableStreamWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BidirectionalStream ¶
type BidirectionalStream struct {
// contains filtered or unexported fields
}
BidirectionalStream is a wrapper around a javascript WebTransportBidirectionalStream object.
func NewBidirectionalStream ¶
func NewBidirectionalStream(v js.Value) BidirectionalStream
NewBidirectionalStream wraps a javascript WebTransportBidirectionalStream object.
func (BidirectionalStream) Readable ¶
func (s BidirectionalStream) Readable() ReadableStream
Readable returns the readable side of the stream.
func (BidirectionalStream) Writable ¶
func (s BidirectionalStream) Writable() WritableStream
Writable returns the writable side of the stream.
type CertificateHash ¶
type CertificateHash struct {
// Algorithm is the hash algorithm, e.g. "sha-256".
Algorithm string
// Value is the certificate hash.
Value [32]byte
}
CertificateHash is a hash of a server certificate, used to authenticate connections to servers with certificates that are not trusted by the browser.
type CloseEvent ¶
type CloseEvent struct {
// Code is the close code, valid if Err is nil.
Code uint32
// Reason is the close reason, valid if Err is nil.
Reason string
// Err is non-nil if the session closed with an error.
Err error
}
CloseEvent is the type passed when a WebTransport session is closed.
type ReadResult ¶
type ReadResult struct {
// Value is the chunk, a Uint8Array for byte streams.
// Nil if Done or Err is set.
Value js.Value
// Done is true if the stream is finished.
Done bool
// Err is non-nil if the read failed.
Err error
}
ReadResult is the result of a read from a ReadableStreamReader.
type ReadableStream ¶
type ReadableStream struct {
// contains filtered or unexported fields
}
ReadableStream is a wrapper around a javascript ReadableStream object.
func (ReadableStream) GetReader ¶
func (s ReadableStream) GetReader() ReadableStreamReader
GetReader returns a reader for the stream. The stream is locked to the returned reader until it is released.
type ReadableStreamReader ¶
type ReadableStreamReader struct {
// contains filtered or unexported fields
}
ReadableStreamReader is a wrapper around a javascript ReadableStreamDefaultReader object.
func (ReadableStreamReader) Cancel ¶
func (r ReadableStreamReader) Cancel(errorCode uint32) (err error)
Cancel cancels the stream with the given error code.
func (ReadableStreamReader) Read ¶
func (r ReadableStreamReader) Read() (ch <-chan ReadResult, err error)
Read reads the next chunk from the stream. The returned channel receives exactly one ReadResult.
type ReceiveStream ¶
type ReceiveStream struct {
// contains filtered or unexported fields
}
ReceiveStream is a wrapper around a javascript WebTransportReceiveStream object.
func NewReceiveStream ¶
func NewReceiveStream(v js.Value) ReceiveStream
NewReceiveStream wraps a javascript WebTransportReceiveStream object.
func (ReceiveStream) Readable ¶
func (s ReceiveStream) Readable() ReadableStream
Readable returns the readable side of the stream.
type WebTransport ¶
type WebTransport struct {
// contains filtered or unexported fields
}
WebTransport is a wrapper around a javascript WebTransport object.
func New ¶
func New(url string, serverCertificateHashes []CertificateHash) (t WebTransport, err error)
New creates a new WebTransport. The connection is established asynchronously: wait on Ready for the connection to be established, or on Closed for it to fail.
func (WebTransport) Close ¶
func (t WebTransport) Close(closeCode uint32, reason string) (err error)
Close closes the session with the given close code and reason.
func (WebTransport) Closed ¶
func (t WebTransport) Closed() (closed <-chan struct{}, closeEvent func() CloseEvent)
Closed registers handlers on transport.closed. The first channel is closed once the session is closed; closeEvent then returns the close event.
func (WebTransport) CreateBidirectionalStream ¶
func (t WebTransport) CreateBidirectionalStream() (created <-chan BidirectionalStream, failed <-chan error)
CreateBidirectionalStream creates a new bidirectional stream. The first channel receives the stream once it is created, or the second channel receives the error if creation fails.
func (WebTransport) CreateUnidirectionalStream ¶
func (t WebTransport) CreateUnidirectionalStream() (created <-chan WritableStream, failed <-chan error)
CreateUnidirectionalStream creates a new unidirectional stream. The first channel receives the stream once it is created, or the second channel receives the error if creation fails.
func (WebTransport) Datagrams ¶
func (t WebTransport) Datagrams() (ReadableStream, WritableStream)
Datagrams returns the readable and writable sides of the datagram stream.
func (WebTransport) IncomingBidirectionalStreams ¶
func (t WebTransport) IncomingBidirectionalStreams() ReadableStream
IncomingBidirectionalStreams returns the stream of bidirectional streams opened by the remote peer.
func (WebTransport) IncomingUnidirectionalStreams ¶
func (t WebTransport) IncomingUnidirectionalStreams() ReadableStream
IncomingUnidirectionalStreams returns the stream of unidirectional streams opened by the remote peer.
func (WebTransport) Ready ¶
func (t WebTransport) Ready() (ready <-chan struct{}, failed <-chan error)
Ready waits for the connection to be established. The first channel is closed once the connection is established. If the connection fails, the second channel receives the error.
type WebTransportError ¶
type WebTransportError struct {
// Code is the error code of the session.
Code uint32
// Message is the error message.
Message string
}
WebTransportError is a javascript WebTransportError.
func (*WebTransportError) Error ¶
func (e *WebTransportError) Error() string
type WritableStream ¶
type WritableStream struct {
// contains filtered or unexported fields
}
WritableStream is a wrapper around a javascript WritableStream object.
func (WritableStream) GetWriter ¶
func (s WritableStream) GetWriter() WritableStreamWriter
GetWriter returns a writer for the stream. The stream is locked to the returned writer until it is released.
type WritableStreamWriter ¶
type WritableStreamWriter struct {
// contains filtered or unexported fields
}
WritableStreamWriter is a wrapper around a javascript WritableStreamDefaultWriter object.
func (WritableStreamWriter) Abort ¶
func (w WritableStreamWriter) Abort(errorCode uint32) (err error)
Abort aborts the stream with the given error code.
func (WritableStreamWriter) Close ¶
func (w WritableStreamWriter) Close() (ch <-chan error, err error)
Close closes the stream, waiting for pending writes to complete. The returned channel receives nil once the stream is closed, or the error if closing fails.