This message was deleted.
# helpdesk
s
This message was deleted.
👀 1
d
Can you describe what is the problem?
Or linking to previous issues if possible 🙂
b
This is the problem we faced, when we emit one data message or any event, listeners triggered multiple times. Example:- 1. When we send one message through data event. data received listener receives several of same message. (And the receiving message count increase as the participant count goes high.) 2. Same goes with every event. When we change participant meta data, participantMetaChange event triggered several times not only one. Same goes with the disconnect event and so on.
f
Thank you @dry-elephant-14928 for your feedback. Please find the issue details below; ----------------------------------------------------------------------------------------------------------- Describe the bug: In React-sdk and react-native-sdk , when we emit one data message or any event, listeners (specifically RoomEvent.DataReceived) triggered multiple times for that one data message pass. Example:- 1. When we send one message through data event. data received listener receives several of same message. (And the receiving message count increase as the participant count goes high.) 2. Same goes with every event. When we change participant meta data, participantMetaChange event triggered several times not only one. Same goes with the disconnect event and so on. To Reproduce : Per Data messages ( https://docs.livekit.io/realtime/client/data-messages/#data-messages ) doc, • Step 1: One client publish data (this can be a chat message sending to other participants)
Copy code
// publish reliable data to a set of participants
room.localParticipant.publishData(data, DataPacket_Kind.RELIABLE, ['participant_sid'])
• Step 2: Receive data from other particpants via RoomEvent.DataReceived event listener
Copy code
// receive data from other participants
room.on(RoomEvent.DataReceived, (payload: Uint8Array, participant: Participant, kind: DataPacket_Kind) => {
  const strData = decoder.decode(payload)
   //log strData in console log 
  ...
})
• In Step 2, for the one message published in Step 1 will trigger more than one trigger/event in Step 2 > console.log output Expected behavior: When a single message emit data via xxxx.PubishData function, it should only trigger one attempt in RoomEvent.DataReceived event listener when data is received to the client. Actual behavior: When a single message emit data via xxxx.PubishData function, it trigger many attempts (some time 10. sometimes 100+) in RoomEvent.DataReceived event listener when data is received to the client. Screencap of the errors or additional context: - source code that can be used to reproduce the code : https://github.com/udaraJ08/livekit-data-event-bug-reproduce-repo.git - this include the latest livekit example source code ( "livekit/components-react": "^1.1.8" - https://github.com/udaraJ08/livekit-data-event-bug-reproduce-repo/blob/58fef06837fc7af7bc4ee770017957ef4b285791/package.json#L9C9-L9C9) with minimal update to reproduce the bug • Attached screencap of the issue reproduce for your reference. -------------------------------------------------------------------------------------------------------- We greatly appreciate you guys insights into this to sort the issue as soon as possible.
RoomEvent.DataReceived console log code can be found in
d
the problem is likely you are register this callback multiple times. This is unlikely to be a livekit bug. Check your listener registrations to make sure they are surrounded by
useEffect
and such
f
Thanks @dry-elephant-14928. Will look into this and confirm.
b
Hey, @dry-elephant-14928 we moved the data recived event inside an useEffect, but the problem still persist. I also updated the repo with the useEffect update and also put a new log with timestamp
f
Hi @dry-elephant-14928 @polite-kilobyte-67570 any insight to sort the issue is really appreciated
p
thanks for the reproduction code, but this repository is huge 👀 Could you please isolate the issue further so that there’s a single page and only the necessary bits to reproduce the issue? (e.g. no redux/axios etc.) You can start from one of the components examples if you want
b
@polite-kilobyte-67570 will reduce the repo furthermore and share, thank you for the update
🙏 2
hey, @polite-kilobyte-67570 @eager-zoo-16408 updated the repo with removing all the unnecessary codes, and packages and minimized it.
p
thanks for that. the
useEffect
here never unsubscribes. So whenever the effect runs again you add additional handlers. There’s two ways to solve this: 1. Return a function in that useEffect that unsubscribes from the event 2. use the
useDataChannel(onDataMessage)
hook instead (recommended)
b
Thnx for the insights @polite-kilobyte-67570, will chk on that !
👍 1
p
had a typo in the hook name, fixed