pad

package
v0.0.0-...-cea8561 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 26 Imported by: 0

README

Changeset server

For installing nodejs

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
export NVM_DIR="$HOME/.local/share/nvm"
[ -s "$NVM_DIR" ] && \. "$NVM_DIR/nvm.sh"
nvm install node

For running the server

cd server
npm install
node server.js

For regenerating the static codegen files

npm install -g grpc-tools
grpc_tools_node_protoc --js_out=import_style=commonjs,binary:./server/changesetproto/ --grpc_out=grpc_js:./server/changesetproto changeset.proto

Changeset client

For installing go

wget https://go.dev/dl/go1.20.6.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go1.20.6.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
rm go1.20.6.linux-amd64.tar.gz
go version

For running the client

cd client
go run client.go

For regenerating the static codegen files

sudo apt update
sudo apt install protobuf-compiler -y
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2
export PATH=$PATH:$(go env GOPATH)/bin
source ~/.bashrc
protoc --go_out=./changesetproto --go_opt=paths=source_relative --go-grpc_out=./changesetproto --go-grpc_opt=paths=source_relative changeset.proto

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangesetClient

type ChangesetClient struct {
	Changsetserverpath string

	Downloadeurl string
	// contains filtered or unexported fields
}

func NewChangesetClient

func NewChangesetClient(ip string, port string) *ChangesetClient

func (*ChangesetClient) Close

func (cc *ChangesetClient) Close()

func (*ChangesetClient) Connect

func (cc *ChangesetClient) Connect() error

func (*ChangesetClient) GenerateChangeset

func (cc *ChangesetClient) GenerateChangeset(oldtext string, newtext string, attribs string) (string, error)

func (*ChangesetClient) StartChangesetServer

func (cc *ChangesetClient) StartChangesetServer() error

func (*ChangesetClient) StopChangesetServer

func (cc *ChangesetClient) StopChangesetServer()

type Pad

type Pad struct {
	URL          string //"https://example.com/pad/"
	WsURL        string //"wss://example.com/pad/"
	SessionToken string
	PadId        string
	SessionID    string
	Cookie       []*http.Cookie

	ChangesetServerIP   string
	ChangesetServerPort string

	Client *goSocketio.Client

	AuthorID string
	Text     string
	Attribs  string

	BaseRev   int
	LocationX int

	ChangesetServerExternal bool
	ChangesetClient         *ChangesetClient

	ShortLanguageName string
	LanguageName      string
	// contains filtered or unexported fields
}

func NewPad

func NewPad(short, lang, url string, wsURL string, sessionToken string, padId string, sessionID string, cookie []*http.Cookie, external bool, host string, port int) *Pad

Create new pad wsURL = "wss://example.com/pad/" SessionToken = gtxiomrffih2b8qr (from bbb) padId = g.9d4O2LRqTkIfh6bM$notes (from ddp. To get it c.ddpCall(bbb.GetPadIdCall, "en")) sessionID = s.4918c0b0b9b7913b5e29334a50f58212 (from ddp. To get it padsSessionsCollection.FindAll()) cookie = client.SessionCookie

func (*Pad) Connect

func (p *Pad) Connect() error

Connect to the pad

func (*Pad) Disconnect

func (p *Pad) Disconnect()

Disconnect from the pad

func (*Pad) GetStatus

func (p *Pad) GetStatus() Status

get status

func (*Pad) OnDisconnect

func (p *Pad) OnDisconnect(f func())

func (*Pad) RegisterSession

func (p *Pad) RegisterSession() error

Register session

func (*Pad) SetText

func (p *Pad) SetText(text string) error

type ReceveClientReady

type ReceveClientReady struct {
	Data struct {
		UserID           string `json:"userId"`
		CollabClientVars struct {
			InitialAttributedText struct {
				Text    string `json:"text"`
				Attribs string `json:"attribs"`
			} `json:"initialAttributedText"`
			Rev int `json:"rev"`
		} `json:"collab_client_vars"`
	} `json:"data"`
}

Initial response from the server

type ReceveConfirmSendChar

type ReceveConfirmSendChar struct {
	Type string `json:"type"`
	Data struct {
		Type   string `json:"type"`
		NewRev int    `json:"newRev"`
	} `json:"data"`
}

Server will confim the SendChar sent by this client {"type":"COLLABROOM","data":{"type":"ACCEPT_COMMIT","newRev":1}}

type ReceveCursorPosition

type ReceveCursorPosition struct {
	Type string `json:"type"`
	Data struct {
		Type    string `json:"type"`
		Payload struct {
			Action     string `json:"action"`
			AuthorID   string `json:"authorId"`
			AuthorName string `json:"authorName"`
			PadID      string `json:"padId"`
			LocationX  int    `json:"locationX"`
			LocationY  int    `json:"locationY"`
		} `json:"payload"`
	} `json:"data"`
}

Server will send a cursor position, if a outher user moved the cursor {"type":"COLLABROOM","data":{"type":"CUSTOM","payload":{"action":"cursorPosition","authorId":"a.3JMUunbWzLnaV1Ox","authorName":"Julian","padId":"g.VPluJJUveQlgElgN$notes","locationX":0,"locationY":0}}}

type ReceveData

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

Server will send data which has a Type. To get the type use ReceveData.Data.Type {"type":"COLLABROOM","data":{"type":"ACCEPT_COMMIT",...}}

type ReceveNewUser

type ReceveNewUser struct {
	Type string `json:"type"`
	Data struct {
		Type     string `json:"type"`
		UserInfo struct {
			ColorID int    `json:"colorId"`
			Name    string `json:"name"`
			UserID  string `json:"userId"`
		} `json:"userInfo"`
	} `json:"data"`
}

Server will send a new user, if a outher user joined the pad {"type":"COLLABROOM","data":{"type":"USER_NEWINFO","userInfo":{"colorId":9,"name":"Julian","userId":"a.MO7GXKUWttjc4se8"}}}

type ReceveSendChar

type ReceveSendChar struct {
	Type string `json:"type"`
	Data struct {
		Type      string `json:"type"`
		NewRev    int    `json:"newRev"`
		Changeset string `json:"changeset"`
		Apool     struct {
			NumToAttrib struct {
				Num0 []string `json:"0"`
			} `json:"numToAttrib"`
			AttribToNum interface{} `json:"attribToNum"`
			NextNum     int         `json:"nextNum"`
		} `json:"apool"`
		Author      string `json:"author"`
		CurrentTime int64  `json:"currentTime"`
		TimeDelta   any    `json:"timeDelta"`
	} `json:"data"`
}

Server will send char, if a outher user wrote a char {"type":"COLLABROOM","data":{"type":"NEW_CHANGES","newRev":3,"changeset":"Z:3>1=2*0+1$b","apool":{"numToAttrib":{"0":["author","a.MO7GXKUWttjc4se8"]},"attribToNum":{"author,a.MO7GXKUWttjc4se8":0},"nextNum":1},"author":"a.MO7GXKUWttjc4se8","currentTime":1677492927116,"timeDelta":null}}

type SendChar

type SendChar struct {
	Type      string `json:"type"`
	Component string `json:"component"`
	Data      struct {
		Type      string `json:"type"`
		BaseRev   int    `json:"baseRev"`
		Changeset string `json:"changeset"`
		Apool     struct {
			NumToAttrib struct {
				Num0 []string `json:"0"`
			} `json:"numToAttrib"`
			NextNum int `json:"nextNum"`
		} `json:"apool"`
	} `json:"data"`
}

Send this to the Server to send a char {"type":"COLLABROOM","component":"pad","data":{"type":"USER_CHANGES","baseRev":0,"changeset":"Z:1>1*0+1$h","apool":{"numToAttrib":{"0":["author","a.3JMUunbWzLnaV1Ox"]},"nextNum":1}}}

type SendCursorPosition

type SendCursorPosition struct {
	Type      string `json:"type"`
	Component string `json:"component"`
	Data      struct {
		Type       string `json:"type"`
		Action     string `json:"action"`
		LocationY  int    `json:"locationY"`
		LocationX  int    `json:"locationX"`
		PadID      string `json:"padId"`
		MyAuthorID string `json:"myAuthorId"`
	} `json:"data"`
}

Send this to the Server to send a cursor position {"type":"COLLABROOM","component":"pad","data":{"type":"cursor","action":"cursorPosition","locationY":0,"locationX":1,"padId":"g.VPluJJUveQlgElgN$notes","myAuthorId":"a.3JMUunbWzLnaV1Ox"}}

type Status

type Status int
const (
	CONNECTED Status = iota
	DISCONNECTED
	CONNECTING
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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