Documentation
¶
Overview ¶
Package session shares a local file in a pedit room.
Index ¶
- Constants
- Variables
- func CloseKept(ctx context.Context, opts KeptTextOptions) error
- func PruneKept(project string, notify func(int)) error
- func ReadSavedComments(projectDir, file string) (*meta.File, error)
- type CommentChange
- type ErrFileExists
- type FileThreads
- type JoinOptions
- type KeptTextOptions
- type KeptTextRecord
- type Link
- type Notice
- type NoticeKind
- type Options
- type Session
- func (s *Session) AddFile(file string) (protocol.FileEntry, error)
- func (s *Session) Comments() []FileThreads
- func (s *Session) File() string
- func (s *Session) Files() []protocol.FileEntry
- func (s *Session) KeepCopy()
- func (s *Session) KeptUntil() time.Time
- func (s *Session) Links() []Link
- func (s *Session) Reply(file, thread, id, body string) (WriteResult, error)
- func (s *Session) Resolve(file, thread string, resolved bool) (WriteResult, error)
- func (s *Session) Stop() error
- func (s *Session) Temporary() bool
- type TooLargeError
- type WriteResult
Constants ¶
const MaxFiles = 20
MaxFiles is how many files one session shares, the first included.
Variables ¶
var ErrAmbiguousThread = errors.New("threads of several files have that id: name the file")
ErrAmbiguousThread means threads of several files have the id asked for.
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 ErrHostAway = errors.New("the host is away: a comment link cannot comment until the host is back, and no room takes comments in the minutes before it is kept")
ErrHostAway means a guest's comment cannot reach the host now: the room is kept and the guest has a comment link, or the host dropped and the room is not kept (yet).
var ErrNoComments = errors.New("no file of the room offers comments")
ErrNoComments means no file of the room offers comments.
var ErrNoFile = errors.New("no file of the room at that path offers comments")
ErrNoFile means the room shares no file at that path, or it offers no comments.
var ErrNoSavedComments = errors.New("no comments are saved for it")
ErrNoSavedComments means no comments were saved for a file: none were made, or the host never ran on it.
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 ¶
func CloseKept ¶ added in v0.3.0
func CloseKept(ctx context.Context, opts KeptTextOptions) error
CloseKept takes in the edits of a room kept by the relay, writes them to the files, and ends the room, which removes its link and its record. Source changes made outside this session are refused rather than overwritten.
func PruneKept ¶ added in v0.3.0
PruneKept removes, without asking the relay, the records in project of rooms past their deadline (by more than expiredGrace) and of the older kind of kept room, which was taken in by polling and can no longer be resumed. A record with a write to finish stays. It tells notify how many it removed.
func ReadSavedComments ¶ added in v0.5.1
ReadSavedComments reads the comments the host saved last for file, in the project at projectDir, as the host reads them: through the project's real directories, with the checks of meta.Parse. It writes nothing (docs/design/comments-cli.md, listing without a session).
Types ¶
type CommentChange ¶ added in v0.5.1
CommentChange is a change to the comments of one of the room's files, as the room shows its path (docs/design/comments-cli.md).
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 FileThreads ¶ added in v0.5.1
FileThreads are the threads on one of the room's files, as the room shows its path.
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. A
// comment link edits nothing, so its copies are not watched.
Watch bool
// OnComments is as in Options.
OnComments func(CommentChange)
// 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)
// OnKept is called with the time a kept room stays open until, before
// OnStatus reports it kept.
OnKept func(time.Time)
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 KeptTextOptions ¶ added in v0.2.0
type KeptTextOptions struct {
File, Project, Resume string
OnSkipped func(int)
// OnImageError reports an image a kept text refers to that could not be
// saved beside its file (once per image and file).
OnImageError func(path string, err error)
// Dial connects to the relay, to take in a live room (kept_away_resume.go).
Dial protocol.Dialer
}
KeptTextOptions says which kept room CloseKept, or the resume of a session, is about.
type KeptTextRecord ¶ added in v0.3.0
type KeptTextRecord struct {
Room string
Paths []string // display paths of the shared files
Files []string // their absolute paths on disk
Until int64 // relay deadline in Unix ms; 0 if unknown
}
KeptTextRecord summarizes a resume record of a project, without its secrets.
func ListKeptText ¶ added in v0.3.0
func ListKeptText(project string) ([]KeptTextRecord, error)
ListKeptText returns the resume records of project, soonest deadline first. Records that cannot be parsed, and those of the older polling kind of kept room, are left out.
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" // CommentsOff means the file offers no comments in the room, for Reason, // such as being outside the project or its metadata not being readable. CommentsOff NoticeKind = "comments-off" // CommentsHeld means the file that keeps the comments of a shared file // (File) changed outside pedit, so pedit no longer saves comments to it. CommentsHeld NoticeKind = "comments-held" )
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
// Project is the directory whose .pedit/meta/ keeps the comments of the
// files inside it (#121). Empty: no file offers comments.
Project 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)
// OnComments is called, one at a time and in order, with each change to
// the comments of the room's files once the session holds it, its own
// included; not with the comments there when a file was added. It must
// not call into the Session.
OnComments func(CommentChange)
// Keep asks the relay to keep the room open for this long after the host
// leaves on purpose (docs/design/rooms-away.md), and has Start write the
// record that pedit resume takes the room up again by. More are the files to
// share with the first, so the record lists them all.
Keep time.Duration
More []string
// Resume is the ID of a room Keep left a record of in Project: Start
// takes in what was written while the host was away, then goes on
// sharing the record's files in that room. File, More and Server are
// the record's.
Resume string
// OnKeep is called with the seconds the relay keeps the room, which may be
// less than asked, or 0 if it cannot keep it (it speaks version 5).
OnKeep func(seconds int64)
// OnSkipped is called with how many entries guests wrote that were
// refused, in all; OnImageError with an image of a replayed edit that
// could not be saved.
OnSkipped func(int)
OnImageError func(path string, err 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) Comments ¶ added in v0.5.1
func (s *Session) Comments() []FileThreads
Comments lists the threads of every file that offers comments, as the browser lists them.
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.
func (*Session) KeptUntil ¶ added in v0.3.0
KeptUntil is when the relay ends the room, if it keeps it now that the host has left, or the zero time if it does not.
func (*Session) Links ¶ added in v0.1.18
Links are the links to the room with less access than the host's (#122): comment only, while some file offers comments, then read only. They come from the fragments the host's keys derive, and like URL hold secrets that must never be sent to the server.
func (*Session) Reply ¶ added in v0.5.1
func (s *Session) Reply(file, thread, id, body string) (WriteResult, error)
Reply adds a comment to a thread, under id, signed with the session's name. file names the thread's file, or is empty to look in every file. A reply the thread holds already is not written again.
func (*Session) Resolve ¶ added in v0.5.1
func (s *Session) Resolve(file, thread string, resolved bool) (WriteResult, error)
Resolve resolves a thread, or reopens it.
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
type WriteResult ¶ added in v0.5.1
type WriteResult struct {
Delivered bool
}
WriteResult says how far a write from the command line got. Delivered is set once the host has it: at once for the host itself.