I am using <VideoConference /> component imp...
# ask-ai
b
I am using <VideoConference /> component imported from "@livekit/components-react", when i open chat box it only shows live chat messages, how to show message sender's identity as well with message?
t
Thanks for reaching out, boris. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To display the sender's identity along with chat messages in the
<VideoConference />
component, you can utilize the
useChat
hook provided by LiveKit. This hook gives access to message objects that include sender information in the
from
property. Here's an example:
Copy code
import { useChat } from '@livekit/components-react';

export default function Chat() {
  const { messages, send, isSending } = useChat();
  // messages contain sender information in the 'from' property
}
If you're using the pre-built
<chatentry />
component, it displays the sender's name by default. You can control this behavior with the
hideName
property:
Copy code
<chat>
  <chatentry hidename="{false}" />
</chat>
Setting
hideName
to
false
(default) ensures that the sender's name is displayed. This is particularly useful for showing the identity of the message sender. Let me know if you need further assistance! Sources: Add chat to your React app | LiveKit Docs | ChatEntry | React Components | LiveKit Docs
b
if i want to make UI with custom building blocks and i dont want to use prebuilt chat buttons how can i get real video screen
t
To create a custom video screen interface without using prebuilt chat buttons, LiveKit provides a variety of building blocks that you can use: • Layout Components: Use components like
GridLayout
,
CarouselLayout
, or
FocusLayout
to arrange video and audio tracks. • Participant Components: Render participant media using components such as
VideoTrack
,
AudioTrack
,
ParticipantTile
,
ParticipantName
,
ConnectionQualityIndicator
, and
TrackMutedIndicator
. • Control Components: Manage media with components like
DisconnectButton
,
TrackToggle
,
MediaDeviceSelect
,
StartAudio
,
ClearPinButton
, and
FocusToggle
. • Hooks: For more control, you can use hooks such as
useTracks
,
useParticipants
, and
useConnectionState
. These components and hooks allow you to build a fully customized video interface while maintaining flexibility in design and functionality. Let me know if you need further guidance! Sources: LiveKit Docs | LiveKit Docs | Building blocks | LiveKit Docs
b
ok so give code example as well
t
While I couldn't find a complete code example in the knowledge base, I can provide you with a basic example of how to create a custom video screen using LiveKit's building blocks:
Copy code
import React from 'react';
import {
  VideoTrack,
  ParticipantTile,
  GridLayout,
  useParticipants
} from '@livekit/components-react';

export default function CustomVideoScreen() {
  const { participants } = useParticipants();

  return (
    
      
    
  );
}
This example uses the
GridLayout
component to arrange participant video tiles. Each tile includes a
VideoTrack
component to display the participant's video. You can further customize the layout and styling as needed. Let me know if you need help with specific customizations or additional features!
b
<VideoConference chatMessageFormatter={{}}/> how to use chatMessageFormatter
t
The
chatMessageFormatter
is an optional property that you can pass to the
<VideoConference />
component to customize the formatting of chat messages. Here's an example of how to use it:
Copy code
const customFormatter = (message) => {
  // Customize the message format here
  return `${message.from}: ${message.text}`;
};

<VideoConference chatMessageFormatter={customFormatter} />
In this example, the
customFormatter
function takes a message object as input and returns a formatted string. You can modify the function to include additional details or apply specific formatting as needed. Let me know if you need further assistance with implementing this! Sources: VideoConference | React Components | LiveKit Docs
b
but i am getting only a single message string in message const customFormatter = (message) => { // Customize the message format here return `${message.from}: ${message.text}`; };
t
It seems that the
chatMessageFormatter
in the
<VideoConference />
component currently receives only a single message string as input, rather than a full message object with properties like
from
or
text
. This means that the formatter function can only modify the string itself, not add additional details like the sender's identity. If you need to include more information in the formatted message, you may need to customize the chat functionality further or use a different approach to access the full message object. Let me know if you'd like guidance on alternative solutions! Sources: Chat | React Components | LiveKit Docs | VideoConference | React Components | LiveKit Docs | ChatEntry | React Components | LiveKit Docs