Skip to content

Commit 661a7ce

Browse files
committed
feat: add auto reconnect checking
Add auto reconnect checking in `SetAutoReconnectChecking` function to ensure continuous connection by reconnecting every 5 minutes when disconnected. fix: update dependencies Update dependencies in go.mod and go.sum for compatibility and performance improvements: - github.com/valyala/fasthttp v1.55.0 to v1.56.0 - github.com/klauspost/compress v1.17.9 to v1.17.10 - go.mau.fi/whatsmeow v0.0.0-20240911102933-bb3364aa3986 to v0.0.0-20240927134544-69ba055bef0f - go.mau.fi/util v0.7.0 to v0.8.0
1 parent c47e54e commit 661a7ce

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ func runRest(_ *cobra.Command, _ []string) {
136136

137137
// Set auto reconnect to whatsapp server after booting
138138
go helpers.SetAutoConnectAfterBooting(appService)
139+
// Set auto reconnect checking
140+
go helpers.SetAutoReconnectChecking(cli)
139141
if err = app.Listen(":" + config.AppPort); err != nil {
140142
log.Fatalln("Failed to start: ", err.Error())
141143
}

src/go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ require (
1818
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
1919
github.com/spf13/cobra v1.8.1
2020
github.com/stretchr/testify v1.9.0
21-
github.com/valyala/fasthttp v1.55.0
21+
github.com/valyala/fasthttp v1.56.0
2222
go.mau.fi/libsignal v0.1.1
23-
go.mau.fi/whatsmeow v0.0.0-20240911102933-bb3364aa3986
23+
go.mau.fi/whatsmeow v0.0.0-20240927134544-69ba055bef0f
2424
google.golang.org/protobuf v1.34.2
2525
)
2626

@@ -35,7 +35,7 @@ require (
3535
github.com/gofiber/utils v1.1.0 // indirect
3636
github.com/gorilla/websocket v1.5.3 // indirect
3737
github.com/inconshreveable/mousetrap v1.1.0 // indirect
38-
github.com/klauspost/compress v1.17.9 // indirect
38+
github.com/klauspost/compress v1.17.10 // indirect
3939
github.com/kr/pretty v0.1.0 // indirect
4040
github.com/mattn/go-colorable v0.1.13 // indirect
4141
github.com/mattn/go-isatty v0.0.20 // indirect
@@ -47,7 +47,7 @@ require (
4747
github.com/spf13/pflag v1.0.5 // indirect
4848
github.com/valyala/bytebufferpool v1.0.0 // indirect
4949
github.com/valyala/tcplisten v1.0.0 // indirect
50-
go.mau.fi/util v0.7.0 // indirect
50+
go.mau.fi/util v0.8.0 // indirect
5151
golang.org/x/crypto v0.27.0 // indirect
5252
golang.org/x/image v0.20.0 // indirect
5353
golang.org/x/net v0.29.0 // indirect

src/go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
4545
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4646
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
4747
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
48+
github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0=
49+
github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0=
4850
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
4951
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
5052
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
@@ -91,17 +93,23 @@ github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6Kllzaw
9193
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
9294
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
9395
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
96+
github.com/valyala/fasthttp v1.56.0 h1:bEZdJev/6LCBlpdORfrLu/WOZXXxvrUQSiyniuaoW8U=
97+
github.com/valyala/fasthttp v1.56.0/go.mod h1:sReBt3XZVnudxuLOx4J/fMrJVorWRiWY2koQKgABiVI=
9498
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
9599
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
96100
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
97101
go.mau.fi/libsignal v0.1.1 h1:m/0PGBh4QKP/I1MQ44ti4C0fMbLMuHb95cmDw01FIpI=
98102
go.mau.fi/libsignal v0.1.1/go.mod h1:QLs89F/OA3ThdSL2Wz2p+o+fi8uuQUz0e1BRa6ExdBw=
99103
go.mau.fi/util v0.7.0 h1:l31z+ivrSQw+cv/9eFebEqtQW2zhxivGypn+JT0h/ws=
100104
go.mau.fi/util v0.7.0/go.mod h1:bWYreIoTULL/UiRbZdfddPh7uWDFW5yX4YCv5FB0eE0=
105+
go.mau.fi/util v0.8.0 h1:MiSny8jgQq4XtCLAT64gDJhZVhqiDeMVIEBDFVw+M0g=
106+
go.mau.fi/util v0.8.0/go.mod h1:1Ixb8HWoVbl3rT6nAX6nV4iMkzn7KU/KXwE0Rn5RmsQ=
101107
go.mau.fi/whatsmeow v0.0.0-20240821142752-3d63c6fcc1a7 h1:Aa4uov0rM0SQQ7Fc/TZZpmQEGksie2SVTv/UuCJwViI=
102108
go.mau.fi/whatsmeow v0.0.0-20240821142752-3d63c6fcc1a7/go.mod h1:BhHKalSq0qNtSCuGIUIvoJyU5KbT4a7k8DQ5yw1Ssk4=
103109
go.mau.fi/whatsmeow v0.0.0-20240911102933-bb3364aa3986 h1:7X+3826qoRBHPCtxY89tqMcYEsi9+OuWE6hHZfRc0qI=
104110
go.mau.fi/whatsmeow v0.0.0-20240911102933-bb3364aa3986/go.mod h1:BhHKalSq0qNtSCuGIUIvoJyU5KbT4a7k8DQ5yw1Ssk4=
111+
go.mau.fi/whatsmeow v0.0.0-20240927134544-69ba055bef0f h1:+gT0NSk50HaAagtyj6J/a/QiNN34FJU+Vm1QyppV8Ec=
112+
go.mau.fi/whatsmeow v0.0.0-20240927134544-69ba055bef0f/go.mod h1:UvaXcdb8y5Mryj2LSXAMw7u4/exnWJIXn8Gvpmf6ndI=
105113
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
106114
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
107115
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=

src/internal/rest/helpers/common.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package helpers
33
import (
44
"context"
55
domainApp "github.com/aldinokemal/go-whatsapp-web-multidevice/domains/app"
6+
"go.mau.fi/whatsmeow"
67
"mime/multipart"
78
"time"
89
)
@@ -12,6 +13,18 @@ func SetAutoConnectAfterBooting(service domainApp.IAppService) {
1213
_ = service.Reconnect(context.Background())
1314
}
1415

16+
func SetAutoReconnectChecking(cli *whatsmeow.Client) {
17+
// Run every 5 minutes to check if the connection is still alive, if not, reconnect
18+
go func() {
19+
for {
20+
time.Sleep(5 * time.Minute)
21+
if !cli.IsConnected() {
22+
_ = cli.Connect()
23+
}
24+
}
25+
}()
26+
}
27+
1528
func MultipartFormFileHeaderToBytes(fileHeader *multipart.FileHeader) []byte {
1629
file, _ := fileHeader.Open()
1730
defer file.Close()

0 commit comments

Comments
 (0)