ConnectyCube / connectycube-reactnative-samples

Chat and Video Chat code samples for React Native, ConnectyCube
https://connectycube.com
Apache License 2.0
124 stars 111 forks source link

OnMessageListener never fired #170

Closed stephanoparaskeva closed 3 years ago

stephanoparaskeva commented 3 years ago
// Doing this way because  ConnectyCube.chat.send(dialog._id || recipientId, message) does not work.
const cubeToken = ConnectyCube?.auth?.proxy?.sdkInstance?.session?.token;
  const y = await axios({
        method: 'post',
        url: 'https://api.connectycube.com/chat/Message',
        data: {
          recipient_id: recipient?.cubeId,
          message: 'where are you?',
        },
        headers: { 'CB-Token': cubeToken },
      });
      console.warn(y);

Success.

console.warn of y:

{ "data": { "_id": ....... }


Other phone:

    ConnectyCube.chat.onMessageListener = () => console.warn('MESSAGE RECEIVED');

Never gets called.

Version: "react-native-connectycube": "^3.7.8",

DaveLomber commented 3 years ago

If you want to send messages via REST API and to be them delivered in real time, just add one more parameter: send_to_chat: 1:

data: {
          recipient_id: recipient?.cubeId,
          message: 'where are you?',
          send_to_chat: 1
        },
DaveLomber commented 3 years ago

as described here https://developers.connectycube.com/server/chat?id=create-a-message

stephanoparaskeva commented 3 years ago

This has worked, thank you! @DaveLomber

aravi365 commented 3 years ago

This has worked, thank you! @DaveLomber

ConnectyCube.chat.onMessageListener = () => console.warn('MESSAGE RECEIVED'); i am in doubt, where to add this code inorder to catch the live messages in the chat. I am using function components instead of class. could someone please help, i am stucked!! @DaveLomber @stephanoparaskeva