server¶
Index¶
- Constants
- func NewHandler(hub *Hub) http.Handler
- type Client
- func (c *Client) Info() ClientInfo
- func (c *Client) ReadPump()
- func (c *Client) WritePump()
- type ClientInfo
- type ClientMessage
- type Hub
- func NewHub(st store.DocumentStore, engine ot.Engine) *Hub
- func (h *Hub) GetSession(docID string) *Session
- func (h *Hub) Run()
- type ServerMessage
- func (m ServerMessage) Encode() []byte
- type Session
- func (s *Session) Run()
Constants¶
Message types exchanged over WebSocket.
const (
MsgJoin = "join"
MsgLeave = "leave"
MsgOp = "op"
MsgAck = "ack"
MsgDoc = "doc"
MsgError = "error"
)
func NewHandler¶
NewHandler creates the HTTP handler with all routes.
type Client¶
Client represents a single WebSocket connection.
func (*Client) Info¶
func (*Client) ReadPump¶
ReadPump reads messages from the WebSocket and routes them.
func (*Client) WritePump¶
WritePump writes messages from the send channel to the WebSocket.
type ClientInfo¶
ClientInfo describes a connected user.
type ClientInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Color string `json:"color"`
}
type ClientMessage¶
ClientMessage is a message from client to server.
type ClientMessage struct {
Type string `json:"type"`
DocID string `json:"docId,omitempty"`
Revision int `json:"revision"`
Op ot.Operation `json:"op,omitempty"`
}
type Hub¶
Hub manages document sessions and routes clients to the right session.
func NewHub¶
func (*Hub) GetSession¶
GetSession returns the session for a document, if active.
func (*Hub) Run¶
Run is the hub's main loop.
type ServerMessage¶
ServerMessage is a message from server to client.
type ServerMessage struct {
Type string `json:"type"`
DocID string `json:"docId,omitempty"`
Content string `json:"content"`
Revision int `json:"revision"`
Op ot.Operation `json:"op,omitempty"`
ClientID string `json:"clientId,omitempty"`
Name string `json:"name,omitempty"`
Color string `json:"color,omitempty"`
Message string `json:"message,omitempty"`
Clients []ClientInfo `json:"clients,omitempty"`
}
func (ServerMessage) Encode¶
Encode serializes a ServerMessage to JSON bytes.
type Session¶
Session manages collaboration for a single document. All operations are serialized through a single goroutine.
func (*Session) Run¶
Run is the session's main loop. It serializes all operations.
Generated by gomarkdoc