session

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 24 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

Package session shares a local file in a pedit room.

Index

Constants

This section is empty.

Variables

View Source
var ErrBehindAccess = errors.New("Cloudflare Access sent us to its login page")

ErrBehindAccess means Cloudflare Access sent us to its login page: we sent no credentials, or Access did not accept them.

View Source
var ErrRoomClosed = errors.New("the room is closed: the host left, or the link is wrong")

ErrRoomClosed means the room could not be joined because nobody hosts it: the host left, or the link is wrong.

Functions

This section is empty.

Types

type ErrFileExists

type ErrFileExists struct{ Path string }

ErrFileExists means the copy was not written because a file of that name is already in Directory.

func (*ErrFileExists) Error

func (e *ErrFileExists) Error() string

type JoinOptions

type JoinOptions struct {
	// URL is the share link, with the key in its fragment.
	URL string
	// Directory is where the copy is written, under the name the host shares,
	// and where it stays after the session. Empty: a temporary directory that
	// is removed when the session stops, leaving nothing behind, like a
	// browser tab.
	Directory  string
	Name       string
	WriteDelay time.Duration
	// Watch streams edits made to the copy outside pedit into the room.
	Watch bool
	// Timeout bounds how long Join waits for the room's state; 15s by default.
	Timeout  time.Duration
	Header   http.Header
	Dial     protocol.Dialer
	OnStatus func(protocol.Status)
	OnPeople func([]string)
	OnError  func(error)
	// contains filtered or unexported fields
}

JoinOptions joins a room someone else hosts, as a browser would, and keeps a local copy of the shared file so any editor can work on it.

type Options

type Options struct {
	File string
	// Server is the base URL of the pedit server, e.g. https://edit.piconic.ai
	Server string
	Name   string
	// Avatar is the URL of the host's picture, shown to the others.
	Avatar     string
	WriteDelay time.Duration
	// Watch streams edits made to the file outside pedit into the room.
	Watch bool
	// Header is sent with every request to the server, such as the Cloudflare
	// Access token of whoever signed in.
	Header     http.Header
	HTTPClient *http.Client
	Dial       protocol.Dialer
	OnStatus   func(protocol.Status)
	// OnPeople is called with the names of the other people in the room,
	// sorted, whenever someone joins, leaves or renames.
	OnPeople func([]string)
	// OnSaved is called with the path, relative to File, of each image
	// someone pasted that was saved beside the file.
	OnSaved func(path string)
	OnError func(error)
}

type Session

type Session struct {
	// URL is the share URL. Its fragment holds the key and must never be sent to the server.
	URL string
	Doc *crdt.Doc
	// Text is the shared text, or nil when the file is a canvas, shared as
	// nodes and edges.
	Text   *crdt.YText
	Client *protocol.Client
	Writer *filewriter.Writer
	// contains filtered or unexported fields
}

func Join

func Join(ctx context.Context, opts JoinOptions) (*Session, error)

Join enters the room at opts.URL, waits for its content and writes it to a file named as the host's. The returned Session mirrors the copy and the room both ways until Stop; Session.URL is the link joined.

func Start

func Start(ctx context.Context, opts Options) (*Session, error)

func (*Session) File

func (s *Session) File() string

File is the path of the shared file, or of the copy when the session joined a room.

func (*Session) Stop

func (s *Session) Stop() error

Stop leaves the room and writes the final state to the file. It reports an error when the final state could not be saved.

func (*Session) Temporary

func (s *Session) Temporary() bool

Temporary reports whether the copy is removed when the session stops.

Jump to

Keyboard shortcuts

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