collab

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventSync         = "file collab sync"
	EventUpdate       = "file collab update"
	EventAwareness    = "file collab awareness"
	EventParticipants = "file collab participants"
	EventSaved        = "file collab saved"
	EventConflict     = "file collab conflict"
	EventError        = "file collab error"
)

Outbound message events (Calagopus-compatible names).

View Source
const (
	EventSubscribe   = "file collab subscribe"
	EventUnsubscribe = "file collab unsubscribe"
	EventUpdateIn    = "file collab update"
	EventAwarenessIn = "file collab awareness"
	EventSave        = "file collab save"
	EventReload      = "file collab reload"
)

Inbound message events.

View Source
const (
	PermissionReadContent = "file.read-content"
	PermissionUpdate      = "file.update"
)

Permission strings expected on the websocket JWT.

Variables

View Source
var (
	ErrDisabled          = errors.New("collaborative editing is disabled")
	ErrNotSubscribed     = errors.New("not subscribed to this file")
	ErrFileNotFound      = errors.New("file not found")
	ErrNotAFile          = errors.New("file is not a file")
	ErrNotEditable       = errors.New("file is not editable as text")
	ErrTooLarge          = errors.New("file is too large for collaborative editing")
	ErrInvalidUpdate     = errors.New("invalid update encoding")
	ErrTooManySessions   = errors.New("too many collaborative sessions open on this server")
	ErrTooManyConnSubs   = errors.New("too many collaborative sessions open on this connection")
	ErrTooManyEditors    = errors.New("too many editors open for this file on this connection")
	ErrEditorIDTooLong   = errors.New("editor id is too long")
	ErrNoParent          = errors.New("file has no parent")
	ErrInvalidFileName   = errors.New("invalid file name")
	ErrAllocateSpace     = errors.New("failed to allocate space")
	ErrMissingPermission = errors.New("missing permission")
)

Functions

func UserError

func UserError(err error) bool

UserError returns true when err is a client-facing collab error.

Types

type Conflict

type Conflict struct {
	Hash    *string `json:"hash"`
	Deleted bool    `json:"deleted"`
}

Conflict describes an on-disk conflict for a collab session.

type HistoryRecorder

type HistoryRecorder interface {
	RecordEdit(path string, before, after []byte, userUUID string) (int64, error)
	Enabled() bool
	FileSizeCap() uint64
}

HistoryRecorder receives successful collaborative file saves.

type Manager

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

Manager hosts collaborative editing sessions for one game server.

func NewManager

func NewManager(serverUUID string, fs *filesystem.Filesystem, ctx context.Context, logger *log.Entry, history HistoryRecorder) *Manager

func (*Manager) ApplyUpdate

func (m *Manager) ApplyUpdate(connectionID uuid.UUID, rawPath string, finished bool, chunk, editor string) error

ApplyUpdate applies a (possibly chunked) Yjs update from a client.

func (*Manager) Disconnect

func (m *Manager) Disconnect(connectionID uuid.UUID)

Disconnect removes a connection and leaves all of its collab sessions.

func (*Manager) Register

func (m *Manager) Register(connectionID uuid.UUID, sender Sender)

Register attaches a websocket sender for a connection.

func (*Manager) RelayAwareness

func (m *Manager) RelayAwareness(connectionID uuid.UUID, rawPath, payload string) error

RelayAwareness relays cursor/presence awareness to other editors.

func (*Manager) Reload

func (m *Manager) Reload(connectionID uuid.UUID, rawPath string) error

Reload reloads session content from disk and forces clients to resync.

func (*Manager) Save

func (m *Manager) Save(connectionID uuid.UUID, userUUID, rawPath string, force bool, expectedHash string) error

Save writes the collaborative document to disk.

func (*Manager) Subscribe

func (m *Manager) Subscribe(connectionID uuid.UUID, userUUID, userName string, avatar *string, rawPath, editor string) error

Subscribe joins a collaborative editing session for a file.

func (*Manager) Unsubscribe

func (m *Manager) Unsubscribe(connectionID uuid.UUID, rawPath, editor string) error

Unsubscribe leaves a collaborative editing session.

type Message

type Message struct {
	Event string
	Args  []string
}

Message is a websocket payload delivered to a specific connection.

type Participant

type Participant struct {
	User   string  `json:"user"`
	Name   string  `json:"name"`
	Avatar *string `json:"avatar"`
}

Participant is someone currently editing a file.

type Saved

type Saved struct {
	User       string `json:"user"`
	RevisionID *int64 `json:"revision_id"`
}

Saved notifies clients that a collaborative save completed.

type Sender

type Sender func(Message)

Sender delivers a collab message to one websocket connection.

type SyncMeta

type SyncMeta struct {
	Dirty    bool      `json:"dirty"`
	Conflict *Conflict `json:"conflict"`
}

SyncMeta is attached to a sync payload.

Jump to

Keyboard shortcuts

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