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

Listeners doesn't seems to works #451

Open
MCSKTLZ opened this issue Mar 2, 2023 · 3 comments
Open

Listeners doesn't seems to works #451

MCSKTLZ opened this issue Mar 2, 2023 · 3 comments

Comments

@MCSKTLZ
Copy link

MCSKTLZ commented Mar 2, 2023

Hello,

I'm facing an issue using the javascript sdk.

Here is the code :
`
const useChatEvents = () => {
const dispatch = useAppDispatch();
const isConnected = useAppSelector(messagingSelector.selectIsConnected);

useEffect(() => {
const onDisconnectedListener = () => {
dispatch(messagingActions.setIsConnected(false));
console.log('Disconnected listener');
};

const onReconnectListener = () => {
  console.log('Reconnect listener');
};

const onMessageListener = (userId: any, message: any) => {
  console.log(userId, message);
};

const onSentMessageListener = (messageLost: any, messageSent: any) => {
  console.log(messageLost, messageSent, 'ici');
};

const onDeliveredStatusListener = (messageId: any, dialogId: any, userId: any) => {
  console.log(messageId, dialogId, userId);
};

const onReadStatusListener = (messageId: any, dialogId: any, userId: any) => {
  console.log(messageId, dialogId, userId);
};

if (isConnected) {
  QB.chat.onReadStatusListener = onReadStatusListener;
  QB.chat.onDeliveredStatusListener = onDeliveredStatusListener;
  QB.chat.onSentMessageCallback = onSentMessageListener;
  QB.chat.onDisconnectedListener = onDisconnectedListener;
  QB.chat.onReconnectListener = onReconnectListener;
  QB.chat.onMessageListener = onMessageListener;
}

return () => {
  if (QB.chat) {
    QB.chat.onReadStatusListener = undefined;
    QB.chat.onDeliveredStatusListener = undefined;
    QB.chat.onSentMessageCallback = undefined;
    QB.chat.onDisconnectedListener = undefined;
    QB.chat.onReconnectListener = undefined;
    QB.chat.onMessageListener = undefined;
  }
};

}, [isConnected]);
};
`
I'm connected and have initialized quickblox, I can get dialogs, dialog messages, send message,.....
I don't receive any response from the listeners apart from QB.chat.onDisconnectedListener.

Is there any solution or some configuration that I'm missing ?

Copy link
Member

Good day. The part of your code looks logical. But have you seen JS Chat Example? We have implemented a lot of requested listeners.
https://github.com/QuickBlox/quickblox-javascript-sdk/blob/gh-pages/samples/chat/js/listeners.js

@MCSKTLZ
Copy link
Author

MCSKTLZ commented Mar 2, 2023

@Artem-K-Koltunov

Yes I have seen this but for me it is not working.
The only one I can make work is the disconnect listener.
The rest are not firing !

For example the onMessageListener is not firing when I get a new message from an other user

@MCSKTLZ
Copy link
Author

MCSKTLZ commented Mar 8, 2023

@Artem-K-Koltunov

Hello,

When I try to join a dialog I have an error code 403 with the message unknown issue.
However I'm connected to the chat and can get dialogs and messages !
I think it is linked with the problem of listeners not firing.

I'm joining the dialog like that:

`try {
console.log('Joining', dialogId);

  const dialogJid = await QB.chat.helpers.getRoomJidFromDialogId(dialogId);
  console.log('jid', dialogJid);

  const res = await new Promise((resolve, reject) => {
    QB.chat.muc.join(dialogId, (error: any, result: any) => {
      if (error) {
        console.log({ error });

        reject(error);
        return;
      }

      console.log({ result });

      resolve(result);
    });
  });
  console.log('joined', res);
} catch (err) {
  console.log(err);
}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants