datatrack

package
v2.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Copyright 2026 LiveKit, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2026 LiveKit, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAllowed         = errors.New("data track publishing unauthorized")
	ErrDuplicateName      = errors.New("track name already taken")
	ErrInvalidName        = errors.New("track name invalid")
	ErrLimitReached       = errors.New("data track publication limit reached")
	ErrPublishTimeout     = errors.New("timed out publishing data track")
	ErrSubscribeTimeout   = errors.New("timed out subscribing to data track")
	ErrDisconnected       = errors.New("room disconnected")
	ErrUnpublished        = errors.New("track unpublished")
	ErrQueueFull          = errors.New("queue full")
	ErrEncryptionDisabled = errors.New("track is end-to-end encrypted but data encryption is not enabled")
)
View Source
var (
	ErrUnsupportedVersion = errors.New("unsupported data track packet version")
	ErrInvalidHandle      = errors.New("invalid data track handle")
)
View Source
var (
	ErrSchemaMissingFrameEncoding = errors.New("frame encoding is required when providing schema ID")
	ErrSchemaMissingID            = errors.New("schema ID is required for frame encoding that is not self-describing")
	ErrSchemaIncompatible         = errors.New("specified schema and frame encodings are incompatible")
)
View Source
var ErrInvalidSID = errors.New("invalid data track SID")

Functions

func UserTimestampNow

func UserTimestampNow() *uint64

UserTimestampNow returns the current Unix time in milliseconds, the interpretation DurationSinceTimestamp expects.

Types

type CustomFrameEncoding

type CustomFrameEncoding string

CustomFrameEncoding is an application-defined frame encoding identified by name.

func (CustomFrameEncoding) String

func (e CustomFrameEncoding) String() string

type CustomSchemaEncoding

type CustomSchemaEncoding string

CustomSchemaEncoding is an application-defined schema encoding identified by name.

func (CustomSchemaEncoding) String

func (e CustomSchemaEncoding) String() string

type Decryptor

type Decryptor interface {
	Decrypt(payload []byte, e2ee dtp.ExtensionE2EE) ([]byte, error)
}

Decryptor opens end-to-end encrypted frame payloads.

type Encryptor

type Encryptor interface {
	Encrypt(payload []byte) ([]byte, dtp.ExtensionE2EE, error)
}

Encryptor seals frame payloads for end-to-end encryption.

type Extensions

type Extensions struct {
	UserTimestamp *uint64
	E2EE          *dtp.ExtensionE2EE
}

Extensions are the header extensions understood by this SDK.

type Frame

type Frame struct {
	Payload []byte
	// UserTimestamp is an optional application-defined timestamp; nil when unset.
	UserTimestamp *uint64
}

Frame is a frame published on a data track.

func (Frame) DurationSinceTimestamp

func (f Frame) DurationSinceTimestamp() (time.Duration, bool)

DurationSinceTimestamp returns how much time has passed since the frame's user timestamp, taken as Unix milliseconds. It is false if the frame has no user timestamp or the timestamp lies in the future.

type FrameEncoding

type FrameEncoding interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

FrameEncoding is the encoding of frames pushed on a data track: a WellKnownFrameEncoding or a CustomFrameEncoding.

type FrameMarker

type FrameMarker uint8

FrameMarker is a packet's position within its frame.

const (
	FrameMarkerInter FrameMarker = iota
	FrameMarkerStart
	FrameMarkerFinal
	FrameMarkerSingle
)

type FramePackets

type FramePackets [][]byte

FramePackets is one frame serialized into data track packets.

type Info

type Info struct {
	SID livekit.TrackID

	Name          string
	UsesE2EE      bool
	Schema        *SchemaID
	FrameEncoding FrameEncoding
	// contains filtered or unexported fields
}

Info describes a published data track. The SID changes when the publisher completes a full reconnect; Name is stable. Schema and FrameEncoding are nil when not specified.

type LocalManager

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

LocalManager tracks the data tracks published by the local participant. Methods are safe for concurrent use.

func NewLocalManager

func NewLocalManager(params LocalManagerParams) *LocalManager

func (*LocalManager) HandlePublishResponse

func (m *LocalManager) HandlePublishResponse(msg *livekit.PublishDataTrackResponse)

HandlePublishResponse completes the publication the SFU accepted.

func (*LocalManager) HandleRequestResponse

func (m *LocalManager) HandleRequestResponse(msg *livekit.RequestResponse) bool

HandleRequestResponse fails the publication a rejection refers to. It reports whether the response was a publish rejection.

func (*LocalManager) HandleUnpublishResponse

func (m *LocalManager) HandleUnpublishResponse(msg *livekit.UnpublishDataTrackResponse)

HandleUnpublishResponse completes an unpublication, whether requested locally or by the SFU.

func (*LocalManager) Publish

func (m *LocalManager) Publish(ctx context.Context, options PublishOptions) (*LocalTrack, error)

Publish requests a publication and waits for the SFU's answer. Ending ctx abandons the request; should the SFU accept it afterwards, the track is unpublished right away.

func (*LocalManager) PublishResponsesForSyncState

func (m *LocalManager) PublishResponsesForSyncState() []*livekit.PublishDataTrackResponse

PublishResponsesForSyncState describes the current publications for SyncState.

func (*LocalManager) RepublishTracks

func (m *LocalManager) RepublishTracks()

RepublishTracks re-requests every publication after a full reconnect. Pending publications fail with ErrDisconnected; published tracks drop frames until the SFU answers with their new SID, and are unpublished if it rejects them.

func (*LocalManager) SetLogger

func (m *LocalManager) SetLogger(l logger.Logger)

SetLogger replaces the logger given at construction.

func (*LocalManager) Shutdown

func (m *LocalManager) Shutdown()

Shutdown fails pending publications and unpublishes every track locally. The manager can be used again for a new session.

type LocalManagerParams

type LocalManagerParams struct {
	Transport LocalTransport
	// Encryptor returns the encryptor for the current session; nil, or a nil result, disables
	// end-to-end encryption for tracks published from then on.
	Encryptor func() Encryptor
	Logger    logger.Logger
}

type LocalTrack

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

LocalTrack is a data track published by the local participant. Methods are safe for concurrent use.

func (*LocalTrack) Info

func (t *LocalTrack) Info() Info

Info returns a snapshot of the track's metadata. The SID changes when the local participant completes a full reconnect.

func (*LocalTrack) IsPublished

func (t *LocalTrack) IsPublished() bool

IsPublished reports whether the track is published. A track being republished after a reconnect still counts as published.

func (*LocalTrack) TryPush

func (t *LocalTrack) TryPush(frame Frame) error

TryPush sends a frame to the track's subscribers. It returns ErrUnpublished once the track is unpublished and ErrQueueFull while it is being republished after a reconnect. Frames are never retained, so the caller may reuse the payload immediately. Frames with empty payloads are dropped.

func (*LocalTrack) Unpublish

func (t *LocalTrack) Unpublish()

Unpublish stops the publication. It is safe to call more than once.

func (*LocalTrack) Unpublished

func (t *LocalTrack) Unpublished() <-chan struct{}

Unpublished is closed once the track is no longer published, whether by Unpublish, the SFU, or disconnecting from the room.

type LocalTransport

type LocalTransport interface {
	// SendPublishRequest may block until the connection is ready; it returns ctx.Err() when ctx ends first.
	SendPublishRequest(ctx context.Context, req *livekit.PublishDataTrackRequest) error
	SendUnpublishRequest(req *livekit.UnpublishDataTrackRequest) error
	// SendFrame queues a frame's packets; it must not block.
	SendFrame(frame FramePackets)
}

LocalTransport carries what the local manager produces: signal requests to the SFU and frame packets over the data channel.

type PipelineOptions

type PipelineOptions struct {
	// MaxPartialFrames is the number of frames reassembled concurrently. Higher values tolerate
	// more reordering at the cost of buffering. Zero is clamped to one.
	MaxPartialFrames int
}

PipelineOptions configure how a remote track's packets are reassembled.

type PublishOption

type PublishOption func(*PublishOptions)

PublishOption customizes a publication.

func WithFrameEncoding

func WithFrameEncoding(encoding FrameEncoding) PublishOption

WithFrameEncoding declares the encoding of the track's frames.

func WithSchema

func WithSchema(schema SchemaID) PublishOption

WithSchema associates a schema with the track's frames.

type PublishOptions

type PublishOptions struct {
	Name          string
	Schema        *SchemaID
	FrameEncoding FrameEncoding
}

PublishOptions describe a data track to publish.

type RemoteManager

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

RemoteManager tracks the data tracks published by remote participants and the local participant's subscriptions to them. Methods are safe for concurrent use.

func NewRemoteManager

func NewRemoteManager(params RemoteManagerParams) *RemoteManager

func (*RemoteManager) HandlePacket

func (m *RemoteManager) HandlePacket(data []byte)

HandlePacket routes a packet received on the data channel to its track's subscribers.

func (*RemoteManager) HandleParticipantSnapshot

func (m *RemoteManager) HandleParticipantSnapshot(participants []*livekit.ParticipantInfo, localIdentity string)

HandleParticipantSnapshot applies a complete list of the room's participants, as carried by a JoinResponse. Publishers absent from the list are treated as gone.

func (*RemoteManager) HandleParticipantUpdate

func (m *RemoteManager) HandleParticipantUpdate(participants []*livekit.ParticipantInfo, localIdentity string)

HandleParticipantUpdate applies the data tracks listed for each participant in a ParticipantUpdate; tracks a participant no longer lists are unpublished.

func (*RemoteManager) HandleSubscriberHandles

func (m *RemoteManager) HandleSubscriberHandles(msg *livekit.DataTrackSubscriberHandles)

HandleSubscriberHandles records the handles the SFU assigned to requested subscriptions, which activates pending subscriptions.

func (*RemoteManager) ResendSubscriptionUpdates

func (m *RemoteManager) ResendSubscriptionUpdates()

ResendSubscriptionUpdates re-requests every pending and active subscription after a full reconnect.

func (*RemoteManager) SetLogger

func (m *RemoteManager) SetLogger(l logger.Logger)

SetLogger replaces the logger given at construction.

func (*RemoteManager) Shutdown

func (m *RemoteManager) Shutdown()

Shutdown ends every subscription and marks every track unpublished. The manager can be used again for a new session.

type RemoteManagerParams

type RemoteManagerParams struct {
	Transport RemoteTransport
	// Decryptor returns the decryptor for the current session; nil, or a nil result, leaves frames of
	// end-to-end encrypted tracks as received.
	Decryptor func() Decryptor
	Logger    logger.Logger
}

type RemoteTrack

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

RemoteTrack is a data track published by a remote participant. Methods are safe for concurrent use.

func (*RemoteTrack) Info

func (t *RemoteTrack) Info() Info

Info returns a snapshot of the track's metadata. The SID changes when the publisher completes a full reconnect.

func (*RemoteTrack) IsPublished

func (t *RemoteTrack) IsPublished() bool

IsPublished reports whether the track is still published.

func (*RemoteTrack) PublisherIdentity

func (t *RemoteTrack) PublisherIdentity() string

PublisherIdentity is the identity of the participant who published the track.

func (*RemoteTrack) SetPipelineOptions

func (t *RemoteTrack) SetPipelineOptions(options PipelineOptions)

SetPipelineOptions configures how the track's packets are reassembled. The options apply to all current and future subscriptions and take effect with the next packet.

func (*RemoteTrack) Subscribe

func (t *RemoteTrack) Subscribe(ctx context.Context, opts ...SubscribeOption) (*Stream, error)

Subscribe starts receiving the track's frames. Only the first subscription talks to the SFU; later ones share the pipeline and miss frames delivered before they were made. A 10 second deadline applies when ctx has none. Do not call it inline from the OnDataTrackPublished callback, which runs on the goroutine that delivers the SFU's response.

func (*RemoteTrack) Unpublished

func (t *RemoteTrack) Unpublished() <-chan struct{}

Unpublished is closed once the track is no longer published, whether by its publisher, the SFU, or disconnecting from the room.

type RemoteTransport

type RemoteTransport interface {
	SendUpdateSubscription(req *livekit.UpdateDataSubscription) error
	OnTrackPublished(track *RemoteTrack)
	OnTrackUnpublished(track *RemoteTrack)
}

RemoteTransport carries what the remote manager produces: subscription requests to the SFU and publication events for the application.

type SchemaEncoding

type SchemaEncoding interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

SchemaEncoding is the encoding of a schema definition: a WellKnownSchemaEncoding or a CustomSchemaEncoding.

type SchemaID

type SchemaID struct {
	Name     string
	Encoding SchemaEncoding
}

SchemaID identifies a data track schema. IDs with the same name but different encodings are distinct.

type Stream

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

Stream delivers the frames of one subscription.

func (*Stream) Close

func (s *Stream) Close()

Close ends the subscription. It is safe to call more than once.

func (*Stream) Next

func (s *Stream) Next(ctx context.Context) (Frame, error)

Next blocks until a frame arrives. It returns io.EOF once the stream is closed, the track is unpublished, or the room disconnects, and ctx's error when ctx ends first.

type SubscribeOption

type SubscribeOption func(*SubscribeOptions)

SubscribeOption customizes a subscription.

func WithBufferSize

func WithBufferSize(frames int) SubscribeOption

WithBufferSize sets the number of received frames buffered for the subscriber. It has no effect when the track already has an active subscription.

type SubscribeOptions

type SubscribeOptions struct {
	// BufferSize is the number of received frames buffered for the subscriber; older frames are
	// dropped when it is exceeded. Zero is clamped to one.
	BufferSize int
}

SubscribeOptions configure a subscription.

type WellKnownFrameEncoding

type WellKnownFrameEncoding uint8

WellKnownFrameEncoding is a frame encoding defined by the protocol.

const (
	// FrameEncodingOther is a well-known encoding not known to this SDK version.
	FrameEncodingOther WellKnownFrameEncoding = iota
	FrameEncodingROS1
	FrameEncodingCDR
	FrameEncodingProtobuf
	FrameEncodingFlatbuffer
	FrameEncodingCBOR
	FrameEncodingMsgPack
	FrameEncodingJSON
)

func (WellKnownFrameEncoding) String

func (e WellKnownFrameEncoding) String() string

type WellKnownSchemaEncoding

type WellKnownSchemaEncoding uint8

WellKnownSchemaEncoding is a schema encoding defined by the protocol.

const (
	// SchemaEncodingOther is a well-known encoding not known to this SDK version.
	SchemaEncodingOther WellKnownSchemaEncoding = iota
	SchemaEncodingProtobuf
	SchemaEncodingFlatbuffer
	SchemaEncodingROS1Msg
	SchemaEncodingROS2Msg
	SchemaEncodingROS2IDL
	SchemaEncodingOMGIDL
	SchemaEncodingJSONSchema
)

func (WellKnownSchemaEncoding) String

func (e WellKnownSchemaEncoding) String() string

Jump to

Keyboard shortcuts

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