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

Message Not being Sent #169

Closed stephanoparaskeva closed 2 years ago

stephanoparaskeva commented 3 years ago

I am using the opponent id eg: 3030123 and sending a chat message via 1 on 1 chat. The onMessage listener on the other device never runs and no messages are listed in the dialog:

Screenshot

Screenshot 2020-12-18 at 19 30 02

Code

const ChatModal = ({ navigation, route }: TRatingProps) => {
  const [messages, setMessages] = useState([]);
  const recipient = route?.params?.user;
  const dialog = route?.params?.dialog;

  const close = () => navigation.goBack();
  const send = async () => {
    const message = {
      type: 3,
      body: 'hello world',
      extension: {
        save_to_history: 1,
        dialog_id: dialog._id,
      },
      markable: 1,
    };
    console.warn(dialog);
    try {
      console.warn(ConnectyCube.chat.send);
      const x = await ConnectyCube.chat.send(recipient?.cubeId, message);
    } catch (err) {
      console.warn(err);
    }
  };

  const params = {
    chat_dialog_id: dialog?._id,
    sort_desc: 'date_sent',
    limit: 100,
    skip: 0,
  };

  useEffect(() => {
    ConnectyCube.chat.message.list(params).then(console.warn).catch(console.warn);
  }, []);

  return (
    <KeyboardAvoidingView style={styles.root} behavior='padding'>
      <CommonText style={styles.closeText}>{recipient.name}</CommonText>
      <TouchableOpacity onPress={close} style={styles.closeButton}>
        <CommonText style={styles.closeText}>Close</CommonText>
      </TouchableOpacity>
      <View>
        <TextInput style={styles.textInput} />
        <TouchableOpacity onPress={send} style={styles.sendButton}>
          <CommonText style={styles.submitButtonText}>Send</CommonText>
        </TouchableOpacity>
      </View>
    </KeyboardAvoidingView>
  );
};

When viewing Network Inspector, it seems that this function does not make a network request at all.

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

DaveLomber commented 3 years ago

Are you connected to chat before using ConnectyCube.chat.send ? If not then it will not work. Make sure you are connected to chat by calling ConnectyCube.chat.connect

Regarding Network requests, the ConnectyCube.chat.send call does not do a common XHR request. Instead you should look into WSS tab -

Screenshot 2020-12-19 at 10 21 38
stephanoparaskeva commented 3 years ago

@DaveLomber I am connected when checking ConnectyCube.chat.isConnected. I see, thank you for explaining this to me. But even still, no messages actually get created and stored to the dialog when calling ConnectyCube.chat.send, I can only get it to work when making an axios request.

By the way, is there any other way of contacting if I get anymore questions, I'd really appreciate that, rather than having to make an issue on these great Repo's every time I run into a small problem that I cannot myself fix.

DaveLomber commented 3 years ago

@stephanoparaskeva it's totally fine to create GitHub issues as many as you need ;)

Let's check the following:

1) what you see in WS tab, Messages section (as shown in my screenshot above)? 2) what you see in browser console log when send a message ?

stephanoparaskeva commented 3 years ago

@stephanoparaskeva it's totally fine to create GitHub issues as many as you need ;)

Let's check the following:

  1. what you see in WS tab, Messages section (as shown in my screenshot above)?
  2. what you see in browser console log when send a message ?

Awesome okay! This works

  export const getCubeToken = () => ConnectyCube?.auth?.proxy?.sdkInstance?.session?.token;
  const cubeToken = getCubeToken();

      await axios({
        method: 'post',
        url: 'https://api.connectycube.com/chat/Message',
        headers: {  'CB-Token': cubeToken },
        data: {
          recipient_id: recipient?.cubeId,
          type: 3,
          markable: 1,
          message: msg,
          send_to_chat: 1,
        },
      });

This does not:

ConnectyCube.chat.send(recipient?.cubeId, message)
ccvlad commented 3 years ago

@stephanoparaskeva Could you enable a logger and provide logs after ConnectyCube.chat.send(recipient?.cubeId, message) ?

aravi365 commented 3 years ago

@stephanoparaskeva could you please guide me how to add the onMessage listeners in function components. Looks like you have used function components in your project.

ccvlad commented 2 years ago

Closed due to inactivity. Please create a new issue if needed.