aws-samples / amazon-chime-react-native-demo

A React Native demo application for Android and iOS using the Amazon Chime SDK.
MIT No Attribution
100 stars 24 forks source link

How we can use sendDataMessage to send a data message to all attendees ? #169

Closed Saifak34 closed 1 year ago

Saifak34 commented 1 year ago

Describe the bug This is not a bug but a help request, how we can send data messages in react-native application? do we need to add extra native code in kotlin and C# ? or we can just add it in Bridge.js as a Native function and use it ?

How to use DataMessageObserver observer to receive messages ?

why we are triggering NativeFunction.sendDataMessage(dataMessage.topic, str, 1000); while subscribing

const onDataMessageReceivedSubscription = getSDKEventEmitter().addListener(
             MobileSDKEvent.OnDataMessageReceive, 
            (dataMessage) => {
            const str = `Received Data message (topic: ${dataMessage.topic}) ${dataMessage.data} from ${dataMessage.senderAttendeeId}:${dataMessage.senderExternalUserId} at ${dataMessage.timestampMs} throttled: ${dataMessage.throttled}`;
            console.log('received',dataMessage);
            NativeFunction.sendDataMessage(dataMessage.topic, str, 1000);
          })
georgezy-amzn commented 1 year ago

Hi @Saifak34,

As long as all attendees are subscribed to the same topic, they will be able to receive messages from this topic.

Please follow this commit for using DataMessageObserver.

NativeFunction.sendDataMessage in the code snippet is just for demo purpose, don't worry about it.