Documentation ¶
Index ¶
- func NewServer(srv *environment.Services) *http.Server
- type Link
- type Message
- type MessageType
- type NotifyMessage
- type ProsemirrorCustomStep
- type ProsemirrorImageStep
- type ProsemirrorInfoResponse
- type ProsemirrorInitMessage
- type ProsemirrorMark
- type ProsemirrorMarkStep
- type ProsemirrorReplaceStep
- type ProsemirrorStepContent
- type ProsemirrorStepMessage
- type ProsemirrorStepResponse
- type Registration
- type Response
- type WebsocketClient
- type WebsocketHub
- type WebsocketRoom
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Message ¶
type Message struct { Type MessageType `json:"type,omitempty"` Payload json.RawMessage `json:"payload"` Raw []byte `json:"--"` // internal information DocumentID string `json:"-"` // current document id UserID string `json:"-"` // current connected user Permission domain.Permission `json:"-"` // permission of the client // channel to reply to the sender Client *WebsocketClient `json:"-"` Reply chan []byte `json:"-"` }
type MessageType ¶
type MessageType string
Message types to differentiate the respective actions to take
const MessageTypeProsemirrorApproval MessageType = "prosemirror-approval"
const MessageTypeProsemirrorInit MessageType = "prosemirror-init"
const MessageTypeProsemirrorSteps MessageType = "prosemirror-steps"
const MessageTypeProsemirrorUpdate MessageType = "prosemirror-update"
const MessageTypeProssemirrorReload MessageType = "prosemirror-reload"
type NotifyMessage ¶
type NotifyMessage struct { Client *WebsocketClient Payload json.RawMessage }
NotifyMessage is used to send a message to all other clients except the sender
type ProsemirrorCustomStep ¶
type ProsemirrorCustomStep struct { Type string `json:"type"` Payload json.RawMessage `json:"payload"` }
ProsemirrorCustomStep information
type ProsemirrorImageStep ¶
type ProsemirrorInfoResponse ¶
type ProsemirrorInfoResponse struct { Type MessageType `json:"type"` Payload struct { BaseVersion int64 `json:"base_version"` Version int64 `json:"version"` } `json:"payload"` }
type ProsemirrorInitMessage ¶
type ProsemirrorInitMessage struct { DocumentID string `json:"documentid,omitempty"` DocumentSchema json.RawMessage `json:"schema,omitempty"` DocumentVersion int64 `json:"version,omitempty"` }
ProsemirrorInitMessage is used when initializing a new room
type ProsemirrorMark ¶
type ProsemirrorMarkStep ¶
type ProsemirrorMarkStep struct { Type string `json:"stepType"` From int `json:"from"` To int `json:"to"` Mark ProsemirrorMark `json:"mark"` }
ProsemirrorMarkStep information
type ProsemirrorReplaceStep ¶
type ProsemirrorReplaceStep struct { Slice struct { Content []ProsemirrorStepContent `json:"content"` } }
ProseMirrorReplaceStep is used when inserting pdf documents directly
type ProsemirrorStepContent ¶
type ProsemirrorStepContent struct { Type string `json:"type"` Attrs struct { // attributes for pdf files DocumentID string `json:"documentId"` FileName string `json:"fileName"` Src string `json:"src"` // attributes for images ImageID string `json:"imageId"` Width int `json:"width"` Height int `json:"height"` Copy bool `json:"copy"` } `json:"attrs"` Marks []*ProsemirrorMark `json:"marks,omitempty"` Content []*ProsemirrorStepContent `json:"content,omitempty"` }
ProsemirrorStepContent is used to parse subcontent of steps attributes are not parsed, as we are mainly interested in the marks
type ProsemirrorStepMessage ¶
type ProsemirrorStepMessage struct { DocumentID string `json:"documentid,omitempty"` DocumentVersion int64 `json:"version,omitempty"` ClientID int `json:"clientID,omitempty"` Steps []json.RawMessage `json:"steps,omitempty"` SaveImmediate bool `json:"save_immediate"` }
ProsemirrorStepMessage information
type ProsemirrorStepResponse ¶
type ProsemirrorStepResponse struct { Type MessageType `json:"type"` Payload struct { BaseVersion int64 `json:"base_version"` Version int64 `json:"version"` ClientIDs []int `json:"clientIds,omitempty"` Steps []json.RawMessage `json:"steps,omitempty"` FromInit bool `json:"from_init"` SaveImmediate bool `json:"save_immediate"` } `json:"payload"` }
type Registration ¶
type Registration struct { Client *WebsocketClient Done chan bool }
Registration with separate done channel to wait until registration is complete
type Response ¶
type Response struct { Type MessageType `json:"type,omitempty"` Payload interface{} `json:"payload"` }
Response sent back to the client
type WebsocketClient ¶
type WebsocketClient struct { // reference the websocket connection Conn *websocket.Conn // document is the unique id of the block that the client is working on DocumentID string DocumentSchema json.RawMessage // unique id of the respective user UserID string // Document permissions of the respective client (read, comment, edit) Permission domain.Permission // use a channel to send messages Send chan []byte // reference to the handler that will manage the message MessageHandler chan Message }
WebsocketClient information
type WebsocketHub ¶
type WebsocketHub struct { Srv *environment.Services // external services Rooms map[string]*WebsocketRoom // room for documents Register chan *Registration // register a new client Unregister chan *Registration // deregister a client }
Hub for socket handling
type WebsocketRoom ¶
type WebsocketRoom struct { Clients map[*WebsocketClient]bool Register chan *Registration // register a new client Unregister chan *Registration // deregister a client Notify chan NotifyMessage // send message to all clients except the sender Broadcast chan []byte // broadcast messages to all clients Handler chan Message // handle incoming messages DocumentID string // unique id of the respective editor content DocumentSchema json.RawMessage // schema of the respective document DocumentVersion int64 // current document version on the server }
WebsocketRoom is used to handle a single editor document