Browse Source

update improve qrcode generating and render process

pull/28/head
Dimas Restu H 4 years ago
parent
commit
96de43466b
  1. 1
      internal/whatsapp/whatsapp.go
  2. 16
      pkg/whatsapp/whatsapp.go

1
internal/whatsapp/whatsapp.go

@ -148,6 +148,7 @@ func Login(c echo.Context) error {
<html> <html>
<head> <head>
<title>WhatsApp Multi-Device Login</title> <title>WhatsApp Multi-Device Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
</head> </head>
<body> <body>
<img src="` + resLogin.QRCode + `" /> <img src="` + resLogin.QRCode + `" />

16
pkg/whatsapp/whatsapp.go

@ -79,7 +79,6 @@ func WhatsAppInitClient(device *store.Device, jid string) {
func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) { func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) {
qrChanCode := make(chan string) qrChanCode := make(chan string)
qrChanTimeout := make(chan int) qrChanTimeout := make(chan int)
qrChanBase64 := make(chan string)
// Get QR Code Data and Timeout // Get QR Code Data and Timeout
go func() { go func() {
@ -91,17 +90,12 @@ func WhatsAppGenerateQR(qrChan <-chan whatsmeow.QRChannelItem) (string, int) {
} }
}() }()
// Generate QR Code Data to PNG Base64 Format
go func() {
select {
case tmp := <-qrChanCode:
png, _ := qrCode.Encode(tmp, qrCode.Medium, 256)
qrChanBase64 <- base64.StdEncoding.EncodeToString(png)
}
}()
// Generate QR Code Data to PNG Image
qrTemp := <-qrChanCode
qrPNG, _ := qrCode.Encode(qrTemp, qrCode.Medium, 256)
// Return QR Code and Timeout Information
return <-qrChanBase64, <-qrChanTimeout
// Return QR Code PNG in Base64 Format and Timeout Information
return base64.StdEncoding.EncodeToString(qrPNG), <-qrChanTimeout
} }
func WhatsAppLogin(jid string) (string, int, error) { func WhatsAppLogin(jid string) (string, int, error) {

Loading…
Cancel
Save