client

package
v0.0.0-...-6a36c00 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Out chan *common.Message
	// contains filtered or unexported fields
}

Main object which represents the chat client

func New

func New(transport Transport) *Client

New creates a new chat client and binds the underlying transport for sending/receiving messages and files

func (*Client) AddContact

func (c *Client) AddContact(contactId string) error

AddContact adds a contact for this client

func (*Client) AddToGroup

func (c *Client) AddToGroup(userId, groupId string) error

AddToGroup adds a participant in already created group

func (*Client) Authenticate

func (c *Client) Authenticate(userId, password string) error

Authenticate authenticates the user with is password. userId is obtain from Register methods earlier. If authentication is successful returns nil error

func (*Client) Connect

func (c *Client) Connect(host string) error

Connect calls undelying transport Connect method

func (*Client) ConnectAsync

func (c *Client) ConnectAsync(host string) chan bool

ConnectAsync calls undelying transport ConnectAsync method

func (*Client) CreateGroup

func (c *Client) CreateGroup() (string, error)

CreateGroup creates a chat group

func (*Client) DeleteGroup

func (c *Client) DeleteGroup(groupId string) error

DeleteGroup deletes a group

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect calls undelying transport Disconnect method

func (*Client) GetHistory

func (c *Client) GetHistory(remote string, from time.Time, to time.Time) (*[]common.Message, error)

GetHistory retrieves the conversation history for a user or a group

func (*Client) JoinGroup

func (c *Client) JoinGroup(groupId string) error

JoinGroup adds the client to the group

func (*Client) LeaveGroup

func (c *Client) LeaveGroup(groupId string) error

LeaveGroup removes the client from the group

func (*Client) ListContacts

func (c *Client) ListContacts() ([]string, error)

ListContacts list the added contacts for this client

func (*Client) ListGroups

func (c *Client) ListGroups() ([]string, error)

ListGroups lists all available groups

func (*Client) Reconnect

func (c *Client) Reconnect() error

Reconnect calls undelying transport Reconnect method

func (*Client) ReconnectAsync

func (c *Client) ReconnectAsync() chan bool

ReconnectAsync calls undelying transport ReconnectAsync method

func (*Client) Register

func (c *Client) Register(username, password string) (string, error)

Register registers the client with username and passowrd. If registration is successful server specific userId is return userId is used with the Athenticate method later

func (*Client) RemoveContact

func (c *Client) RemoveContact(contactId string) error

Remove contact removes a contact for this client

func (*Client) RemoveFromGroup

func (c *Client) RemoveFromGroup(userId, groupId string) error

RemoveFromGroup removes a participant for already created group

func (*Client) SearchContact

func (c *Client) SearchContact(contactName string) (string, error)

SearchContact searches for user with contactName globally on the server

func (*Client) SendMessage

func (c *Client) SendMessage(userId string, message string) error

SendMessage sends a instant message to a user or a group

func (*Client) SendTempMessage

func (c *Client) SendTempMessage(userId string, message string,
	expire time.Time) error

SendTempMessage sends a temporary message with expire period to a user or a group

func (*Client) SendTextFile

func (c *Client) SendTextFile(userId string, filePath string) (string, error)

SendTextFile sends a text file to a user or a group

func (*Client) StartInteractiveMode

func (c *Client) StartInteractiveMode()

StartInteractiveMode starts a commandline mode where you chat with the other users in the system

Example
ws := NewWebSocketClient()
c := New(ws)
err := c.Connect("ws://127.0.0.1:9000/websocket")
fmt.Println("connected", err)
userId, err := c.Register("pesho", "123")
fmt.Println("registered", err)

err = c.Authenticate(userId, "123")
fmt.Println("authenticated", err)

if err == nil {
	c.StartInteractiveMode()
}
Output:

func (Client) UserId

func (c Client) UserId() string

UserId return the server specific userId

type Transport

type Transport interface {
	Connect(host string) error
	ConnectAsync(host string) chan bool
	Disconnect()
	Reconnect() error
	ReconnectAsync() chan bool
	SendText(message string) error
	SendBinary(date []byte) error
	SetReceiver(chan *common.Message)
}

Defines the interface for transport implementations

type WebSocketClient

type WebSocketClient struct {
	In chan *common.Message
	// contains filtered or unexported fields
}

Transport implementation with a websocket

func NewWebSocketClient

func NewWebSocketClient() *WebSocketClient

func (*WebSocketClient) Connect

func (ws *WebSocketClient) Connect(host string) error

func (*WebSocketClient) ConnectAsync

func (ws *WebSocketClient) ConnectAsync(host string) chan bool

func (*WebSocketClient) Disconnect

func (ws *WebSocketClient) Disconnect()

func (*WebSocketClient) Reconnect

func (ws *WebSocketClient) Reconnect() error

func (*WebSocketClient) ReconnectAsync

func (ws *WebSocketClient) ReconnectAsync() chan bool

func (*WebSocketClient) SendBinary

func (ws *WebSocketClient) SendBinary(data []byte) error

func (*WebSocketClient) SendText

func (ws *WebSocketClient) SendText(message string) error

func (*WebSocketClient) SetReceiver

func (ws *WebSocketClient) SetReceiver(input chan *common.Message)

Jump to

Keyboard shortcuts

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