ws

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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, 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) 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
}

func NewChannelOperator

func NewChannelOperator(p *PadMessageHandler) ChannelOperator

func (*ChannelOperator) AddToQueue

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

type Client

type Client struct {
	Hub *Hub
	// The websocket connection.
	Conn WebSocketConn
	// Buffered channel of outbound messages.
	Send          chan []byte
	Room          string
	SessionId     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) 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) 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) DeletePad added in v0.0.2

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

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) 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) HandleSavedRevisionMessage added in v0.0.4

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

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) UpdatePadClients added in v0.0.2

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

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 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