Documentation ¶
Index ¶
- type ChangeConfirmation
- type Client
- func (c *Client) Connect(ctx context.Context) error
- func (c *Client) GetChangeCount() int
- func (c *Client) GetConflictsCount() int
- func (c *Client) GetObject(objectID string) ([]ChangeConfirmation, error)
- func (c *Client) Listen(ctx context.Context) error
- func (c *Client) RegisterConverters(convertFromObject func(object *ClientObject) error, ...) error
- func (c *Client) RegisterToObject(ctx context.Context, objectID string) error
- func (c *Client) SendObject(objectID string, clientObject any) error
- type ClientObject
- type OutgoingChange
- type Property
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChangeConfirmation ¶
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 (*Client) GetChangeCount ¶
GetChangeCount lists the number of unconfirmed changes for client
func (*Client) GetConflictsCount ¶
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 ¶
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 ¶
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 ¶
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 ¶
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