Package javaforce.voip
Class SIPClient
java.lang.Object
javaforce.voip.SIP
javaforce.voip.SIPClient
- All Implemented Interfaces:
STUN.Listener,SIPInterface,TransportInterface
Handles the client end of a SIP link.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanSends a reply to accept an inbound (re)INVITE.booleanSend a request to terminate a call in progress.booleanCancels an INVITE request.booleanDenies an INVITE for whatever reason.String[]getHeaders(String callid) Returns local RTP IP address.Returns the remote host.String[]Returns the raw SDP from onSuccess() eventgetUser()Returns the registered user name.booleaninit(String remotehost, int remoteport, int localport, SIPClientInterface iface, TransportType type) Initialize this instance for SIP.Send an invite to server.booleanisCaller()booleanDetermines if the SIP call is currently on hold.static booleanDetermine if server is on a local private network.booleanReturns the registration status.voidSend an empty SIP message to server.voidLogs all SIP messages to a log file.Send instant message.Send instant message.voidProcesses SIP messages sent from the SIP server.booleanPublishes Presence to server.booleanSends a reply to accept an inbound REINVITE.booleanSend a refer command to server (blind transfer)booleanSend a refer command to server (non-blind transfer)booleanRegisters this client with the SIP server/proxy.booleanRegisters this client with the SIP server/proxy.booleanSends a reINVITE to server using previous SDP packet.booleanSends a reINVITE to server with a new SDP packet.booleanReregister with the server.booleanresubscribe(String callid, String subuser, String event, int expires) Resubscribe a previously subscribed user.static voidsetEnableReceived(boolean state) static voidsetEnableRport(boolean state) booleanSet/clear hold state, must call reinvite() after to notify server.voidsetMessageURI(String prefix) Sets URI prefix for message() Default = "sip" Some servers user "im".static voidsetNAT(SIPClient.NAT nat, String host, String user, String pass) Sets the type of NAT traversal type (global setting).voidsetremoteport(int port) voidsetUserPass(String user, String pass) voidstunPublicIP(STUN stun, String ip, int port) Subscribe to a user's presence on server.voidvoidvoidvoidturnFailed(STUN stun) voidturnRefresh(STUN stun, int lifetime) voiduninit()Free all resources.booleanReregister with the server using an expiration of 0 (zero).booleanunsubscribe(String callid, String subuser, String event) Unsubscribe a previously subscribed user.static voiduseNATOnPrivateNetwork(boolean state) Disable/enable use of NAT traversal on private networks (global setting) Private networks : 192.168.x.x , 10.x.x.x , 172.[16-31].x.xMethods inherited from class javaforce.voip.SIP
addCodec, buildsdp, convertParameters, delCodec, generatetag, getAuthResponse, getbranch, getbranch, getcallid, getCodec, getCodecName, getcseq, getcseqcmd, getexpires, getFlag2, getnonce, getNow, getremote_audio_rtp_port, getremote_video_rtp_port, getremotertphost, getRequest, getResponse, getResponseType, getrinstance, getroutelist, getSDP, gettag, gettupleid, geturi, getURI, getvialist, hasCodec, init, ishold, join, onConnect, onDisconnect, removetag, replacetag, resolve, send, setFlag2, setResolver, setResolver, split
-
Field Details
-
rtmp
-
userobj
-
expires
public int expires
-
-
Constructor Details
-
SIPClient
public SIPClient()
-
-
Method Details
-
getUser
Returns the registered user name. -
getRemoteHost
Returns the remote host. -
isHold
Determines if the SIP call is currently on hold. -
isRegistered
public boolean isRegistered()Returns the registration status. -
init
public boolean init(String remotehost, int remoteport, int localport, SIPClientInterface iface, TransportType type) Initialize this instance for SIP.- Parameters:
remotehost- ,remoteport is the SIP Server/Proxy address.localport- is the UDP port to bind to locally.iface- must be a SIPClientInterface where SIP events are dispatched to.
-
uninit
public void uninit()Free all resources. -
log
Logs all SIP messages to a log file.- Parameters:
id- = JFLog id (0 = default and should not be used)file- = log file
-
setNAT
Sets the type of NAT traversal type (global setting). -
useNATOnPrivateNetwork
public static void useNATOnPrivateNetwork(boolean state) Disable/enable use of NAT traversal on private networks (global setting) Private networks : 192.168.x.x , 10.x.x.x , 172.[16-31].x.x -
register
Registers this client with the SIP server/proxy.- Parameters:
displayName- : display nameuserAccount- : usernameauthName- : authorization name (optional, default=user)password- : password- Returns:
- : if message was sent to server successfully
This function does not block waiting for a reply. You should receive onRegister() thru the SIPClientInterface when a reply is returned from server.
-
register
public boolean register(String displayName, String userAccount, String authName, String password, int expires) Registers this client with the SIP server/proxy.- Parameters:
displayName- : display name (usually same as userAccount)userAccount- : usernameauthName- : authorization name (optional, default=userAccount)password- : passwordexpires- : number seconds to register for (0=unregisters)- Returns:
- : if message was sent to server
This function does not block waiting for a reply. You should receive either registered() or unauthorized() thru the SIPClientInterface when a reply is returned from server.
-
reregister
public boolean reregister()Reregister with the server. -
unregister
public boolean unregister()Reregister with the server using an expiration of 0 (zero). Effectively unregisters. -
publish
Publishes Presence to server. (not tested since Asterisk doesn't support it) -
subscribe
Subscribe to a user's presence on server. RFC : 3265- Returns:
- Call-ID
-
resubscribe
Resubscribe a previously subscribed user. -
unsubscribe
Unsubscribe a previously subscribed user. Re-sends a subscribe with expires set to zero. NOTE:Should receive last NOTIFY as confirmation. -
keepalive
public void keepalive()Send an empty SIP message to server. This should be done periodically to keep firewalls open. Most routers close UDP connections after 60 seconds. Not sure if needed with TCP/TLS but is done anyways. -
isPrivateNetwork
Determine if server is on a local private network. -
getlocalRTPhost
Returns local RTP IP address.- Specified by:
getlocalRTPhostin classSIP
-
stunPublicIP
- Specified by:
stunPublicIPin interfaceSTUN.Listener
-
turnAlloc
- Specified by:
turnAllocin interfaceSTUN.Listener
-
turnBind
- Specified by:
turnBindin interfaceSTUN.Listener
-
turnRefresh
- Specified by:
turnRefreshin interfaceSTUN.Listener
-
turnFailed
- Specified by:
turnFailedin interfaceSTUN.Listener
-
turnData
- Specified by:
turnDatain interfaceSTUN.Listener
-
invite
Send an invite to server.- Parameters:
to- : number to dialsdp- : SDP (only stream types/modes/codecs are needed)- Returns:
- unique Call-ID (not caller id)
-
refer
Send a refer command to server (blind transfer) -
referLive
Send a refer command to server (non-blind transfer) -
setHold
Set/clear hold state, must call reinvite() after to notify server. -
reinvite
Sends a reINVITE to server with a new SDP packet.- Parameters:
callid- : id of call to reinvitesdp- : SDP (only stream types/modes/codecs are needed) (ip not needed)
-
reinvite
Sends a reINVITE to server using previous SDP packet.- Parameters:
callid- : id of call to reinvite
-
cancel
Cancels an INVITE request. Usually done while phone is ringing. -
bye
Send a request to terminate a call in progress. -
message
Send instant message. Outside of a dialog. See RFC 3428 TODO : RFC 4975 for rich text messages. -
message
Send instant message. Within current dialog. See RFC 3428 TODO : RFC 4975 for rich text messages. -
setMessageURI
Sets URI prefix for message() Default = "sip" Some servers user "im". -
accept
Sends a reply to accept an inbound (re)INVITE.- Parameters:
sdp- : SDP (only stream types/modes/codecs are needed) (ip not needed)
-
reaccept
Sends a reply to accept an inbound REINVITE.- Parameters:
sdp- : SDP (only stream types/modes/codecs are needed) (ip not needed)
-
deny
Denies an INVITE for whatever reason. -
setUserPass
-
packet
Processes SIP messages sent from the SIP server.- Specified by:
packetin interfaceSIPInterface
-
setremoteport
public void setremoteport(int port) - Overrides:
setremoteportin classSIP
-
setEnableRport
public static void setEnableRport(boolean state) -
setEnableReceived
public static void setEnableReceived(boolean state) -
getSDP
Returns the raw SDP from onSuccess() event -
getHeaders
-
isCaller
public boolean isCaller()
-