Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After disconnecting and trying to connect/reconnect I get an error. #528

Open
josecaster opened this issue Nov 11, 2024 · 0 comments
Open
Labels
waiting triage A maintainer acknowledged the issue, further discussion is needed

Comments

@josecaster
Copy link

Scenario,

Screenshot 2024-11-11 191944

When I click start the Qr-code appears, I scan, it syncs. I click stop which does not log out the session but disconnects.
I clik start which connects, but get error, even if I press reconnect which reconnects I get these errors:
Either
2024-11-11T19:16:44.918-03:00 ERROR 26760 --- [onPool-worker-5] ErrorHandler : [5978171994] Socket failure at MEDIA_CONNECTION 2024-11-11T19:16:44.919-03:00 WARN 26760 --- [onPool-worker-5] ErrorHandler : [5978171994] Ignored failure java.util.concurrent.CompletionException: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@67b4f29b[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@1e0780bc[Wrapped task = it.auties.whatsapp.implementation.StreamHandler$$Lambda/0x000001a9933cd388@79ab5b24]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@7fa1a90c[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 4]

or

2024-11-11T19:16:45.039-03:00 ERROR 26760 --- [onPool-worker-5] ErrorHandler : [5978171994] Socket failure at LOGIN 2024-11-11T19:16:45.042-03:00 WARN 26760 --- [onPool-worker-5] ErrorHandler : [5978171994] Cannot login Disconnected: DISCONNECTED java.util.concurrent.CompletionException: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask@6e26143d[Not completed, task = java.util.concurrent.Executors$RunnableAdapter@35e83f7c[Wrapped task = it.auties.whatsapp.implementation.StreamHandler$$Lambda/0x000001a9933d57f8@7e24ac83]] rejected from java.util.concurrent.ScheduledThreadPoolExecutor@7fa1a90c[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 4]

or both.

If without disconnecting I press the reconnect button, everything works fine.
This is my code :
`private final UUID uuid;
private final WebOptionsBuilder webOptionsBuilder;
private UI current;

public WhatsappBotView() {

    uuid = UUID.randomUUID();

    VerticalLayout sessionLayout = new VerticalLayout();
    VerticalLayout detailLayout = new VerticalLayout();

    SplitLayout splitLayout = new SplitLayout();
    splitLayout.addToPrimary(sessionLayout);
    splitLayout.addToSecondary(detailLayout);
    splitLayout.setSizeFull();

    buildSessionLayout(sessionLayout);

    add(splitLayout);
    setSizeFull();
    webOptionsBuilder = Whatsapp.webBuilder().newConnection(uuid);
}

private void buildSessionLayout(VerticalLayout sessionLayout) {

    sessionLayout.setAlignItems(Alignment.CENTER);
    sessionLayout.setJustifyContentMode(JustifyContentMode.CENTER);

    Div qrCode = new Div();
    Button startBtn = new Button("Start");
    Button stopBtn = new Button("Stop");
    Button reconnect = new Button("Reconnect");

    sessionLayout.add(qrCode);
    sessionLayout.add(new HorizontalLayout(startBtn, stopBtn, reconnect));

    startBtn.setEnabled(true);
    stopBtn.setEnabled(false);

    current = UI.getCurrent();

    listeners(startBtn, stopBtn, reconnect, qrCode);
}

private void listeners(Button startBtn, Button stopBtn, Button reconnect, Div qrCode) {
    startBtn.addClickListener(f -> {
        boolean connected = Whatsapp.isConnected(uuid);
        if (!connected) {
            Optional<Whatsapp> registered = webOptionsBuilder.registered();
            if (registered.isEmpty()) {
                register(startBtn, stopBtn, qrCode);
            } else {
                registered.get().connect().whenCompleteAsync((a, b) -> {
                    System.out.println("Truly reconnected");
                    current.access(() -> {
                        Notification reconnected = Notification.show("Reconnected", 5000, Notification.Position.BOTTOM_START);
                        reconnected.addThemeVariants(NotificationVariant.LUMO_WARNING);
                        reconnected.open();
                    });
                });
            }

        } else {
            Optional<Whatsapp> registered = webOptionsBuilder.registered();
            if (registered.isPresent()) {
                registered.get().connect().whenCompleteAsync((a, b) -> {
                    System.out.println("Truly reconnected");
                    current.access(() -> {
                        Notification reconnected = Notification.show("Reconnected", 5000, Notification.Position.BOTTOM_START);
                        reconnected.addThemeVariants(NotificationVariant.LUMO_WARNING);
                        reconnected.open();
                    });
                });
            } else {
                register(startBtn, stopBtn, qrCode);
            }
        }
    });
    reconnect.addClickListener(f -> {
        Optional<Whatsapp> registered = webOptionsBuilder.registered();
        registered.ifPresent(whatsapp -> whatsapp.reconnect().whenCompleteAsync((a, b) -> {
            System.out.println("Truly reconnected");
            current.access(() -> {
                Notification reconnected = Notification.show("Reconnected", 5000, Notification.Position.BOTTOM_START);
                reconnected.addThemeVariants(NotificationVariant.LUMO_WARNING);
                reconnected.open();
            });
        }));
    });
    stopBtn.addClickListener(f -> {
        Optional<Whatsapp> registered = webOptionsBuilder.registered();
        if (registered.isPresent()) {
            Whatsapp whatsapp = registered.get();
            boolean connected = whatsapp.isConnected();
            if (connected) {
                whatsapp.disconnect().whenCompleteAsync((a, b) -> {
                    System.out.println("Truly disconnected");
                    current.access(() -> {
                        Notification disconnected = Notification.show("Disconnected", 5000, Notification.Position.BOTTOM_START);
                        disconnected.addThemeVariants(NotificationVariant.LUMO_ERROR);
                        disconnected.open();
                    });
                });
            }
        }
    });
}

private void register(Button startBtn, Button stopBtn, Div qrCode) {

    webOptionsBuilder.historyLength(WebHistoryLength.extended()).unregistered(QrHandler.toPlainString(c -> {
                current.access(() -> {
                    qrCode.removeAll();
                    Barcode qrcode = new Barcode(c, Barcode.Type.qrcode, "200px", "200px");
                    qrCode.add(qrcode);
                });

            })).addLoggedInListener(api -> {
                System.out.printf("Connected: %s%n", api.store().privacySettings());
                current.access(() -> {
                    startBtn.setEnabled(false);
                    stopBtn.setEnabled(true);
                });

            }).addDisconnectedListener(reason -> {
                System.out.printf("Disconnected: %s%n", reason);
                current.access(() -> {
                    startBtn.setEnabled(true);
                    stopBtn.setEnabled(false);
                });

            }).addContactsListener((api, contacts) -> System.out.printf("Contacts: %s%n", contacts.size()))//
            .addChatsListener((api, chats) -> System.out.printf("Chats: %s%n", chats.size()))//
            .addNewslettersListener((api, newsletters) -> System.out.printf("Newsletters: %s%n", newsletters.size()))//
            .addNodeReceivedListener(incoming -> System.out.printf("Received node %s%n", incoming))//
            .addNodeSentListener(outgoing -> System.out.printf("Sent node %s%n", outgoing))//
            .addActionListener((action, info) -> System.out.printf("New action: %s, info: %s%n", action, info))//
            .addSettingListener(setting -> System.out.printf("New setting: %s%n", setting))//
            .addMessageStatusListener((info) -> System.out.printf("Message status update for %s%n", info.id()))//
            .addChatMessagesSyncListener((api, chat, last) -> System.out.printf("%s now has %s messages: %s(oldest message: %s)%n", chat.name(), chat.messages().size(), !last ? "waiting for more" : "done", chat.oldestMessage().flatMap(ChatMessageInfo::timestamp).orElse(null)))//
            .addHistorySyncProgressListener((progress, recent) -> System.out.println("History sync progress: " + progress + "%(" + recent + ")"))//
            .addListener(new MyListener()).connect().whenCompleteAsync((a, b) -> {

                System.out.println("Truly Completed");
                current.access(() -> {
                    Notification reconnected = Notification.show("Completed", 5000, Notification.Position.BOTTOM_START);
                    reconnected.addThemeVariants(NotificationVariant.LUMO_SUCCESS);
                    reconnected.open();
                });

            });
}

`

@Auties00 Auties00 added the waiting triage A maintainer acknowledged the issue, further discussion is needed label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting triage A maintainer acknowledged the issue, further discussion is needed
Projects
None yet
Development

No branches or pull requests

2 participants