Documentation ¶
Index ¶
- type Client
- func (c *Client) AddContact(contactId string) error
- func (c *Client) AddToGroup(userId, groupId string) error
- func (c *Client) Authenticate(userId, password string) error
- func (c *Client) Connect(host string) error
- func (c *Client) ConnectAsync(host string) chan bool
- func (c *Client) CreateGroup() (string, error)
- func (c *Client) DeleteGroup(groupId string) error
- func (c *Client) Disconnect()
- func (c *Client) GetHistory(remote string, from time.Time, to time.Time) (*[]common.Message, error)
- func (c *Client) JoinGroup(groupId string) error
- func (c *Client) LeaveGroup(groupId string) error
- func (c *Client) ListContacts() ([]string, error)
- func (c *Client) ListGroups() ([]string, error)
- func (c *Client) Reconnect() error
- func (c *Client) ReconnectAsync() chan bool
- func (c *Client) Register(username, password string) (string, error)
- func (c *Client) RemoveContact(contactId string) error
- func (c *Client) RemoveFromGroup(userId, groupId string) error
- func (c *Client) SearchContact(contactName string) (string, error)
- func (c *Client) SendMessage(userId string, message string) error
- func (c *Client) SendTempMessage(userId string, message string, expire time.Time) error
- func (c *Client) SendTextFile(userId string, filePath string) (string, error)
- func (c *Client) StartInteractiveMode()
- func (c Client) UserId() string
- type Transport
- type WebSocketClient
- func (ws *WebSocketClient) Connect(host string) error
- func (ws *WebSocketClient) ConnectAsync(host string) chan bool
- func (ws *WebSocketClient) Disconnect()
- func (ws *WebSocketClient) Reconnect() error
- func (ws *WebSocketClient) ReconnectAsync() chan bool
- func (ws *WebSocketClient) SendBinary(data []byte) error
- func (ws *WebSocketClient) SendText(message string) error
- func (ws *WebSocketClient) SetReceiver(input chan *common.Message)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Main object which represents the chat client
func New ¶
New creates a new chat client and binds the underlying transport for sending/receiving messages and files
func (*Client) AddContact ¶
AddContact adds a contact for this client
func (*Client) AddToGroup ¶
AddToGroup adds a participant in already created group
func (*Client) Authenticate ¶
Authenticate authenticates the user with is password. userId is obtain from Register methods earlier. If authentication is successful returns nil error
func (*Client) ConnectAsync ¶
ConnectAsync calls undelying transport ConnectAsync method
func (*Client) CreateGroup ¶
CreateGroup creates a chat group
func (*Client) DeleteGroup ¶
DeleteGroup deletes a group
func (*Client) Disconnect ¶
func (c *Client) Disconnect()
Disconnect calls undelying transport Disconnect method
func (*Client) GetHistory ¶
GetHistory retrieves the conversation history for a user or a group
func (*Client) LeaveGroup ¶
LeaveGroup removes the client from the group
func (*Client) ListContacts ¶
ListContacts list the added contacts for this client
func (*Client) ListGroups ¶
ListGroups lists all available groups
func (*Client) ReconnectAsync ¶
ReconnectAsync calls undelying transport ReconnectAsync method
func (*Client) Register ¶
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 ¶
Remove contact removes a contact for this client
func (*Client) RemoveFromGroup ¶
RemoveFromGroup removes a participant for already created group
func (*Client) SearchContact ¶
SearchContact searches for user with contactName globally on the server
func (*Client) SendMessage ¶
SendMessage sends a instant message to a user or a group
func (*Client) SendTempMessage ¶
SendTempMessage sends a temporary message with expire period to a user or a group
func (*Client) SendTextFile ¶
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:
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 ¶
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)