This project demonstrates how to integrate SIP.js with a React application. It provides a SIP context that can be used to make and receive calls within a React component.
- Node.js and npm installed on your machine
- Basic understanding of React
- install the repository: npm install git+https://github.com/Winston87245/react-sip.git#master
- import SipContextProvider
import { SipContextProvider, PhoneComponent } from 'react-sip';
- set sip config
function App() {
const sipConfig = {
baseUri: "sip.example.com",
server: "ws:sip.example.com",
aor: "sip:user1@sip.example.com",
userAgentOptions: {
authorizationUsername: "user1",
authorizationPassword: "password",
}
}
return (
<SipContextProvider sipConfig={sipConfig} >
<PhoneComponent />
</SipContextProvider>
);
}
or you use SipContext to build your own component
import { SipContext } from 'react-sip';
// Example of using the SipContext in a component
const MyComponent: React.FC = () => {
const { state, call, hangup } = React.useContext(SipContext);
const [destination, setDestination] = useState('');
const handleCall = () => {
call(destination);
};
const handleHangup = () => {
hangup();
};
return (
<div>
<input
type="text"
value={destination}
onChange={(e) => setDestination(e.target.value)}
placeholder="Enter destination"
/>
<button onClick={handleCall} disabled={state !== SipState.idle}>
Call
</button>
<button onClick={handleHangup} disabled={state !== SipState.connected}>
Hang Up
</button>
<div>Current State: {state}</div>
</div>
);
}
Contributions are always welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request.
Please make sure to update tests as appropriate.
git commit -m "Add README with project overview and getting started guide"
Distributed under the MIT License. See LICENSE
for more information.