live

package
v0.0.0-...-e14778a Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionNotFound    = errors.New("session not found")
	ErrComponentNotFound  = errors.New("component not found")
	ErrSchedulerNotActive = errors.New("scheduler not active")
)

Error definitions

Functions

func EncodeEvent

func EncodeEvent(evt Event) []byte

EncodeEvent encodes an event to binary format

func EncodePatches

func EncodePatches(patches []vdom.Patch) ([]byte, error)

EncodePatches encodes patches to binary format

func InitBridge

func InitBridge(server *Server)

InitBridge initializes the global scheduler bridge

Types

type BridgedSession

type BridgedSession struct {
	Session    *Session
	Scheduler  *scheduler.Scheduler
	Components map[string]*server.ComponentInstance
}

BridgedSession represents a session with scheduler integration

type Decoder

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

Decoder handles decoding of live protocol messages

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new decoder

func (*Decoder) ReadByte

func (d *Decoder) ReadByte() (byte, error)

ReadByte implements io.ByteReader

func (*Decoder) ReadBytes

func (d *Decoder) ReadBytes(n int) ([]byte, error)

ReadBytes reads n bytes

func (*Decoder) ReadString

func (d *Decoder) ReadString() (string, error)

ReadString reads a length-prefixed string

func (*Decoder) ReadUvarint

func (d *Decoder) ReadUvarint() (uint64, error)

ReadUvarint reads an unsigned varint

type Encoder

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

Encoder handles encoding of live protocol messages

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates a new encoder

func (*Encoder) WriteBytes

func (e *Encoder) WriteBytes(b []byte) error

WriteBytes writes raw bytes

func (*Encoder) WriteString

func (e *Encoder) WriteString(s string) error

WriteString writes a length-prefixed string

func (*Encoder) WriteUvarint

func (e *Encoder) WriteUvarint(v uint64) error

WriteUvarint writes an unsigned varint

type Event

type Event struct {
	Type   EventType
	NodeID uint32
	Data   map[string]interface{}
}

Event represents a client-side event

func DecodeEvent

func DecodeEvent(data []byte) (*Event, error)

DecodeEvent decodes an event from binary format

type EventType

type EventType uint8

EventType represents client-side event types

const (
	EventClick     EventType = 0x01
	EventIncrement EventType = 0x02
	EventDecrement EventType = 0x03
	EventReset     EventType = 0x04
	EventInput     EventType = 0x05
	EventSubmit    EventType = 0x06
)

type MessageType

type MessageType uint8

MessageType represents the type of live protocol message

const (
	// Frame types
	FramePatches MessageType = 0x00
	FrameEvent   MessageType = 0x01
	FrameControl MessageType = 0x02
)

type SchedulerBridge

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

SchedulerBridge connects the scheduler to the Live Protocol

func GetBridge

func GetBridge() *SchedulerBridge

GetBridge returns the global scheduler bridge

func NewSchedulerBridge

func NewSchedulerBridge(liveServer *Server) *SchedulerBridge

NewSchedulerBridge creates a new scheduler bridge

func (*SchedulerBridge) CleanupSession

func (b *SchedulerBridge) CleanupSession(sessionID string)

CleanupSession cleans up when a session ends

func (*SchedulerBridge) CreateServerComponent

func (b *SchedulerBridge) CreateServerComponent(
	sessionID string,
	componentID string,
	render func(ctx *vango.Context) *vdom.VNode,
) (*server.ComponentInstance, error)

CreateServerComponent creates a server-driven component instance

func (*SchedulerBridge) CreateSessionScheduler

func (b *SchedulerBridge) CreateSessionScheduler(sessionID string) *scheduler.Scheduler

CreateSessionScheduler creates a scheduler for a session

func (*SchedulerBridge) GetBridgedSession

func (b *SchedulerBridge) GetBridgedSession(sessionID string) (*BridgedSession, bool)

GetBridgedSession returns a bridged session

func (*SchedulerBridge) HandleComponentEvent

func (b *SchedulerBridge) HandleComponentEvent(sessionID string, nodeID uint32, eventType string) error

HandleComponentEvent routes an event to a component

type Server

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

Server handles WebSocket connections for live updates

func NewServer

func NewServer() *Server

NewServer creates a new live protocol server

func (*Server) GetSession

func (s *Server) GetSession(sessionID string) (*Session, bool)

GetSession retrieves a session by ID

func (*Server) HandleWebSocket

func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request)

HandleWebSocket handles WebSocket upgrade and session management

func (*Server) RemoveSession

func (s *Server) RemoveSession(sessionID string)

RemoveSession removes a session

type Session

type Session struct {
	ID string
	// contains filtered or unexported fields
}

Session represents a live connection session

func (*Session) GetState

func (s *Session) GetState(key string) (interface{}, bool)

GetState retrieves a state value

func (*Session) SendPatches

func (s *Session) SendPatches(patches []vdom.Patch) error

SendPatches sends a batch of patches to the client

func (*Session) UpdateState

func (s *Session) UpdateState(key string, value interface{})

UpdateState updates the session state and generates patches

Jump to

Keyboard shortcuts

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