Class SIPClient

java.lang.Object
javaforce.voip.SIP
javaforce.voip.SIPClient
All Implemented Interfaces:
STUN.Listener, SIPInterface, TransportInterface

public class SIPClient extends SIP implements SIPInterface, STUN.Listener
Handles the client end of a SIP link.
  • Field Details

    • rtmp

      public Object rtmp
    • userobj

      public Object userobj
    • expires

      public int expires
  • Constructor Details

    • SIPClient

      public SIPClient()
  • Method Details

    • getUser

      public String getUser()
      Returns the registered user name.
    • getRemoteHost

      public String getRemoteHost()
      Returns the remote host.
    • isHold

      public boolean isHold(String callid)
      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.
      Overrides:
      uninit in class SIP
    • log

      public void log(int id, String file)
      Logs all SIP messages to a log file.
      Parameters:
      id - = JFLog id (0 = default and should not be used)
      file - = log file
    • setNAT

      public static void setNAT(SIPClient.NAT nat, String host, String user, String pass)
      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

      public boolean register(String displayName, String userAccount, String authName, String password)
      Registers this client with the SIP server/proxy.
      Parameters:
      displayName - : display name
      userAccount - : username
      authName - : 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 - : username
      authName - : authorization name (optional, default=userAccount)
      password - : password
      expires - : 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

      public boolean publish(String state)
      Publishes Presence to server. (not tested since Asterisk doesn't support it)
    • subscribe

      public String subscribe(String subuser, String event, int expires)
      Subscribe to a user's presence on server. RFC : 3265
      Returns:
      Call-ID
    • resubscribe

      public boolean resubscribe(String callid, String subuser, String event, int expires)
      Resubscribe a previously subscribed user.
    • unsubscribe

      public boolean unsubscribe(String callid, String subuser, String event)
      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

      public static boolean isPrivateNetwork(String ip)
      Determine if server is on a local private network.
    • getlocalRTPhost

      public String getlocalRTPhost(CallDetails cd)
      Returns local RTP IP address.
      Specified by:
      getlocalRTPhost in class SIP
    • stunPublicIP

      public void stunPublicIP(STUN stun, String ip, int port)
      Specified by:
      stunPublicIP in interface STUN.Listener
    • turnAlloc

      public void turnAlloc(STUN stun, String ip, int port, byte[] token, int lifetime)
      Specified by:
      turnAlloc in interface STUN.Listener
    • turnBind

      public void turnBind(STUN stun)
      Specified by:
      turnBind in interface STUN.Listener
    • turnRefresh

      public void turnRefresh(STUN stun, int lifetime)
      Specified by:
      turnRefresh in interface STUN.Listener
    • turnFailed

      public void turnFailed(STUN stun)
      Specified by:
      turnFailed in interface STUN.Listener
    • turnData

      public void turnData(STUN stun, byte[] data, int offset, int length, short channel)
      Specified by:
      turnData in interface STUN.Listener
    • invite

      public String invite(String to, SDP sdp)
      Send an invite to server.
      Parameters:
      to - : number to dial
      sdp - : SDP (only stream types/modes/codecs are needed)
      Returns:
      unique Call-ID (not caller id)
    • refer

      public boolean refer(String callid, String to)
      Send a refer command to server (blind transfer)
    • referLive

      public boolean referLive(String callid, String othercallid)
      Send a refer command to server (non-blind transfer)
    • setHold

      public boolean setHold(String callid, boolean state)
      Set/clear hold state, must call reinvite() after to notify server.
    • reinvite

      public boolean reinvite(String callid, SDP sdp)
      Sends a reINVITE to server with a new SDP packet.
      Parameters:
      callid - : id of call to reinvite
      sdp - : SDP (only stream types/modes/codecs are needed) (ip not needed)
    • reinvite

      public boolean reinvite(String callid)
      Sends a reINVITE to server using previous SDP packet.
      Parameters:
      callid - : id of call to reinvite
    • cancel

      public boolean cancel(String callid)
      Cancels an INVITE request. Usually done while phone is ringing.
    • bye

      public boolean bye(String callid)
      Send a request to terminate a call in progress.
    • message

      public String message(String to, String[] msg)
      Send instant message. Outside of a dialog. See RFC 3428 TODO : RFC 4975 for rich text messages.
    • message

      public String message(String callid, String to, String[] msg)
      Send instant message. Within current dialog. See RFC 3428 TODO : RFC 4975 for rich text messages.
    • setMessageURI

      public void setMessageURI(String prefix)
      Sets URI prefix for message() Default = "sip" Some servers user "im".
    • accept

      public boolean accept(String callid, SDP sdp)
      Sends a reply to accept an inbound (re)INVITE.
      Parameters:
      sdp - : SDP (only stream types/modes/codecs are needed) (ip not needed)
    • reaccept

      public boolean reaccept(String callid, SDP sdp)
      Sends a reply to accept an inbound REINVITE.
      Parameters:
      sdp - : SDP (only stream types/modes/codecs are needed) (ip not needed)
    • deny

      public boolean deny(String callid, String msg, int code)
      Denies an INVITE for whatever reason.
    • setUserPass

      public void setUserPass(String user, String pass)
    • packet

      public void packet(String[] msg, String remoteip, int remoteport)
      Processes SIP messages sent from the SIP server.
      Specified by:
      packet in interface SIPInterface
    • setremoteport

      public void setremoteport(int port)
      Overrides:
      setremoteport in class SIP
    • setEnableRport

      public static void setEnableRport(boolean state)
    • setEnableReceived

      public static void setEnableReceived(boolean state)
    • getSDP

      public String[] getSDP(String callid)
      Returns the raw SDP from onSuccess() event
    • getHeaders

      public String[] getHeaders(String callid)
    • isCaller

      public boolean isCaller()