Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,16 @@ func (cli *Client) WaitForConnection(timeout time.Duration) bool {
return true
}

// Connect connects the client to the WhatsApp web websocket with the specified context.
// After connection, it will either authenticate if there's data in the device store,
// or emit a QREvent to set up a new link.
func (cli *Client) Connect() error {
return cli.ConnectWithTimeout(context.Background())
}

// Connect connects the client to the WhatsApp web websocket. After connection, it will either
// authenticate if there's data in the device store, or emit a QREvent to set up a new link.
func (cli *Client) Connect() error {
func (cli *Client) ConnectWithTimeout(timeCtx context.Context) error {
cli.socketLock.Lock()
defer cli.socketLock.Unlock()
if cli.socket != nil {
Expand Down Expand Up @@ -430,7 +437,7 @@ func (cli *Client) Connect() error {
fs.HTTPHeaders.Set("Sec-Fetch-Mode", "websocket")
fs.HTTPHeaders.Set("Sec-Fetch-Site", "cross-site")
}
if err := fs.Connect(); err != nil {
if err := fs.Connect(timeCtx); err != nil {
fs.Close(0)
return err
} else if err = cli.doHandshake(fs, *keys.NewKeyPair()); err != nil {
Expand Down
1 change: 0 additions & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func (cli *Client) handlePlaintextMessage(info *types.MessageInfo, node *waBinar
}
}
cli.dispatchEvent(evt.UnwrapRaw())
return
}

func (cli *Client) decryptMessages(info *types.MessageInfo, node *waBinary.Node) {
Expand Down
4 changes: 2 additions & 2 deletions socket/framesocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ func (fs *FrameSocket) Close(code int) {
}
}

func (fs *FrameSocket) Connect() error {
func (fs *FrameSocket) Connect(timeCtx context.Context) error {
fs.lock.Lock()
defer fs.lock.Unlock()

if fs.conn != nil {
return ErrSocketAlreadyOpen
}
ctx, cancel := context.WithCancel(context.Background())
ctx, cancel := context.WithCancel(timeCtx)

fs.log.Debugf("Dialing %s", fs.URL)
conn, _, err := fs.Dialer.Dial(fs.URL, fs.HTTPHeaders)
Expand Down