moqtransport

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2024 License: MIT Imports: 13 Imported by: 6

README

Media over QUIC Transport

Go Reference

moqtransport is an implementation of Media over QUIC Transport on top of quic-go and optionally webtransport-go.

Example: Chat Server and Client

The examples directory contains an implementation of MoQ Chat.

To run a simple chat server using MoQ Tranpsort on top of QUIC, run:

go run examples/chat-server/main.go

Then, open a new shell and start a client:

go run examples/chat-client/main.go

The client is a simple interactive shell that reads and writes messages from stdin and stdout (input and output is currently not well synchronized).

Open another shell and run a second client to chat with the first one using the commands join <roomID> <username> to join a room and msg <roomID> <message> to send messages to a room.

To use WebTransport, you need to create a TLS certificate. This can be done using mkcert:

mkcert localhost
mkcert -install

mkcert will generate a localhost.pem and a localhost-key.pem file. If you change the name of the files or use a different host name, you can use the -cert and -key flags of the server command to point it to the correct files.

Now start the server and client with the -webtransport and -addr flags to run MoQ Transport on top of WebTransport:

Server:

go run examples/chat-server/main.go -webtransport

Client:

go run examples/chat-client/main.go -webtransport -addr https://localhost:8080/moq

Documentation

Index

Constants

View Source
const (
	ErrorCodeNoError                 = 0x00
	ErrorCodeInternal                = 0x01
	ErrorCodeUnauthorized            = 0x02
	ErrorCodeProtocolViolation       = 0x03
	ErrorCodeDuplicateTrackAlias     = 0x04
	ErrorCodeParameterLengthMismatch = 0x05
	ErrorCodeGoAwayTimeout           = 0x10

	// Errors not included in current draft
	ErrorCodeUnsupportedVersion = 0xff01
	ErrorCodeTrackNotFound      = 0xff02
)
View Source
const (
	SubscribeErrorInternal        = 0x00
	SubscribeErrorInvalidRange    = 0x01
	SubscribeErrorRetryTrackAlias = 0x02

	// TODO: These are not specified yet, but seem useful
	SubscribeErrorUnknownTrack = 0x03
)
View Source
const (
	SubscribeStatusUnsubscribed      = 0x00
	SubscribeStatusInternalError     = 0x01
	SubscribeStatusUnauthorized      = 0x02
	SubscribeStatusTrackEnded        = 0x03
	SubscribeStatusSubscriptionEnded = 0x04
	SubscribeStatusGoingAway         = 0x05
	SubscribeStatusExpired           = 0x06
)
View Source
const (
	DRAFT_IETF_MOQ_TRANSPORT_00 = 0xff000000
	DRAFT_IETF_MOQ_TRANSPORT_01 = 0xff000001
	DRAFT_IETF_MOQ_TRANSPORT_02 = 0xff000002
	DRAFT_IETF_MOQ_TRANSPORT_03 = 0xff000003

	CURRENT_VERSION = DRAFT_IETF_MOQ_TRANSPORT_03
)

Variables

This section is empty.

Functions

func SetLogHandler added in v0.2.0

func SetLogHandler(handler slog.Handler)

Types

type Announcement added in v0.2.0

type Announcement struct {
	// contains filtered or unexported fields
}

func (*Announcement) Namespace added in v0.2.0

func (a *Announcement) Namespace() string

type AnnouncementHandler

type AnnouncementHandler interface {
	HandleAnnouncement(*Session, *Announcement, AnnouncementResponseWriter)
}

type AnnouncementHandlerFunc added in v0.3.0

type AnnouncementHandlerFunc func(*Session, *Announcement, AnnouncementResponseWriter)

func (AnnouncementHandlerFunc) HandleAnnouncement added in v0.3.0

func (f AnnouncementHandlerFunc) HandleAnnouncement(s *Session, a *Announcement, arw AnnouncementResponseWriter)

type AnnouncementResponseWriter added in v0.3.0

type AnnouncementResponseWriter interface {
	Accept()
	Reject(code uint64, reason string)
}

type ApplicationError added in v0.3.0

type ApplicationError struct {
	// contains filtered or unexported fields
}

func (ApplicationError) Error added in v0.3.0

func (e ApplicationError) Error() string

type Connection added in v0.3.0

type Connection interface {
	OpenStream() (Stream, error)
	OpenStreamSync(context.Context) (Stream, error)
	OpenUniStream() (SendStream, error)
	OpenUniStreamSync(context.Context) (SendStream, error)
	AcceptStream(context.Context) (Stream, error)
	AcceptUniStream(context.Context) (ReceiveStream, error)
	SendDatagram([]byte) error
	ReceiveDatagram(context.Context) ([]byte, error)
	CloseWithError(uint64, string) error
}

type LocalTrack added in v0.3.0

type LocalTrack struct {
	ID        uint64
	Namespace string
	Name      string
	// contains filtered or unexported fields
}

A LocalTrack is a local media source. Writing objects to the track will relay the objects to all subscribers. All methods are safe for concurrent use. Ordering of objects is only guaranteed within MultiObjectStreams. LocalTracks must be created with NewLocalTrack to ensure proper initialization.

func NewLocalTrack added in v0.3.0

func NewLocalTrack(id uint64, namespace, trackname string) *LocalTrack

NewLocalTrack creates a new LocalTrack

func (*LocalTrack) Close added in v0.3.0

func (t *LocalTrack) Close() error

func (*LocalTrack) SubscriberCount added in v0.3.0

func (t *LocalTrack) SubscriberCount() int

func (*LocalTrack) WriteObject added in v0.3.0

func (t *LocalTrack) WriteObject(ctx context.Context, o Object) error

WriteObject adds an object to the track

type Location added in v0.2.0

type Location struct {
	Mode  LocationMode
	Value uint64
}

type LocationMode added in v0.2.0

type LocationMode int
const (
	LocationModeNone LocationMode = iota
	LocationModeAbsolute
	LocationModeRelativePrevious
	LocationModeRelativeNext
)

type Object added in v0.3.0

type Object struct {
	GroupID              uint64
	ObjectID             uint64
	ObjectSendOrder      uint64
	ForwardingPreference ObjectForwardingPreference

	Payload []byte
}

type ObjectForwardingPreference added in v0.3.0

type ObjectForwardingPreference int
const (
	ObjectForwardingPreferenceDatagram ObjectForwardingPreference = iota
	ObjectForwardingPreferenceStream
	ObjectForwardingPreferenceStreamGroup
	ObjectForwardingPreferenceStreamTrack
)

type ObjectWriter added in v0.3.0

type ObjectWriter interface {
	WriteObject(Object) error
	io.Closer
}

An ObjectWriter allows sending objects using.

type ProtocolError added in v0.3.0

type ProtocolError struct {
	// contains filtered or unexported fields
}

func (ProtocolError) Code added in v0.3.0

func (e ProtocolError) Code() uint64

func (ProtocolError) Error added in v0.3.0

func (e ProtocolError) Error() string

type ReceiveStream added in v0.3.0

type ReceiveStream interface {
	io.Reader
}

type RemoteTrack added in v0.3.0

type RemoteTrack struct {
	// contains filtered or unexported fields
}

func (*RemoteTrack) ReadObject added in v0.3.0

func (s *RemoteTrack) ReadObject(ctx context.Context) (Object, error)

func (*RemoteTrack) Unsubscribe added in v0.3.0

func (s *RemoteTrack) Unsubscribe()

type Role added in v0.2.0

type Role uint64
const (
	RolePublisher Role = iota + 1
	RoleSubscriber
	RolePubSub
)

type SendStream added in v0.3.0

type SendStream interface {
	io.WriteCloser
}

type Session added in v0.2.0

type Session struct {
	Conn                Connection
	EnableDatagrams     bool
	LocalRole           Role
	RemoteRole          Role
	AnnouncementHandler AnnouncementHandler
	SubscriptionHandler SubscriptionHandler
	// contains filtered or unexported fields
}

func (*Session) AddLocalTrack added in v0.3.0

func (s *Session) AddLocalTrack(t *LocalTrack) error

func (*Session) Announce added in v0.2.0

func (s *Session) Announce(ctx context.Context, namespace string) error

func (*Session) Close added in v0.3.0

func (s *Session) Close() error

func (*Session) CloseWithError added in v0.2.0

func (s *Session) CloseWithError(code uint64, msg string) error

func (*Session) RunClient added in v0.3.0

func (s *Session) RunClient() error

func (*Session) RunServer added in v0.3.0

func (s *Session) RunServer(ctx context.Context) error

func (*Session) Subscribe added in v0.2.0

func (s *Session) Subscribe(ctx context.Context, subscribeID, trackAlias uint64, namespace, trackname, auth string) (*RemoteTrack, error)

type Stream added in v0.3.0

type Stream interface {
	ReceiveStream
	SendStream
}

type Subscription added in v0.3.0

type Subscription struct {
	ID            uint64
	TrackAlias    uint64
	Namespace     string
	TrackName     string
	Authorization string
}

type SubscriptionHandler

type SubscriptionHandler interface {
	HandleSubscription(*Session, *Subscription, SubscriptionResponseWriter)
}

type SubscriptionHandlerFunc added in v0.3.0

type SubscriptionHandlerFunc func(*Session, *Subscription, SubscriptionResponseWriter)

func (SubscriptionHandlerFunc) HandleSubscription added in v0.3.0

func (f SubscriptionHandlerFunc) HandleSubscription(se *Session, su *Subscription, srw SubscriptionResponseWriter)

type SubscriptionResponseWriter added in v0.3.0

type SubscriptionResponseWriter interface {
	Accept(*LocalTrack)
	Reject(code uint64, reason string)
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL