Skip to content

Client

moqt.Dialer manages client-side operations for the MoQ protocol. It establishes sessions with MOQ servers over both WebTransport and native QUIC connections.

Overview
func main() {
    // Create a new dialer
	dialer := moqt.Dialer{
		TLSConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	}

	// Dial and establish a session with the server
	sess, err := dialer.Dial(context.Background(), "https://[addr]:[port]/[path]", nil)
	if err != nil {
		log.Fatalf("Failed to dial: %v", err)
	}
	defer sess.CloseWithError(moqt.NoError, "done")

	// Use the session (e.g., subscribe to tracks, receive announcements)
}

Initialize a Dialer

There is no dedicated function (such as a constructor) for initializing a dialer. Users define the struct directly and assign values to its fields as needed.

    dialer := moqt.Dialer{
		// Set dialer options here
	}

Configuration

The following table describes the public fields of the moqt.Dialer struct:

FieldTypeDescription
TLSConfig*tls.ConfigTLS configuration for secure connections
QUICConfig*quic.ConfigQUIC configuration for raw QUIC connections
Config*moqt.ConfigMOQ protocol configuration
DialQUICFuncfunc(ctx, addr, tlsConfig, quicConfig) (StreamConn, error)Custom QUIC dial function. If nil, the default dialer is used.
DialWebTransportFuncfunc(ctx, addr, header, tlsConfig) (*http.Response, WebTransportSession, error)Custom WebTransport dial function. If nil, the default dialer is used.
FetchHandlermoqt.FetchHandlerHandles incoming fetch requests on WebTransport sessions. If nil, fetch requests are not handled.
OnGoawayfunc(newSessionURI string)Called when the server requests session migration. The newSessionURI parameter contains the redirect URI, which may be empty.
Logger*slog.LoggerLogger for connection and session events. If nil, logging is disabled.

quic-go/quic-go is used internally as the default QUIC implementation when relevant fields which is set for customization are not set or nil.

quic-go/quic-go
Loading...
- -

quic-go/webtransport-go is used internally as the default WebTransport implementation when relevant fields which is set for customization are not set or nil.

quic-go/webtransport-go
Loading...
- -

Dial and Establish Session

A Dialer can connect to servers using the Dial method, which automatically selects the transport based on the URL scheme:

  • https:// — WebTransport (HTTP/3)
  • moqt:// — Native QUIC
	var mux *moqt.TrackMux
	sess, err := dialer.Dial(ctx, "https://[addr]:[port]/[path]", mux)
	if err != nil {
		// Handle error
		return
	}

	// Handle session

You can also use transport-specific methods directly:

	// WebTransport
	sess, err := dialer.DialWebTransport(ctx, "host:port", "/path", mux)

	// Native QUIC
	sess, err := dialer.DialQUIC(ctx, "host:port", mux)

Note: Nil TrackMux

When mux is set to nil, the moqt.DefaultMux will be used by default. Ensure that the mux is properly configured for your use case to avoid unexpected behavior.

Note: ALPN Negotiation

For native QUIC connections, the dialer automatically sets the ALPN token to moq-lite-04 (moqt.NextProtoMOQ) if TLSConfig.NextProtos is not configured.