client

package
v0.0.0-...-f45a054 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChangeConfirmation

type ChangeConfirmation struct {
	ObjectID   string
	PropertyID string
	Data       []byte
}

ChangeConfirmation is the confirmation that the server accepts this change and has passed to all subscribed clients Currently this has the same structure as OutgoingChange, but keeping them as separate types due to suspecting they will diverge

type Client

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

Client is the client API for CollabLite service.

func NewClient

func NewClient(serverAddr string) *Client

NewClient creates a new client, configured to connect to serverAddr (host:port)

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect creates the stream against the server

func (*Client) GetChangeCount

func (c *Client) GetChangeCount() int

GetChangeCount lists the number of unconfirmed changes for client

func (*Client) GetConflictsCount

func (c *Client) GetConflictsCount() int

GetConflictsCount returns number of conflicts the client has recorded

func (*Client) GetObject

func (c *Client) GetObject(objectID string) ([]ChangeConfirmation, error)

GetObject returns the entire object from the server. Used for initial loading etc.

func (*Client) Listen

func (c *Client) Listen(ctx context.Context) error

Listen will loop for incoming changes from the server. Any changes that are received and are NOT discarded (due to modifying the same object/property as a local change) will be passed to the callback registered via RegisterCallback

func (*Client) RegisterConverters

func (c *Client) RegisterConverters(convertFromObject func(object *ClientObject) error,
	convertToObject func(objectID string, exitingObject *ClientObject, clientObject any) (*ClientObject, error)) error

RegisterConverters called by the client code to register functions to convert between their own structures/objects and our ClientObject struct.

func (*Client) RegisterToObject

func (c *Client) RegisterToObject(ctx context.Context, objectID string) error

RegisterToObject sends a message to the server indicating that the client is listening for changes for a particular ObjectID. This only needs to be done when the client is switching between objects.

func (*Client) SendObject

func (c *Client) SendObject(objectID string, clientObject any) error

SendObject takes the users object, converts to what the server expects and sends it. Steps:

  • Update our internal object (c.object) with the new clientObject. This may just be updating a single property Or populating the entire object.
  • Loop through the dirty properties in the internal object and send to server.

type ClientObject

type ClientObject struct {
	ObjectID   string
	Properties map[string]Property

	// This may or may not stay. This is just to help the client know what type of
	// object this is representing. eg Could be set to "json" so they know they can
	// change to JSON later, or anything else. This is purely a helper field.
	ObjectType string

	// lock for controlling modifications. In two minds about having it within the object itself
	// or outside controlling. Will include it internally for now and revisit if causing an issue
	Lock sync.Mutex
}

ClientObject is a simple object used to represent an object in the system.

func NewObject

func NewObject(objectID string, objectType string) *ClientObject

func (*ClientObject) AdjustProperty

func (o *ClientObject) AdjustProperty(propertyID string, data []byte, dirty bool, updated bool)

func (*ClientObject) ClearPropertyDirtyFlag

func (o *ClientObject) ClearPropertyDirtyFlag(propertyID string)

ClearPropertyDirtyFlag is used to adjust dirty flag This smells of a design issue

func (*ClientObject) ClearPropertyUpdatedFlag

func (o *ClientObject) ClearPropertyUpdatedFlag(propertyID string)

ClearPropertyUpdatedFlag is used to adjust updated flag This smells of a design issue

func (*ClientObject) GetProperties

func (o *ClientObject) GetProperties() map[string]Property

type OutgoingChange

type OutgoingChange struct {
	ObjectID   string
	PropertyID string
	Data       []byte
}

OutgoingChange is the change the client is sending to the server. The change is purely related to a single property within the object. If there has been 2 changes (eg, colour changed to red and size changed to 10) then two separate OutgoingChange objects will need to be created and sent.

type Property

type Property struct {
	Data []byte

	// Dirty is used to identify any property that has been changed locally and needs to be sent to the server.
	Dirty bool

	// indicates that its been updated from the server... and needs to be used by the client.
	Updated bool
}

Property is the a property key/value of an object. We dont care what the data is, we purely treat it as a byte array Keep a dirty flag to know what data needs to be sent to server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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