AgoraIO-Community / VideoUIKit-Web-React

A Web library to simply integrate Agora Video Calling or Live Video Streaming to your website with just a few lines of code.
MIT License
53 stars 44 forks source link

Unable to find the sendChannelMessage method #12

Closed monizb closed 1 year ago

monizb commented 2 years ago

I am trying to integrate Agora UI Kits into my react app, the connection part works and I am able to connect to both RTM and RTC channels, now I want to be able to send a message to everyone in the channel, I see there is a "sendChannelMessage" method under "RtmContext" in the library but I am unable to figure out how to import and use this method? Even if I import RtmContext it doesn't seem to expose the sendChannelMessage method somehow? Please help me, thanks!

I tried referring to this: https://agoraio-community.github.io/Web-React-UIKit/interfaces/_internal_.rtmContext.html#sendChannelMessage but I'm unable to understand how to import this into React

EkaanshArora commented 2 years ago

Hi Monish, sorry about the delayed response. You can access the sendChannelMessage method from the RtmContext like you mentioned. Here's a snippet:

let MyComp = () => {
  const { sendChannelMessage } = useContext(RtmContext)

  return (
    <div onClick={() => sendChannelMessage({ messageType: 'RtmDataRequest', type: 'ping' })}>
      send
    </div>
  )
}

You can inject the component like so:

          <PropsContext.Provider value={{
            rtcProps: {
              appId: APP_ID,
              channel: 'test',
            }}}>
              <TracksConfigure>
                <VideocallUI />
                <MyComp />
              </TracksConfigure>
          </PropsContext.Provider></>

If you can describe the use-case, I'll update the messageObject type to add a user customizable type that can be used to send custom messages in a future update, I think there's scope to add more flexibility with sending messages.

EkaanshArora commented 1 year ago

closing due to inactivity