Sitelet https://github.com/QuickBlox/quickblox-javascript-sdk/issues/451
Skip to content

Listeners doesn't seems to works #451

Description

@MCSKTLZ

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 ?

Activity

  1. Artem-K-Koltunov commented on Mar 2, 2023

    @Artem-K-Koltunov
    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

  2. MCSKTLZ commented on Mar 2, 2023

    @MCSKTLZ
    Author

    @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

  3. MCSKTLZ commented on Mar 8, 2023

    @MCSKTLZ
    Author

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions