ConnectyCube / connectycube-reactnative-samples

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

is it possible to attach video and audio file like images in chat attachment ? #52

Closed yogitaV-dev closed 4 years ago

ccvlad commented 4 years ago

Yes, you are able to send/receive any attachment file by the same way as an image attachment. You just have to use react-native libs that would play your video/audio attachments

yogitaV-dev commented 4 years ago

Yes, you are able to send/receive any attachment file by the same way as an image attachment. You just have to use react-native libs that would play your video/audio attachments

will you please give me the documentation for audio/video attachment and how can we send it on chat and receive from backend because i am not able to find video/audio attachment doc in connectycube documentation

ccvlad commented 4 years ago

From or docs: https://developers.connectycube.com/js/messaging?id=attachments

For example you would use use the react-native-document-picker:

import DocumentPicker from 'react-native-document-picker';
import ConnectyCube from 'react-native-connectycube';

...
 // For sender
const file = await DocumentPicker.pick({ type: [DocumentPicker.types.allFiles] });
const fileParams = {
  file: file,
  name: file.name, // or any you want
  type: file.type, // mime-type ('video/mp4', 'audio/mp3', 'image/jpeg' etc.)
  size: file.size, // bytes (number)
  public: false // or true
}

ConnectyCube.storage.createAndUpload(params)
  .then(result => {
    const message = {
      type: "chat",
      body: "attachment",
      extension: {
        save_to_history: 1,
        dialog_id: dialog._id,
        attachments: [{ uid: result.uid, type: "*" }] // set type you what: 'image', 'video', 'audio' else...
      }
    };

    ConnectyCube.chat.send(opponentId, message);
  });

// For receiver
ConnectyCube.chat.onMessageListener = (userId, message) => {
  if (message.extension.hasOwnProperty("attachments")) {
    if (message.extension.attachments.length > 0) {
      const fileUID = message.extension.attachments[0].uid;
      const fileType = message.extension.attachments[0].type; // 
      const fileURL = ConnectyCube.storage.privateUrl(fileUID);
      // const fileURL = ConnectyCube.storage.pablicUrl(fileUID); - if fileParams.pablic = true
      ...
      // get file by 'fileURL'
    }
  }
};
ccvlad commented 4 years ago

Since there is no activity I’m going to close the issue. Please raise a separate issue in case of any other questions.