FileDocCategorySizeDatePackage
SipSession.javaAPI DocAndroid 5.1 API19082Thu Mar 12 22:22:52 GMT 2015android.net.sip

SipSession

public final class SipSession extends Object
Represents a SIP session that is associated with a SIP dialog or a standalone transaction not within a dialog.

You can get a {@link SipSession} from {@link SipManager} with {@link SipManager#createSipSession createSipSession()} (when initiating calls) or {@link SipManager#getSessionFor getSessionFor()} (when receiving calls).

Fields Summary
private static final String
TAG
private final ISipSession
mSession
private Listener
mListener
Constructors Summary
SipSession(ISipSession realSession)

        mSession = realSession;
        if (realSession != null) {
            try {
                realSession.setListener(createListener());
            } catch (RemoteException e) {
                loge("SipSession.setListener:", e);
            }
        }
    
SipSession(ISipSession realSession, Listener listener)

        this(realSession);
        setListener(listener);
    
Methods Summary
public voidanswerCall(java.lang.String sessionDescription, int timeout)
Answers an incoming call with the specified session description. The method is only valid to call when the session state is in {@link State#INCOMING_CALL}.

param
sessionDescription the session description to answer this call
param
timeout the session will be timed out if the call is not established within {@code timeout} seconds. Default value (defined by SIP protocol) is used if {@code timeout} is zero or negative.

        try {
            mSession.answerCall(sessionDescription, timeout);
        } catch (RemoteException e) {
            loge("answerCall:", e);
        }
    
public voidchangeCall(java.lang.String sessionDescription, int timeout)
Changes the session description during a call. The method is only valid to call when the session state is in {@link State#IN_CALL}.

param
sessionDescription the new session description
param
timeout the session will be timed out if the call is not established within {@code timeout} seconds. Default value (defined by SIP protocol) is used if {@code timeout} is zero or negative.

        try {
            mSession.changeCall(sessionDescription, timeout);
        } catch (RemoteException e) {
            loge("changeCall:", e);
        }
    
private ISipSessionListenercreateListener()

        return new ISipSessionListener.Stub() {
            @Override
            public void onCalling(ISipSession session) {
                if (mListener != null) {
                    mListener.onCalling(SipSession.this);
                }
            }

            @Override
            public void onRinging(ISipSession session, SipProfile caller,
                    String sessionDescription) {
                if (mListener != null) {
                    mListener.onRinging(SipSession.this, caller,
                            sessionDescription);
                }
            }

            @Override
            public void onRingingBack(ISipSession session) {
                if (mListener != null) {
                    mListener.onRingingBack(SipSession.this);
                }
            }

            @Override
            public void onCallEstablished(ISipSession session,
                    String sessionDescription) {
                if (mListener != null) {
                    mListener.onCallEstablished(SipSession.this,
                            sessionDescription);
                }
            }

            @Override
            public void onCallEnded(ISipSession session) {
                if (mListener != null) {
                    mListener.onCallEnded(SipSession.this);
                }
            }

            @Override
            public void onCallBusy(ISipSession session) {
                if (mListener != null) {
                    mListener.onCallBusy(SipSession.this);
                }
            }

            @Override
            public void onCallTransferring(ISipSession session,
                    String sessionDescription) {
                if (mListener != null) {
                    mListener.onCallTransferring(
                            new SipSession(session, SipSession.this.mListener),
                            sessionDescription);

                }
            }

            @Override
            public void onCallChangeFailed(ISipSession session, int errorCode,
                    String message) {
                if (mListener != null) {
                    mListener.onCallChangeFailed(SipSession.this, errorCode,
                            message);
                }
            }

            @Override
            public void onError(ISipSession session, int errorCode, String message) {
                if (mListener != null) {
                    mListener.onError(SipSession.this, errorCode, message);
                }
            }

            @Override
            public void onRegistering(ISipSession session) {
                if (mListener != null) {
                    mListener.onRegistering(SipSession.this);
                }
            }

            @Override
            public void onRegistrationDone(ISipSession session, int duration) {
                if (mListener != null) {
                    mListener.onRegistrationDone(SipSession.this, duration);
                }
            }

            @Override
            public void onRegistrationFailed(ISipSession session, int errorCode,
                    String message) {
                if (mListener != null) {
                    mListener.onRegistrationFailed(SipSession.this, errorCode,
                            message);
                }
            }

            @Override
            public void onRegistrationTimeout(ISipSession session) {
                if (mListener != null) {
                    mListener.onRegistrationTimeout(SipSession.this);
                }
            }
        };
    
public voidendCall()
Ends an established call, terminates an outgoing call or rejects an incoming call. The method is only valid to call when the session state is in {@link State#IN_CALL}, {@link State#INCOMING_CALL}, {@link State#OUTGOING_CALL} or {@link State#OUTGOING_CALL_RING_BACK}.

        try {
            mSession.endCall();
        } catch (RemoteException e) {
            loge("endCall:", e);
        }
    
public java.lang.StringgetCallId()
Gets the call ID of the session.

return
the call ID

        try {
            return mSession.getCallId();
        } catch (RemoteException e) {
            loge("getCallId:", e);
            return null;
        }
    
public java.lang.StringgetLocalIp()
Gets the IP address of the local host on which this SIP session runs.

return
the IP address of the local host

        try {
            return mSession.getLocalIp();
        } catch (RemoteException e) {
            loge("getLocalIp:", e);
            return "127.0.0.1";
        }
    
public SipProfilegetLocalProfile()
Gets the SIP profile that this session is associated with.

return
the SIP profile that this session is associated with

        try {
            return mSession.getLocalProfile();
        } catch (RemoteException e) {
            loge("getLocalProfile:", e);
            return null;
        }
    
public SipProfilegetPeerProfile()
Gets the SIP profile that this session is connected to. Only available when the session is associated with a SIP dialog.

return
the SIP profile that this session is connected to

        try {
            return mSession.getPeerProfile();
        } catch (RemoteException e) {
            loge("getPeerProfile:", e);
            return null;
        }
    
ISipSessiongetRealSession()

        return mSession;
    
public intgetState()
Gets the session state. The value returned must be one of the states in {@link State}.

return
the session state

        try {
            return mSession.getState();
        } catch (RemoteException e) {
            loge("getState:", e);
            return State.NOT_DEFINED;
        }
    
public booleanisInCall()
Checks if the session is in a call.

return
true if the session is in a call

        try {
            return mSession.isInCall();
        } catch (RemoteException e) {
            loge("isInCall:", e);
            return false;
        }
    
private voidloge(java.lang.String s, java.lang.Throwable t)

        Rlog.e(TAG, s, t);
    
public voidmakeCall(SipProfile callee, java.lang.String sessionDescription, int timeout)
Initiates a call to the specified profile. The session listener is called back upon defined session events. The method is only valid to call when the session state is in {@link State#READY_TO_CALL}.

param
callee the SIP profile to make the call to
param
sessionDescription the session description of this call
param
timeout the session will be timed out if the call is not established within {@code timeout} seconds. Default value (defined by SIP protocol) is used if {@code timeout} is zero or negative.
see
Listener

        try {
            mSession.makeCall(callee, sessionDescription, timeout);
        } catch (RemoteException e) {
            loge("makeCall:", e);
        }
    
public voidregister(int duration)
Performs registration to the server specified by the associated local profile. The session listener is called back upon success or failure of registration. The method is only valid to call when the session state is in {@link State#READY_TO_CALL}.

param
duration duration in second before the registration expires
see
Listener

        try {
            mSession.register(duration);
        } catch (RemoteException e) {
            loge("register:", e);
        }
    
public voidsetListener(android.net.sip.SipSession$Listener listener)
Sets the listener to listen to the session events. A {@code SipSession} can only hold one listener at a time. Subsequent calls to this method override the previous listener.

param
listener to listen to the session events of this object

        mListener = listener;
    
public voidunregister()
Performs unregistration to the server specified by the associated local profile. Unregistration is technically the same as registration with zero expiration duration. The session listener is called back upon success or failure of unregistration. The method is only valid to call when the session state is in {@link State#READY_TO_CALL}.

see
Listener

        try {
            mSession.unregister();
        } catch (RemoteException e) {
            loge("unregister:", e);
        }