React SIP
React wrapper for jssip.
Installation
npm install react-sip
There is no need to install jssip
as it is a dependency of react-sip
.
Usage
;; ReactDOM;
Child components get access to this context:
sip: sipType call: callType registerSip: PropTypesfunc unregisterSip: PropTypesfunc answerCall: PropTypesfunc startCall: PropTypesfunc stopCall: PropTypesfunc
See lib/types.ts for technical details of what sipType
and callType
are.
An overview is given below:
sip
sip.status
represents SIP connection status and equals to one of these values:
'sipStatus/DISCONNECTED'
whenhost
,port
oruser
is not defined'sipStatus/CONNECTING'
'sipStatus/CONNECTED'
'sipStatus/REGISTERED'
after callingregisterSip
or after'sipStatus/CONNECTED'
whenautoRegister
is true'sipStatus/ERROR'
in case of configuration, connection or registration problems
sip.errorType
:
null
whensip.status
is not'sipStatus/ERROR'
'sipErrorType/CONFIGURATION'
'sipErrorType/CONNECTION'
'sipErrorType/REGISTRATION'
sip.host
, sip.port
, sip.user
, ...
– <SipProvider />
’s props (to make them easy to be displayed in the UI).
call
call.id
is a unique session id of the actual established voice call; undefined
between calls
call.status
represents the status of the call:
'callStatus/IDLE'
between calls (even when disconnected)'callStatus/STARTING'
active incoming or outgoing call request'callStatus/ACTIVE'
during ongoing call'callStatus/STOPPING'
during call cancelation request
call.direction
indicates the direction of the ongoing call:
null
between calls'callDirection/INCOMING'
'callDirection/OUTGOING'
call.counterpart
represents the call destination in case of outgoing call and caller for
incoming calls.
The format depends on the configuration of the SIP server (e.g. "bob" <+441234567890@sip.example.com>
, +441234567890@sip.example.com
or bob@sip.example.com
).
methods
When autoRegister
is set to false
, you can call sipRegister()
and sipUnregister()
manually for advanced registration scenarios.
To make calls, simply use these functions:
answerCall()
startCall(destination)
stopCall()
The value for destination
argument equals to the target SIP user without the host part (e.g. +441234567890
or bob
).
The omitted host part is equal to host you’ve defined in SipProvider
props (e.g. sip.example.com
).
The values for sip.status
, sip.errorType
, call.status
and call.direction
can be imported as constants to make typos easier to detect:
;
Custom PropTypes types are also provided by the library:
;