AI Agent Component Spec
AI Agent Component Spec
Overview
CometChatSoundManager is a helper class for managing audio cues in the UI Kit. Use it to play default sounds or custom audio files for calls and messages.
Time estimate: 5 minutesDifficulty: Beginner
Prerequisites
- React.js integration completed
Steps
Step 1: Import the sound manager
Step 2: Play default sounds
Use the built-in sounds for common events:Step 3: Use custom sounds
Pass a custom audio file URL as the second argument:Step 4: Use convenience methods
Direct methods for common scenarios:Step 5: Check user interaction
Browsers require user interaction before playing audio. Check if the user has interacted:Complete Example
Sound Events Reference
| Event | When it plays | Loops |
|---|---|---|
incomingCall | Incoming call detected | Yes |
outgoingCall | Outgoing call initiated | Yes |
incomingMessage | New message in current conversation | No |
incomingMessageFromOther | New message from different conversation | No |
outgoingMessage | Message sent | No |
Methods Reference
| Method | Parameters | Description |
|---|---|---|
play(sound, customSound?) | Sound event key, optional URL | Play sound |
pause() | None | Stop current sound |
onIncomingCall(customSound?) | Optional URL | Play incoming call |
onOutgoingCall(customSound?) | Optional URL | Play outgoing call |
onIncomingMessage(customSound?) | Optional URL | Play incoming message |
onIncomingOtherMessage(customSound?) | Optional URL | Play other message |
onOutgoingMessage(customSound?) | Optional URL | Play outgoing message |
hasInteracted() | None | Check user interaction |
Common Issues
| Issue | Solution |
|---|---|
| Sound not playing | Check hasInteracted() - user may need to interact first |
| Sound keeps looping | Call pause() when call ends |
| Custom sound not found | Verify the audio file path is correct |