diff options
Diffstat (limited to 'voip/java/android')
-rw-r--r-- | voip/java/android/net/sip/ISipSessionListener.aidl | 8 | ||||
-rw-r--r-- | voip/java/android/net/sip/SipAudioCall.java | 57 | ||||
-rw-r--r-- | voip/java/android/net/sip/SipSession.java | 21 | ||||
-rw-r--r-- | voip/java/android/net/sip/SipSessionAdapter.java | 4 |
4 files changed, 89 insertions, 1 deletions
diff --git a/voip/java/android/net/sip/ISipSessionListener.aidl b/voip/java/android/net/sip/ISipSessionListener.aidl index 5920bca..690700c 100644 --- a/voip/java/android/net/sip/ISipSessionListener.aidl +++ b/voip/java/android/net/sip/ISipSessionListener.aidl @@ -72,6 +72,14 @@ interface ISipSessionListener { void onCallBusy(in ISipSession session); /** + * Called when the call is being transferred to a new one. + * + * @param newSession the new session that the call will be transferred to + * @param sessionDescription the new peer's session description + */ + void onCallTransferring(in ISipSession newSession, String sessionDescription); + + /** * Called when an error occurs during session initialization and * termination. * diff --git a/voip/java/android/net/sip/SipAudioCall.java b/voip/java/android/net/sip/SipAudioCall.java index b46f826..2666b69 100644 --- a/voip/java/android/net/sip/SipAudioCall.java +++ b/voip/java/android/net/sip/SipAudioCall.java @@ -170,6 +170,7 @@ public class SipAudioCall { private SipProfile mLocalProfile; private SipAudioCall.Listener mListener; private SipSession mSipSession; + private SipSession mTransferringSession; private long mSessionId = System.currentTimeMillis(); private String mPeerSd; @@ -347,6 +348,27 @@ public class SipAudioCall { } } + private synchronized void transferToNewSession() { + if (mTransferringSession == null) return; + SipSession origin = mSipSession; + mSipSession = mTransferringSession; + mTransferringSession = null; + + // stop the replaced call. + if (mAudioStream != null) { + mAudioStream.join(null); + } else { + try { + mAudioStream = new AudioStream(InetAddress.getByName( + getLocalIp())); + } catch (Throwable t) { + Log.i(TAG, "transferToNewSession(): " + t); + } + } + if (origin != null) origin.endCall(); + startAudio(); + } + private SipSession.Listener createListener() { return new SipSession.Listener() { @Override @@ -404,6 +426,13 @@ public class SipAudioCall { mPeerSd = sessionDescription; Log.v(TAG, "onCallEstablished()" + mPeerSd); + // TODO: how to notify the UI that the remote party is changed + if ((mTransferringSession != null) + && (session == mTransferringSession)) { + transferToNewSession(); + return; + } + Listener listener = mListener; if (listener != null) { try { @@ -420,7 +449,17 @@ public class SipAudioCall { @Override public void onCallEnded(SipSession session) { - Log.d(TAG, "sip call ended: " + session); + Log.d(TAG, "sip call ended: " + session + " mSipSession:" + mSipSession); + // reset the trasnferring session if it is the one. + if (session == mTransferringSession) { + mTransferringSession = null; + return; + } + // or ignore the event if the original session is being + // transferred to the new one. + if ((mTransferringSession != null) || + (session != mSipSession)) return; + Listener listener = mListener; if (listener != null) { try { @@ -489,6 +528,22 @@ public class SipAudioCall { public void onRegistrationDone(SipSession session, int duration) { // irrelevant } + + @Override + public void onCallTransferring(SipSession newSession, + String sessionDescription) { + Log.v(TAG, "onCallTransferring mSipSession:" + + mSipSession + " newSession:" + newSession); + mTransferringSession = newSession; + // session changing request + try { + String answer = createAnswer(sessionDescription).encode(); + newSession.answerCall(answer, SESSION_TIMEOUT); + } catch (Throwable e) { + Log.e(TAG, "onCallTransferring()", e); + newSession.endCall(); + } + } }; } diff --git a/voip/java/android/net/sip/SipSession.java b/voip/java/android/net/sip/SipSession.java index 5629b3c..5ba1626 100644 --- a/voip/java/android/net/sip/SipSession.java +++ b/voip/java/android/net/sip/SipSession.java @@ -160,6 +160,17 @@ public final class SipSession { } /** + * Called when the call is being transferred to a new one. + * + * @hide + * @param newSession the new session that the call will be transferred to + * @param sessionDescription the new peer's session description + */ + public void onCallTransferring(SipSession newSession, + String sessionDescription) { + } + + /** * Called when an error occurs during session initialization and * termination. * @@ -489,6 +500,16 @@ public final class SipSession { } } + public void onCallTransferring(ISipSession session, + String sessionDescription) { + if (mListener != null) { + mListener.onCallTransferring( + new SipSession(session, SipSession.this.mListener), + sessionDescription); + + } + } + public void onCallChangeFailed(ISipSession session, int errorCode, String message) { if (mListener != null) { diff --git a/voip/java/android/net/sip/SipSessionAdapter.java b/voip/java/android/net/sip/SipSessionAdapter.java index 86aca37..f538983 100644 --- a/voip/java/android/net/sip/SipSessionAdapter.java +++ b/voip/java/android/net/sip/SipSessionAdapter.java @@ -42,6 +42,10 @@ public class SipSessionAdapter extends ISipSessionListener.Stub { public void onCallBusy(ISipSession session) { } + public void onCallTransferring(ISipSession session, + String sessionDescription) { + } + public void onCallChangeFailed(ISipSession session, int errorCode, String message) { } |