forked from lug/matterbridge
Update nlopes/slack vendor
This commit is contained in:
43
vendor/github.com/nlopes/slack/websocket.go
generated
vendored
43
vendor/github.com/nlopes/slack/websocket.go
generated
vendored
@@ -3,9 +3,10 @@ package slack
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -19,8 +20,9 @@ const (
|
||||
//
|
||||
// Create this element with Client's NewRTM() or NewRTMWithOptions(*RTMOptions)
|
||||
type RTM struct {
|
||||
idGen IDGenerator
|
||||
pings map[int]time.Time
|
||||
idGen IDGenerator
|
||||
pingInterval time.Duration
|
||||
pingDeadman *time.Timer
|
||||
|
||||
// Connection life-cycle
|
||||
conn *websocket.Conn
|
||||
@@ -44,6 +46,13 @@ type RTM struct {
|
||||
// rtm.start to connect to Slack, otherwise it will use
|
||||
// rtm.connect
|
||||
useRTMStart bool
|
||||
|
||||
// dialer is a gorilla/websocket Dialer. If nil, use the default
|
||||
// Dialer.
|
||||
dialer *websocket.Dialer
|
||||
|
||||
// mu is mutex used to prevent RTM connection race conditions
|
||||
mu *sync.Mutex
|
||||
}
|
||||
|
||||
// RTMOptions allows configuration of various options available for RTM messaging
|
||||
@@ -60,9 +69,17 @@ type RTMOptions struct {
|
||||
|
||||
// Disconnect and wait, blocking until a successful disconnection.
|
||||
func (rtm *RTM) Disconnect() error {
|
||||
// this channel is always closed on disconnect. lets the ManagedConnection() function
|
||||
// properly clean up.
|
||||
close(rtm.disconnected)
|
||||
// avoid RTM disconnect race conditions
|
||||
rtm.mu.Lock()
|
||||
defer rtm.mu.Unlock()
|
||||
|
||||
// always push into the disconnected channel when invoked,
|
||||
// this lets the ManagedConnection() function properly clean up.
|
||||
// if the buffer is full then just continue on.
|
||||
select {
|
||||
case rtm.disconnected <- struct{}{}:
|
||||
default:
|
||||
}
|
||||
|
||||
if !rtm.isConnected {
|
||||
return errors.New("Invalid call to Disconnect - Slack API is already disconnected")
|
||||
@@ -72,12 +89,6 @@ func (rtm *RTM) Disconnect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reconnect only makes sense if you've successfully disconnectd with Disconnect().
|
||||
func (rtm *RTM) Reconnect() error {
|
||||
logger.Println("RTM::Reconnect not implemented!")
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetInfo returns the info structure received when calling
|
||||
// "startrtm", holding all channels, groups and other metadata needed
|
||||
// to implement a full chat client. It will be non-nil after a call to
|
||||
@@ -97,3 +108,11 @@ func (rtm *RTM) SendMessage(msg *OutgoingMessage) {
|
||||
|
||||
rtm.outgoingMessages <- *msg
|
||||
}
|
||||
|
||||
func (rtm *RTM) resetDeadman() {
|
||||
timerReset(rtm.pingDeadman, deadmanDuration(rtm.pingInterval))
|
||||
}
|
||||
|
||||
func deadmanDuration(d time.Duration) time.Duration {
|
||||
return d * 4
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user