Documentation
¶
Overview ¶
Package session shares a local file in a pedit room.
Index ¶
Constants ¶
const MaxFiles = 20
MaxFiles is how many files one session shares, the first included.
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 ErrClientOutdated = errors.New("this pedit is too old for the server; update it")
ErrClientOutdated means the server speaks a newer protocol version than this pedit, which has to be updated.
var ErrRelayMaintenance = errors.New("the relay is closed for maintenance; try again later")
ErrRelayMaintenance means the relay is closed for maintenance.
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.
var ErrRoomExpired = errors.New("the room has ended: it reached its time limit on the relay; ask the host to run pedit again for a new link")
ErrRoomExpired means the room reached its relay's time limit and has ended for good.
var ErrRoomFull = errors.New("the room is full: its relay takes only so many people at once; try again when someone leaves")
ErrRoomFull means the room already has as many guests as its relay allows.
var ErrServerOutdated = errors.New("the server is older than this pedit; ask whoever runs it to update it")
ErrServerOutdated means the server speaks an older protocol version than this pedit; whoever runs it has to update it.
var ErrTooLarge = errors.New("the shared file is too large to share; pedit shares files up to " + SizeLimit + " for now")
ErrTooLarge means the room's file grew too large to share.
var SizeLimit = fmt.Sprintf("about %d MiB", protocol.MaxFrameBytes>>20)
SizeLimit is how much pedit shares, as people read it: a room gets the whole state in one frame, which the relay caps at protocol.MaxFrameBytes.
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 appeared in its directory, which pedit made empty.
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
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)
// OnNotice and OnError are as in Options.
OnNotice func(Notice)
OnError func(error)
// OnMirrored is called for each other file the room shares, with the path
// the host shows it at and the path of its copy beside the first, and why
// it is not copied when it is not. Called one at a time.
OnMirrored func(hostPath, path string, err error)
// contains filtered or unexported fields
}
JoinOptions joins a room someone else hosts, as a browser would, and keeps a local copy of each text file it shares so any editor can work on it. The copies go in a new temporary directory, removed when the session stops, leaving nothing behind, like a browser tab. They are named by the guest (copyName), never as the host names them.
type Notice ¶ added in v0.1.2
type Notice struct {
Kind NoticeKind
// File is the path of the shared file, or of the copy when joined.
File string
// Reason says why in a few words, for SaveFailed, ChangeHeld and
// ImageNotSaved. It is the same each time the same cause comes back.
Reason string
// Details are more lines about Reason, such as each problem in a canvas.
Details []string
// Kept is the temporary name, beside File, a save is kept under, for
// SaveKept.
Kept string
// Err is the error behind the notice, for diagnostics.
Err error
}
Notice tells the user about a condition of the local file they can act on. Errors nobody can act on, or that clear by themselves, go to OnError.
type NoticeKind ¶ added in v0.1.2
type NoticeKind string
NoticeKind names a condition of the local file that the user can act on.
const ( // SaveFailed means the file could not be saved, and could not when tried // again either. The edits are kept, and the save is tried again until it // lands. SaveFailed NoticeKind = "save-failed" // SaveRecovered means a save landed after SaveFailed. SaveRecovered NoticeKind = "save-recovered" // ChangeHeld means the file changed outside pedit into something pedit // cannot take in, so pedit does not save over it until it is fixed. ChangeHeld NoticeKind = "change-held" // HoldReleased means that after ChangeHeld, the file was fixed or put // back, and saving goes on. HoldReleased NoticeKind = "hold-released" // ImageNotSaved means an image someone pasted could not be saved beside // the file. They are told it was not added. ImageNotSaved NoticeKind = "image-not-saved" // SaveLost means a save made outside pedit while pedit wrote the file was // written into the file pedit's write replaced, and is lost. Only where // files cannot be exchanged, such as on Windows. SaveLost NoticeKind = "save-lost" // SaveKept means pedit moved aside what was in the file while it wrote it, // and could not put it back: a save made outside pedit may be in Kept. SaveKept NoticeKind = "save-kept" )
type Options ¶
type Options struct {
File string
// Root is the directory the paths of a room's files are shown relative
// to, such as where pedit runs. A file outside it is shown by its name.
// Empty: the first file's directory.
Root 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)
// OnNotice is called, one at a time, with conditions of the file the
// user can act on: a save that failed, or a change pedit cannot take in,
// and when each ends. It must not call into the Session.
OnNotice func(Notice)
// OnError is called with errors nobody can act on, or that clear by
// themselves, such as a dropped connection.
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
// 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 copy (copyName). The returned Session mirrors the copy and the room both ways until Stop; Session.URL is the link joined.
func (*Session) AddFile ¶ added in v0.1.12
AddFile shares another file in the room, in a Y.Doc of its own, and tells the room its new list of files. The host names every file: nothing in the room can add one. It fails, changing nothing, when the file cannot be shared, or is already.
func (*Session) File ¶
File is the path of the shared file, or of the copy when the session joined a room.
func (*Session) Files ¶ added in v0.1.12
Files lists the files the session shares, the first one first.
func (*Session) KeepCopy ¶ added in v0.1.3
func (s *Session) KeepCopy()
KeepCopy makes Stop keep the temporary directory of the copies. Call it before Stop.
type TooLargeError ¶ added in v0.1.3
type TooLargeError struct {
File string
// Size is the file's size in bytes.
Size int
// shared form is larger than its file; 0 for text.
Shared int
}
TooLargeError means a file is too large to share: a room gets its whole state in one frame, which the relay caps at protocol.MaxFrameBytes.
func (*TooLargeError) Error ¶ added in v0.1.3
func (e *TooLargeError) Error() string