use-fb-call
v1.2.2
Published
A React hook for managing voice calls using FocusBuddy Infra.
Downloads
606
Readme
use-fb-call
A React hook for managing voice calls using FocusBuddy Infra.
Installation
npm install use-fb-call
Usage
import { useFBCall, type FBConnection } from 'use-fb-call';
import { type FC } from 'react';
const MyComponent: FC = () => {
const { isConnected, startCall, endCall, activeConnection } = useFBCall({
device_id: "your_device_id",
prompt: "Initial conversation prompt",
responseHandlerUrl: "http://your-api.com/handle-responses"
});
const handleMute = () => {
if (activeConnection) {
activeConnection.mute(true);
}
};
return (
<div>
<button onClick={startCall} disabled={isConnected}>
Start Call
</button>
<button onClick={endCall} disabled={!isConnected}>
End Call
</button>
<button onClick={handleMute} disabled={!isConnected}>
Mute
</button>
</div>
);
};
API
Props
| Prop | Type | Description | |------|------|-------------| | device_id | string | Unique identifier for the device | | prompt | string | Initial prompt for the conversation | | responseHandlerUrl | string | URL that will receive call responses |
Returns
| Value | Type | Description | |-------|------|-------------| | isConnected | boolean | Whether call is active | | startCall | () => Promise | Start a call | | endCall | () => Promise | End current call | | activeConnection | FBConnection | null | The Twilio Connection object if connected |
The activeConnection
object provides methods for controlling the call (mute, volume, etc). See Twilio's Connection documentation for all available methods.
Requirements
- React 16.8+
- Twilio Client
- Backend server running on http://localhost:5000 (configurable)