Skip to content

Commit

Permalink
wip example on publishing data and receiving it
Browse files Browse the repository at this point in the history
thus we can easily build the raise hand features, notifying everyone user X has raised hand.
However, this feature is not simple, and will take few days, let's write a brief first.
  • Loading branch information
lebaudantoine committed Aug 4, 2024
1 parent 3c1bded commit 2a4b735
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/frontend/src/features/rooms/components/Conference.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,28 @@ export const Conference = ({
await track.videoTrack.stopProcessor();
}


room.on('dataReceived', (payload, participant) => {
const message = new TextDecoder().decode(payload);
console.log(`Received message from ${participant?.identity}: ${message}`);
});

const sendMessage = async (message) => {
// Convert message to a Uint8Array

console.log('clicked')
const payload = new TextEncoder().encode(message);

// Send the message to all participants in the room
await room.localParticipant.publishData(payload, 'text/plain');
}

return (
<QueryAware status={status}>
<Screen>
<button onClick={() => blurTrack()}>blur</button>
<button onClick={() => unBlurTrack()}>unblur</button>
<button onClick={() => sendMessage('raise hand')}>raise hand</button>
<LiveKitRoom
room={room}
serverUrl={data?.livekit?.url}
Expand Down

0 comments on commit 2a4b735

Please sign in to comment.