Add IRC connection status indicator
This commit is contained in:
parent
83aef5df7b
commit
f429a528ba
11 changed files with 124 additions and 38 deletions
|
@ -12,14 +12,15 @@ import (
|
|||
)
|
||||
|
||||
type Client struct {
|
||||
Server string
|
||||
Host string
|
||||
TLS bool
|
||||
TLSConfig *tls.Config
|
||||
Password string
|
||||
Username string
|
||||
Realname string
|
||||
Messages chan *Message
|
||||
Server string
|
||||
Host string
|
||||
TLS bool
|
||||
TLSConfig *tls.Config
|
||||
Password string
|
||||
Username string
|
||||
Realname string
|
||||
Messages chan *Message
|
||||
ConnectionChanged chan bool
|
||||
|
||||
nick string
|
||||
|
||||
|
@ -40,13 +41,14 @@ type Client struct {
|
|||
|
||||
func NewClient(nick, username string) *Client {
|
||||
return &Client{
|
||||
nick: nick,
|
||||
Username: username,
|
||||
Realname: nick,
|
||||
Messages: make(chan *Message, 32),
|
||||
out: make(chan string, 32),
|
||||
quit: make(chan struct{}),
|
||||
reconnect: make(chan struct{}),
|
||||
nick: nick,
|
||||
Username: username,
|
||||
Realname: nick,
|
||||
Messages: make(chan *Message, 32),
|
||||
ConnectionChanged: make(chan bool, 16),
|
||||
out: make(chan string, 32),
|
||||
quit: make(chan struct{}),
|
||||
reconnect: make(chan struct{}),
|
||||
backoff: &backoff.Backoff{
|
||||
Jitter: true,
|
||||
},
|
||||
|
|
|
@ -10,6 +10,8 @@ import (
|
|||
)
|
||||
|
||||
func (c *Client) Connect(address string) {
|
||||
c.ConnectionChanged <- false
|
||||
|
||||
if idx := strings.Index(address, ":"); idx < 0 {
|
||||
c.Host = address
|
||||
|
||||
|
@ -70,6 +72,7 @@ func (c *Client) connect() error {
|
|||
}
|
||||
|
||||
c.connected = true
|
||||
c.ConnectionChanged <- true
|
||||
c.reader = bufio.NewReader(c.conn)
|
||||
|
||||
c.register()
|
||||
|
@ -154,6 +157,7 @@ func (c *Client) recv() {
|
|||
return
|
||||
|
||||
default:
|
||||
c.ConnectionChanged <- false
|
||||
c.lock.Lock()
|
||||
c.connected = false
|
||||
c.lock.Unlock()
|
||||
|
@ -181,6 +185,7 @@ func (c *Client) recv() {
|
|||
|
||||
func (c *Client) close() {
|
||||
if c.Connected() {
|
||||
c.ConnectionChanged <- false
|
||||
c.lock.Lock()
|
||||
c.connected = false
|
||||
c.lock.Unlock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue