Documentation
¶
Overview ¶
Package session shares a local file in a pedit room.
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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 (*Session) File ¶
File is the path of the shared file, or of the copy when the session joined a room.