ws

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeClientVarsExtra added in v0.6.5

func MergeClientVarsExtra(cv *clientVars.ClientVars, extra map[string]any) (map[string]any, error)

MergeClientVarsExtra serializes cv to a top-level JSON object and overlays the keys from extra that the typed struct does not already own. On collision the typed field wins, so plugins cannot clobber engine-owned CLIENT_VARS keys.

func ServeAdminWs added in v0.0.2

func ServeAdminWs(conn *websocket.Conn, configSettings *settings.Settings, logger *zap.SugaredLogger, handler AdminMessageHandler)

ServeAdminWs handles admin websocket requests using Fiber's websocket middleware.

func ServeWs

func ServeWs(conn *websocket.Conn, sessionID string, integratorSessionID string, clientIP string, webAccessUser any,
	configSettings *settings.Settings,
	logger *zap.SugaredLogger, handler *PadMessageHandler)

ServeWs handles websocket requests from the peer using Fiber's websocket middleware.

Types

type AcceptCommitData

type AcceptCommitData struct {
	Type   string `json:"type"`
	NewRev int    `json:"newRev"`
}

type AcceptCommitMessage

type AcceptCommitMessage struct {
	Type string           `json:"type"`
	Data AcceptCommitData `json:"data"`
}

type AccessStatusMessage

type AccessStatusMessage struct {
	AccessStatus string `json:"accessStatus"`
}

type AdminMessageHandler added in v0.0.2

type AdminMessageHandler struct {
	Logger *zap.SugaredLogger
	App    *fiber.App
	// contains filtered or unexported fields
}

func NewAdminMessageHandler added in v0.0.2

func NewAdminMessageHandler(store db.DataStore, h *hooks.Hook, m *pad.Manager, padMessHandler *PadMessageHandler, logger *zap.SugaredLogger, hub *Hub, app *fiber.App, upd *updater.Updater) AdminMessageHandler

func (AdminMessageHandler) DeleteRevisions added in v0.0.2

func (h AdminMessageHandler) DeleteRevisions(padId string, keepRevisions int) error

func (AdminMessageHandler) HandleMessage added in v0.0.2

func (h AdminMessageHandler) HandleMessage(message admin.EventMessage, retrievedSettings *settings.Settings, c *Client)

type AuthSession

type AuthSession struct {
	PadID         string
	Token         string
	ReadOnlyPadId *string
	ReadOnly      bool
}

type ChangesetInfo added in v0.0.2

type ChangesetInfo struct {
	ForwardsChangesets  []string    `json:"forwardsChangesets"`
	BackwardsChangesets []string    `json:"backwardsChangesets"`
	ActualEndNum        int         `json:"actualEndNum"`
	TimeDeltas          []int64     `json:"timeDeltas"`
	Start               int         `json:"start"`
	Granularity         int         `json:"granularity"`
	APool               apool.APool `json:"apool"`
	RequestId           int         `json:"requestID"`
}

type ChangesetResponse added in v0.0.2

type ChangesetResponse struct {
	Type string        `json:"type"`
	Data ChangesetInfo `json:"data"`
}

type ChannelOperator

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

ChannelOperator processes USER_CHANGES.

It used to start one goroutine per pad that was never stopped, so every pad ever edited leaked a goroutine and its channel. Now each task runs on the sending client's read loop while handleUserChanges holds the pad's write lock. That keeps commits of one client in order, serialises commits per pad (also against HTTP API writes, which take the same lock) and leaves nothing running once the pad is idle.

func NewChannelOperator

func NewChannelOperator(p *PadMessageHandler) ChannelOperator

func (*ChannelOperator) AddToQueue

func (c *ChannelOperator) AddToQueue(_ string, t Task)

AddToQueue handles the task synchronously. The room argument is kept for compatibility; serialisation is keyed by the session's pad ID.

type Client

type Client struct {
	Hub *Hub
	// The websocket connection.
	Conn WebSocketConn
	// Buffered channel of outbound messages.
	Send      chan []byte
	Room      string
	SessionId string
	// IntegratorSessionID carries the integrator-set sessionID cookie
	// value (from createSession() HTTP API), read from the socket.io
	// handshake so the cookie can be HttpOnly. Upstream #7045 / #7755.
	IntegratorSessionID string

	ClientIP      string
	WebAccessUser any
	Handler       *PadMessageHandler
	// contains filtered or unexported fields
}

Client is a middleman between the websocket connection and the hub.

func (*Client) Leave

func (c *Client) Leave()

func (*Client) SafeSend added in v0.0.2

func (c *Client) SafeSend(message []byte) (sent bool)

SafeSend sends a message to the client, returning false if the channel is closed.

func (*Client) SendPadDelete

func (c *Client) SendPadDelete()

func (*Client) SendUserDupMessage

func (c *Client) SendUserDupMessage()

type ClientReconnectData added in v0.0.2

type ClientReconnectData struct {
	Type        string      `json:"type"`
	HeadRev     int         `json:"headRev,omitempty"`
	NewRev      int         `json:"newRev"`
	Changeset   string      `json:"changeset,omitempty"`
	APool       apool.APool `json:"apool,omitempty"`
	Author      string      `json:"author,omitempty"`
	CurrentTime int64       `json:"currentTime,omitempty"`
	NoChanges   bool        `json:"noChanges,omitempty"`
}

type ClientReconnectMessage added in v0.0.2

type ClientReconnectMessage struct {
	Type string              `json:"type"`
	Data ClientReconnectData `json:"data"`
}

type Hub

type Hub struct {
	// Registered Clients.
	Clients        map[*Client]bool
	ClientsRWMutex sync.RWMutex

	// Inbound messages from the Clients.
	Broadcast chan []byte

	// Register requests from the Clients.
	Register chan *Client

	// Unregister requests from Clients.
	Unregister chan *Client
}

Hub maintains the set of active Clients and broadcasts messages to the Clients.

func NewHub

func NewHub() *Hub

func (*Hub) BroadcastShout added in v0.6.5

func (h *Hub) BroadcastShout(message string, sticky bool)

BroadcastShout sends a sticky/non-sticky notice to every connected client using the same COLLABROOM/result:shout envelope the admin "shout" command uses. Used by the updater to announce an imminent restart during draining.

func (*Hub) Run

func (h *Hub) Run()

type LineChange added in v0.0.2

type LineChange struct {
	Alines    []string
	TextLines []string
}

type Message

type Message struct {
	Data clientVars2.ClientVars `json:"data"`
	Type string                 `json:"type"`
}

type MockWebSocketConn added in v0.0.2

type MockWebSocketConn struct {
	Data []WebSocketConnData
	// contains filtered or unexported fields
}

func NewActualMockWebSocketconn added in v0.0.2

func NewActualMockWebSocketconn() *MockWebSocketConn

func (*MockWebSocketConn) Close added in v0.0.2

func (m *MockWebSocketConn) Close() error

func (*MockWebSocketConn) NextWriter added in v0.0.2

func (m *MockWebSocketConn) NextWriter(messageType int) (io.WriteCloser, error)

func (*MockWebSocketConn) ReadMessage added in v0.0.2

func (m *MockWebSocketConn) ReadMessage() (messageType int, p []byte, err error)

func (*MockWebSocketConn) RemoteAddr added in v0.0.2

func (m *MockWebSocketConn) RemoteAddr() net.Addr

func (*MockWebSocketConn) SetPongHandler added in v0.0.2

func (m *MockWebSocketConn) SetPongHandler(h func(appData string) error)

func (*MockWebSocketConn) SetReadDeadline added in v0.0.2

func (m *MockWebSocketConn) SetReadDeadline(t time.Time) error

func (*MockWebSocketConn) SetReadLimit added in v0.0.2

func (m *MockWebSocketConn) SetReadLimit(size int64)

func (*MockWebSocketConn) SetWriteDeadline added in v0.0.2

func (m *MockWebSocketConn) SetWriteDeadline(t time.Time) error

func (*MockWebSocketConn) WriteControl added in v0.0.2

func (m *MockWebSocketConn) WriteControl(messageType int, data []byte, deadline time.Time) error

func (*MockWebSocketConn) WriteMessage added in v0.0.2

func (m *MockWebSocketConn) WriteMessage(messageType int, data []byte) error

type NewChangesMessage

type NewChangesMessage struct {
	Type string                `json:"type"`
	Data NewChangesMessageData `json:"data"`
}

type NewChangesMessageData

type NewChangesMessageData struct {
	Type        string      `json:"type"`
	NewRev      int         `json:"newRev"`
	Changeset   string      `json:"changeset"`
	APool       apool.APool `json:"apool"`
	Author      string      `json:"author"`
	CurrentTime int64       `json:"currentTime"`
	TimeDelta   int64       `json:"timeDelta"`
}

type PadDelete

type PadDelete struct {
	Type string `json:"type"`
	Data struct {
		PadID string `json:"padId"`
	}
}

type PadDeleteMessage

type PadDeleteMessage struct {
	Disconnect string `json:"disconnect"`
}

type PadMessageHandler added in v0.0.2

type PadMessageHandler struct {
	SessionStore *SessionStore

	Logger *zap.SugaredLogger
	// contains filtered or unexported fields
}

func NewPadMessageHandler added in v0.0.2

func NewPadMessageHandler(db db2.DataStore, hooks *hooks.Hook, padManager *pad.Manager, sessionStore *SessionStore, hub *Hub, logger *zap.SugaredLogger, uiAssets embed.FS) *PadMessageHandler

func (*PadMessageHandler) BroadcastSheetReload added in v0.6.5

func (p *PadMessageHandler) BroadcastSheetReload(padId string)

BroadcastSheetReload tells every client of a sheet to re-fetch its state (used after an xlsx import replaces the workbook).

func (*PadMessageHandler) BroadcastSocketEvent added in v0.5.0

func (p *PadMessageHandler) BroadcastSocketEvent(event string, payload interface{})

func (*PadMessageHandler) BroadcastSystemChatToRoom added in v0.5.0

func (p *PadMessageHandler) BroadcastSystemChatToRoom(padId string, message map[string]any)

BroadcastSystemChatToRoom sends a chat message to all clients in a pad room without saving to the database. The message map is sent as-is inside a CHAT_MESSAGE COLLABROOM event.

func (*PadMessageHandler) ComposePadChangesets added in v0.0.2

func (p *PadMessageHandler) ComposePadChangesets(retrievedPad *pad2.Pad, startNum int, endNum int) (string, error)

func (*PadMessageHandler) CorrectMarkersInPadForTest added in v0.6.3

func (p *PadMessageHandler) CorrectMarkersInPadForTest(atext apool.AText, pool apool.APool) *string

CorrectMarkersInPadForTest exposes correctMarkersInPad for tests.

func (*PadMessageHandler) DeletePad added in v0.0.2

func (p *PadMessageHandler) DeletePad(padId string) error

func (*PadMessageHandler) EnqueueSheetOp added in v0.6.5

func (p *PadMessageHandler) EnqueueSheetOp(client *Client, msg ws.SheetOpIncoming)

EnqueueSheetOp routes a SHEET_OP to the per-document serialization goroutine. Keyed by the session's pad id so each document keeps a total order.

func (*PadMessageHandler) GetPadUsers added in v0.0.5

func (p *PadMessageHandler) GetPadUsers(padId string) []PadUserInfo

GetPadUsers returns the list of users currently in a pad

func (*PadMessageHandler) GetPadUsersCount added in v0.0.5

func (p *PadMessageHandler) GetPadUsersCount(padId string) int

GetPadUsersCount returns the number of users currently in a pad

func (*PadMessageHandler) GetRoomSockets added in v0.0.2

func (p *PadMessageHandler) GetRoomSockets(padID string) []Client

func (*PadMessageHandler) HandleChangesetRequest added in v0.0.2

func (p *PadMessageHandler) HandleChangesetRequest(socket *Client, message ws.ChangesetReq)

func (*PadMessageHandler) HandleClientMessage added in v0.6.3

func (p *PadMessageHandler) HandleClientMessage(message ws.ClientMessage, client *Client, session *ws.Session)

HandleClientMessage handles the COLLABROOM CLIENT_MESSAGE family, mirroring the original's handleSuggestUserName / handlePadOptionsMessage.

func (*PadMessageHandler) HandleClientReadyMessage added in v0.0.2

func (p *PadMessageHandler) HandleClientReadyMessage(ready ws.ClientReady, client *Client, thisSession *ws.Session, retrievedSettings *settings.Settings, logger *zap.SugaredLogger)

func (*PadMessageHandler) HandleDisconnectOfPadClient added in v0.0.2

func (p *PadMessageHandler) HandleDisconnectOfPadClient(client *Client, settings *settings.Settings, logger *zap.SugaredLogger)

func (*PadMessageHandler) HandleMessage added in v0.0.2

func (p *PadMessageHandler) HandleMessage(message any, client *Client, retrievedSettings *settings.Settings, logger *zap.SugaredLogger)

func (*PadMessageHandler) HandlePadDelete added in v0.0.2

func (p *PadMessageHandler) HandlePadDelete(client *Client, padDeleteMessage PadDelete)

func (*PadMessageHandler) HandlePresence added in v0.6.5

func (p *PadMessageHandler) HandlePresence(client *Client, msg ws.SheetPresenceIncoming)

HandlePresence relays an ephemeral cursor / live-edit frame to the other clients of the sheet. It is NOT persisted and NOT ordered through the per-doc goroutine. Identity is stamped server-side from the session author (no client spoofing); read-only sessions may move a cursor but never broadcast a live edit.

func (*PadMessageHandler) HandleSavedRevisionMessage added in v0.0.4

func (p *PadMessageHandler) HandleSavedRevisionMessage(foundPad *pad2.Pad, author string)

func (*PadMessageHandler) HandleSheetClientReady added in v0.6.5

func (p *PadMessageHandler) HandleSheetClientReady(ready ws.ClientReady, client *Client, session *ws.Session)

HandleSheetClientReady materializes the pad as a sheet, then either sends the full SHEET_VARS snapshot (fresh connect) or the missed ops (reconnect), and announces presence to the other clients of the document.

func (*PadMessageHandler) HandleUserInfoUpdate added in v0.0.2

func (p *PadMessageHandler) HandleUserInfoUpdate(userInfo UserInfoUpdate, client *Client)

func (*PadMessageHandler) KickSessionsFromPad added in v0.0.2

func (p *PadMessageHandler) KickSessionsFromPad(padID string)

func (*PadMessageHandler) SendChatMessageToPadClients added in v0.0.2

func (p *PadMessageHandler) SendChatMessageToPadClients(session *ws.Session, chatMessage ws.ChatMessageData)

func (*PadMessageHandler) SendCustomMessageToPad added in v0.6.3

func (p *PadMessageHandler) SendCustomMessageToPad(padId string, msgType string)

SendCustomMessageToPad broadcasts a custom COLLABROOM message type to all clients of a pad, mirroring the original handleCustomMessage (backing the sendClientsMessage HTTP API).

func (*PadMessageHandler) SetRetention added in v0.6.8

func (p *PadMessageHandler) SetRetention(retention *pad.Retention)

func (*PadMessageHandler) SheetManager added in v0.6.5

func (p *PadMessageHandler) SheetManager() *sheetdoc.Manager

SheetManager exposes the shared sheet document manager so HTTP handlers (xlsx import/export) operate on the same live state as the websocket clients.

func (*PadMessageHandler) UpdatePadClients added in v0.0.2

func (p *PadMessageHandler) UpdatePadClients(pad *pad2.Pad)

UpdatePadClients sends every client of the pad the revisions it hasn't seen yet (NEW_CHANGES).

type PadUserInfo added in v0.0.5

type PadUserInfo struct {
	AuthorId string
	ColorId  string
	Name     string
}

PadUserInfo represents a user in a pad

type SavedRevision added in v0.0.4

type SavedRevision struct {
	Event string            `json:"event"`
	Data  SavedRevisionData `json:"data"`
}

type SavedRevisionData added in v0.0.4

type SavedRevisionData struct {
	Type      string                `json:"type"`
	Component string                `json:"component"`
	Data      SavedRevisionDataData `json:"data"`
}

type SavedRevisionDataData added in v0.0.4

type SavedRevisionDataData struct {
	Type string `json:"type"`
}

type SessionInfo

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

type SessionStat added in v0.0.5

type SessionStat struct {
	ActivePads  int
	ActiveUsers int
}

type SessionStore

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

func NewSessionStore

func NewSessionStore() SessionStore

NewSessionStore erstellt einen neuen Session-Store

func (*SessionStore) AddHandleClientInformationForTest added in v0.0.2

func (s *SessionStore) AddHandleClientInformationForTest(sessionId string, padId string, token string) *ws.Session

AddHandleClientInformationForTest adds client information for testing

func (*SessionStore) AddPadReadOnlyIdsForTest added in v0.0.2

func (s *SessionStore) AddPadReadOnlyIdsForTest(sessionId, padId string, readOnlyPadId string, readOnly bool)

AddPadReadOnlyIdsForTest adds pad read-only IDs for testing

func (*SessionStore) GetPadSessions added in v0.0.5

func (s *SessionStore) GetPadSessions(padId string) []PadUserInfo

GetPadSessions returns all sessions for a given pad (only author IDs)

func (*SessionStore) GetPadSessionsCount added in v0.0.5

func (s *SessionStore) GetPadSessionsCount(padId string) int

GetPadSessionsCount returns the count of users in a given pad

func (*SessionStore) GetSessionForTest added in v0.0.2

func (s *SessionStore) GetSessionForTest(sessionId string) *ws.Session

GetSessionForTest returns a session for testing

func (*SessionStore) GetStats added in v0.0.5

func (s *SessionStore) GetStats() (SessionStat, error)

func (*SessionStore) InitSessionForTest added in v0.0.2

func (s *SessionStore) InitSessionForTest(sessionId string)

InitSessionForTest initializes a session for testing

func (*SessionStore) RemoveSessionForTest added in v0.0.2

func (s *SessionStore) RemoveSessionForTest(sessionId string)

RemoveSessionForTest removes a session for testing

func (*SessionStore) SetAuthorForTest added in v0.0.2

func (s *SessionStore) SetAuthorForTest(sessionId string, authorId string)

SetAuthorForTest sets the author for a session for testing

func (*SessionStore) SetPadIdForTest added in v0.0.2

func (s *SessionStore) SetPadIdForTest(sessionId string, padId string)

SetPadIdForTest sets the pad ID for a session for testing

func (*SessionStore) SetReadOnlyForTest added in v0.0.2

func (s *SessionStore) SetReadOnlyForTest(sessionId string, readOnly bool)

SetReadOnlyForTest sets the read-only flag for a session for testing

func (*SessionStore) SetRevisionForTest added in v0.0.2

func (s *SessionStore) SetRevisionForTest(sessionId string, revision int)

SetRevisionForTest sets the revision for a session for testing

type SheetChannelOperator added in v0.6.5

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

SheetChannelOperator serializes SHEET_OPs per sheet document. Like ChannelOperator it runs each op on the sender's read loop under the document's write lock instead of keeping a goroutine per document alive forever; apply and broadcast stay in one total order per document.

func NewSheetChannelOperator added in v0.6.5

func NewSheetChannelOperator(p *PadMessageHandler) SheetChannelOperator

func (*SheetChannelOperator) AddToQueue added in v0.6.5

func (c *SheetChannelOperator) AddToQueue(ch string, t SheetTask)

type SheetTask added in v0.6.5

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

SheetTask is one queued SHEET_OP awaiting serialized processing per document.

type Task

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

type UserDupMessage

type UserDupMessage struct {
	Disconnect string `json:"disconnect"`
}

type UserInfoUpdate

type UserInfoUpdate struct {
	Type string `json:"type"`
	Data struct {
		UserInfo struct {
			ColorId *string `json:"colorId"`
			IP      *string `json:"ip"`
			Name    *string `json:"name"`
			UserId  *string `json:"userId"`
		} `json:"userInfo"`
		Type string `json:"type"`
	} `json:"data"`
}

type UserInfoUpdateWrapper

type UserInfoUpdateWrapper struct {
	Event string         `json:"event"`
	Data  UserInfoUpdate `json:"data"`
}

type WebSocketConn added in v0.0.2

type WebSocketConn interface {
	ReadMessage() (messageType int, p []byte, err error)
	WriteMessage(messageType int, data []byte) error
	Close() error
	SetWriteDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetPongHandler(h func(appData string) error)
	WriteControl(messageType int, data []byte, deadline time.Time) error
	RemoteAddr() net.Addr
	SetReadLimit(size int64)
	NextWriter(messageType int) (io.WriteCloser, error)
}

func NewMockWebSocketConn added in v0.0.2

func NewMockWebSocketConn() WebSocketConn

func NewWebSocketWrapper added in v0.0.2

func NewWebSocketWrapper(conn *websocket.Conn) WebSocketConn

type WebSocketConnData added in v0.0.2

type WebSocketConnData struct {
	Data []byte
	// contains filtered or unexported fields
}

type WebSocketWrapper added in v0.0.2

type WebSocketWrapper struct {
	*websocket.Conn
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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