@@ -62,6 +62,7 @@ type Client struct {
62
62
socket * socket.NoiseSocket
63
63
socketLock sync.RWMutex
64
64
socketWait chan struct {}
65
+ wsDialer * websocket.Dialer
65
66
66
67
isLoggedIn atomic.Bool
67
68
expectedDisconnect atomic.Bool
@@ -172,8 +173,9 @@ type Client struct {
172
173
}
173
174
174
175
type MessengerConfig struct {
175
- UserAgent string
176
- BaseURL string
176
+ UserAgent string
177
+ BaseURL string
178
+ WebsocketURL string
177
179
}
178
180
179
181
// Size of buffer for the channel that all incoming XML nodes go through.
@@ -401,6 +403,10 @@ func (cli *Client) WaitForConnection(timeout time.Duration) bool {
401
403
return true
402
404
}
403
405
406
+ func (cli * Client ) SetWSDialer (dialer * websocket.Dialer ) {
407
+ cli .wsDialer = dialer
408
+ }
409
+
404
410
// Connect connects the client to the WhatsApp web websocket. After connection, it will either
405
411
// authenticate if there's data in the device store, or emit a QREvent to set up a new link.
406
412
func (cli * Client ) Connect () error {
@@ -418,8 +424,10 @@ func (cli *Client) Connect() error {
418
424
}
419
425
420
426
cli .resetExpectedDisconnect ()
421
- wsDialer := websocket.Dialer {}
422
- if ! cli .proxyOnlyLogin || cli .Store .ID == nil {
427
+ var wsDialer websocket.Dialer
428
+ if cli .wsDialer != nil {
429
+ wsDialer = * cli .wsDialer
430
+ } else if ! cli .proxyOnlyLogin || cli .Store .ID == nil {
423
431
if cli .proxy != nil {
424
432
wsDialer .Proxy = cli .proxy
425
433
} else if cli .socksProxy != nil {
@@ -432,12 +440,14 @@ func (cli *Client) Connect() error {
432
440
}
433
441
fs := socket .NewFrameSocket (cli .Log .Sub ("Socket" ), wsDialer )
434
442
if cli .MessengerConfig != nil {
435
- fs .URL = "wss://web-chat-e2ee.facebook.com/ws/chat"
443
+ fs .URL = cli . MessengerConfig . WebsocketURL
436
444
fs .HTTPHeaders .Set ("Origin" , cli .MessengerConfig .BaseURL )
437
445
fs .HTTPHeaders .Set ("User-Agent" , cli .MessengerConfig .UserAgent )
438
- fs .HTTPHeaders .Set ("Sec-Fetch-Dest" , "empty" )
439
- fs .HTTPHeaders .Set ("Sec-Fetch-Mode" , "websocket" )
440
- fs .HTTPHeaders .Set ("Sec-Fetch-Site" , "cross-site" )
446
+ fs .HTTPHeaders .Set ("Cache-Control" , "no-cache" )
447
+ fs .HTTPHeaders .Set ("Pragma" , "no-cache" )
448
+ //fs.HTTPHeaders.Set("Sec-Fetch-Dest", "empty")
449
+ //fs.HTTPHeaders.Set("Sec-Fetch-Mode", "websocket")
450
+ //fs.HTTPHeaders.Set("Sec-Fetch-Site", "cross-site")
441
451
}
442
452
if err := fs .Connect (); err != nil {
443
453
fs .Close (0 )
0 commit comments