Skip to content

Commit ae900cb

Browse files
committed
client: update messenger websocket settings
1 parent 92458da commit ae900cb

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

client.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Client struct {
6262
socket *socket.NoiseSocket
6363
socketLock sync.RWMutex
6464
socketWait chan struct{}
65+
wsDialer *websocket.Dialer
6566

6667
isLoggedIn atomic.Bool
6768
expectedDisconnect atomic.Bool
@@ -172,8 +173,9 @@ type Client struct {
172173
}
173174

174175
type MessengerConfig struct {
175-
UserAgent string
176-
BaseURL string
176+
UserAgent string
177+
BaseURL string
178+
WebsocketURL string
177179
}
178180

179181
// 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 {
401403
return true
402404
}
403405

406+
func (cli *Client) SetWSDialer(dialer *websocket.Dialer) {
407+
cli.wsDialer = dialer
408+
}
409+
404410
// Connect connects the client to the WhatsApp web websocket. After connection, it will either
405411
// authenticate if there's data in the device store, or emit a QREvent to set up a new link.
406412
func (cli *Client) Connect() error {
@@ -418,8 +424,10 @@ func (cli *Client) Connect() error {
418424
}
419425

420426
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 {
423431
if cli.proxy != nil {
424432
wsDialer.Proxy = cli.proxy
425433
} else if cli.socksProxy != nil {
@@ -432,12 +440,14 @@ func (cli *Client) Connect() error {
432440
}
433441
fs := socket.NewFrameSocket(cli.Log.Sub("Socket"), wsDialer)
434442
if cli.MessengerConfig != nil {
435-
fs.URL = "wss://web-chat-e2ee.facebook.com/ws/chat"
443+
fs.URL = cli.MessengerConfig.WebsocketURL
436444
fs.HTTPHeaders.Set("Origin", cli.MessengerConfig.BaseURL)
437445
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")
441451
}
442452
if err := fs.Connect(); err != nil {
443453
fs.Close(0)

0 commit comments

Comments
 (0)