summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Rhymen/go-whatsapp/conn.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/Rhymen/go-whatsapp/conn.go')
-rw-r--r--vendor/github.com/Rhymen/go-whatsapp/conn.go78
1 files changed, 61 insertions, 17 deletions
diff --git a/vendor/github.com/Rhymen/go-whatsapp/conn.go b/vendor/github.com/Rhymen/go-whatsapp/conn.go
index 59445591..4b28cbe1 100644
--- a/vendor/github.com/Rhymen/go-whatsapp/conn.go
+++ b/vendor/github.com/Rhymen/go-whatsapp/conn.go
@@ -116,31 +116,59 @@ Creates a new connection with a given timeout. The websocket connection to the W
The goroutine for handling incoming messages is started
*/
func NewConn(timeout time.Duration) (*Conn, error) {
- wac := &Conn{
- handler: make([]Handler, 0),
- msgCount: 0,
- msgTimeout: timeout,
- Store: newStore(),
-
- longClientName: "github.com/rhymen/go-whatsapp",
- shortClientName: "go-whatsapp",
- clientVersion: "0.1.0",
- }
- return wac, wac.connect()
+ return NewConnWithOptions(&Options{
+ Timeout: timeout,
+ })
}
// NewConnWithProxy Create a new connect with a given timeout and a http proxy.
func NewConnWithProxy(timeout time.Duration, proxy func(*http.Request) (*url.URL, error)) (*Conn, error) {
+ return NewConnWithOptions(&Options{
+ Timeout: timeout,
+ Proxy: proxy,
+ })
+}
+
+// NewConnWithOptions Create a new connect with a given options.
+type Options struct {
+ Proxy func(*http.Request) (*url.URL, error)
+ Timeout time.Duration
+ Handler []Handler
+ ShortClientName string
+ LongClientName string
+ ClientVersion string
+ Store *Store
+}
+func NewConnWithOptions(opt *Options) (*Conn, error) {
+ if opt == nil {
+ return nil, ErrOptionsNotProvided
+ }
wac := &Conn{
handler: make([]Handler, 0),
msgCount: 0,
- msgTimeout: timeout,
+ msgTimeout: opt.Timeout,
Store: newStore(),
-
- longClientName: "github.com/rhymen/go-whatsapp",
+ longClientName: "github.com/Rhymen/go-whatsapp",
shortClientName: "go-whatsapp",
clientVersion: "0.1.0",
- Proxy: proxy,
+ }
+ if opt.Handler != nil {
+ wac.handler = opt.Handler
+ }
+ if opt.Store != nil {
+ wac.Store = opt.Store
+ }
+ if opt.Proxy != nil {
+ wac.Proxy = opt.Proxy
+ }
+ if len(opt.ShortClientName) != 0 {
+ wac.shortClientName = opt.ShortClientName
+ }
+ if len(opt.LongClientName) != 0 {
+ wac.longClientName = opt.LongClientName
+ }
+ if len(opt.ClientVersion) != 0 {
+ wac.clientVersion = opt.ClientVersion
}
return wac, wac.connect()
}
@@ -249,10 +277,26 @@ func (wac *Conn) keepAlive(minIntervalMs int, maxIntervalMs int) {
}
}
+// IsConnected returns whether the server connection is established or not
+func (wac *Conn) IsConnected() bool {
+ return wac.connected
+}
+
+// GetConnected returns whether the server connection is established or not
+//
+// Deprecated: function name is not go idiomatic, use IsConnected instead
func (wac *Conn) GetConnected() bool {
- return wac.connected
+ return wac.connected
+}
+
+//IsLoggedIn returns whether the you are logged in or not
+func (wac *Conn) IsLoggedIn() bool {
+ return wac.loggedIn
}
+// GetLoggedIn returns whether the you are logged in or not
+//
+// Deprecated: function name is not go idiomatic, use IsLoggedIn instead.
func (wac *Conn) GetLoggedIn() bool {
- return wac.loggedIn
+ return wac.loggedIn
}