y_websocket_server_go

package module
v0.0.0-...-d916251 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

README

y_websocket_server_go

A backend for y-websocket written in Go (with Cgo)

!! Does not support Awareness yet

Getting Started:

  1. To build from source you'll need toolchains for Go, Rust and C. Also make sure you have the y-crdt git submodule checked out.

  2. Run setup-ffi.sh from the root of the repo to build y-crdt. The build artifacts will be copied to the yjs folder.

  3. To start the server you can simply run the following from the root of the repo.

    go run ./cmd/y_websocket_server_go/main.go localhost:1234

TODO

  1. grep -rin TODO
  2. Support for Awareness
  3. Benchmark and optimize code (especially the Cgo code)

License

AGPL-3.0

Documentation

Index

Constants

View Source
const (
	WbMsgSync      uint64 = 0
	WbMsgAwareness uint64 = 1
	WbMsgAuth      uint64 = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server handles WebSocket connections for Yjs documents.

func NewServer

func NewServer(logger *slog.Logger) *Server

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Server) Stop

func (s *Server) Stop(ctx context.Context)

type SyncdYDoc

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

SyncdYDoc is a Yjs document stored in memory along with the connections currently editing it.

func (*SyncdYDoc) AddConn

func (s *SyncdYDoc) AddConn(wc *WebConn)

func (*SyncdYDoc) Conns

func (s *SyncdYDoc) Conns() []*WebConn

func (*SyncdYDoc) ReadSyncStep1

func (s *SyncdYDoc) ReadSyncStep1(svr io.Reader) ([]byte, error)

func (*SyncdYDoc) RemoveConn

func (s *SyncdYDoc) RemoveConn(wc *WebConn)

func (*SyncdYDoc) WriteSyncStep1

func (s *SyncdYDoc) WriteSyncStep1() []byte

func (*SyncdYDoc) WriteUpdate

func (s *SyncdYDoc) WriteUpdate(update []byte, origin string)

type SyncdYDocMap

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

YDocMap stores the Yjs document by id.

func NewSyncdYDocMap

func NewSyncdYDocMap() *SyncdYDocMap

NewSyncdYDocMap creates a new SyncdYDocMap.

func (*SyncdYDocMap) GetOrCreate

func (sm *SyncdYDocMap) GetOrCreate(id string) *SyncdYDoc

type WebConn

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

WebConn represents a WebSocket connection

func (*WebConn) Start

func (wc *WebConn) Start()

Start begins handling the WebSocket connections for the ysjs document with the given ID.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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