ot

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidWSMsg = errors.New("WSMessage is invalid")
)

OT Errors

Functions

This section is empty.

Types

type Client

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

Client is structure for client connection

func NewClient

func NewClient(conn *websocket.Conn, profile ClientProfile, readOnly bool) (*Client, error)

NewClient generates OTClient

func (*Client) Loop

func (cl *Client) Loop()

Loop is main loop for client

type ClientData

type ClientData struct {
	Name      string `json:"name"`
	UUID      string `json:"uuid"`
	IconURI   string `json:"icon_uri"`
	Selection Ranges `json:"selection"`
}

ClientData is structure for client information

type ClientJoinData

type ClientJoinData struct {
	ID      string `json:"id"`
	Name    string `json:"name"`
	UUID    string `json:"uuid"`
	IconURI string `json:"icon_uri"`
}

ClientJoinData is structure for client information

type ClientProfile

type ClientProfile struct {
	UUID    string
	Name    string
	IconURI string
}

ClientProfile is structure for client profile

type DocData

type DocData struct {
	Clients    map[string]ClientData `json:"clients"`
	Document   string                `json:"document"`
	Revision   int                   `json:"revision"`
	Owner      string                `json:"owner"`
	Permission int                   `json:"permission"`
	Editable   bool                  `json:"editable"`
}

DocData is structure for document data

type Manager

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

Manager is structure for ot management

func NewManager

func NewManager(db *db.DB) (*Manager, error)

NewManager creates new manager

func (*Manager) ClientConnect

func (mgr *Manager) ClientConnect(cl *Client, docid string)

ClientConnect connects client to server

func (*Manager) Loop

func (mgr *Manager) Loop()

Loop is main loop for manager

func (*Manager) StartServer

func (mgr *Manager) StartServer(docID string) error

StartServer creates new server and start main loop

func (*Manager) StopOTManager

func (mgr *Manager) StopOTManager()

StopOTManager stops manager

func (*Manager) StopOTSession added in v0.10.0

func (mgr *Manager) StopOTSession(docID string)

StopOTSession stops session

type OT

type OT struct {
	Text     string
	History  map[int]Ops
	Revision int
}

OT is structure for OT session

func NewOT

func NewOT(text string) *OT

NewOT creates OT

func (*OT) Operate

func (ot *OT) Operate(rev int, ops Ops) (Ops, error)

Operate applies OT operation

func (*OT) Transform

func (ot *OT) Transform(rev int, ops Ops) (Ops, error)

Transform converts OT operations

type Op

type Op struct {
	OpType OpType
	Len    int
	Text   string
}

Op is structure for part of OT operation

type OpData

type OpData struct {
	Revision  int
	Operation []interface{}
	Selection Ranges
}

OpData is structure for OT operation data

type OpType

type OpType int

OpType is enum of OT operation

const (
	OpTypeRetain OpType = iota
	OpTypeInsert
	OpTypeDelete
)

OpType enums

type Ops

type Ops struct {
	User string
	Ops  []Op
}

Ops is structure for OT operation

type Ranges

type Ranges struct {
	Ranges []SelData `json:"ranges"`
}

Ranges is structure for selection array data

type SelData

type SelData struct {
	Anchor int `json:"anchor"`
	Head   int `json:"head"`
}

SelData is structure for selection data

type Server

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

Server is structure for server

func NewServer

func NewServer(docID string, sv2mgr chan otServerRequest, db *db.DB) (*Server, error)

NewServer creates new server

func (*Server) Loop

func (sv *Server) Loop()

Loop is main loop for server

type WSMsg

type WSMsg struct {
	Event string          `json:"e"`
	Data  json.RawMessage `json:"d,omitempty"`
}

WSMsg is structure for websocket message

type WSMsgType

type WSMsgType int

WSMsgType is WebSocket message type

const (
	WSMsgTypeUnknown WSMsgType = iota
	WSMsgTypeDoc
	WSMsgTypeOp
	WSMsgTypeOK
	WSMsgTypeSel
	WSMsgTypeQuit
	WSMsgTypeJoin
	OTReqResTypePing
)

WSMsgType list

Jump to

Keyboard shortcuts

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