📄 call.java
字号:
/*
* Copyright (C) 2005 Luca Veltri - University of Parma - Italy
*
* This file is part of MjSip (http://www.mjsip.org)
*
* MjSip is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MjSip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MjSip; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author(s):
* Luca Veltri (luca.veltri@unipr.it)
*/
package org.zoolu.sip.call;
import org.zoolu.sip.dialog.*;
import org.zoolu.sip.provider.*;
import org.zoolu.sip.message.*;
import org.zoolu.sip.address.NameAddress;
import org.zoolu.sip.header.MultipleHeader;
import org.zoolu.tools.Log;
import org.zoolu.tools.LogLevel;
import org.zoolu.sdp.*;
import java.util.Vector;
/** Class Call implements SIP calls.
* <p>It handles both outgoing or incoming calls.
* <p>Both offer/answer models are supported, that is:
* <br> i) offer/answer in invite/2xx, or
* <br> ii) offer/answer in 2xx/ack
*/
public class Call implements InviteDialogListener
{
/** Event logger. */
Log log;
/** The SipProvider used for the call */
protected SipProvider sip_provider;
/** The invite dialog (sip.dialog.InviteDialog) */
protected InviteDialog dialog;
/** The user url (AOR) */
protected String from_url;
/** The user contact url */
protected String contact_url;
/** The local sdp */
protected String local_sdp;
/** The remote sdp */
protected String remote_sdp;
/** The call listener (sipx.call.CallListener) */
CallListener listener;
/** Creates a new Call. */
public Call(SipProvider sip_provider, String from_url, String contact_url, CallListener call_listener)
{ this.sip_provider=sip_provider;
this.log=sip_provider.getLog();
this.listener=call_listener;
this.from_url=from_url;
this.contact_url=contact_url;
this.dialog=null;
this.local_sdp=null;
this.remote_sdp=null;
}
/** Creates a new Call specifing the sdp */
/*public Call(SipProvider sip_provider, String from_url, String contact_url, String sdp, CallListener call_listener)
{ this.sip_provider=sip_provider;
this.log=sip_provider.getLog();
this.listener=call_listener;
this.from_url=from_url;
this.contact_url=contact_url;
local_sdp=sdp;
}*/
/** Creates a new Call for the already received INVITE request <i>invite</i>. */
public Call(SipProvider sip_provider, Message invite, String contact_url, CallListener call_listener)
{ this.sip_provider=sip_provider;
this.log=sip_provider.getLog();
this.listener=call_listener;
this.from_url=invite.getToHeader().getNameAddress().toString();
this.contact_url=contact_url;
this.dialog=new InviteDialog(sip_provider,invite,this);
this.local_sdp=null;
this.remote_sdp=invite.getBody();
}
/** Gets the current invite dialog */
/*public InviteDialog getInviteDialog()
{ return dialog;
}*/
/** Gets the current call-id */
public String getCallId()
{ if (dialog==null) return null;
else return dialog.getCallID();
}
/** Gets the current local session descriptor */
public String getLocalSessionDescriptor()
{ return local_sdp;
}
/** Sets a new local session descriptor */
public void setLocalSessionDescriptor(String sdp)
{ local_sdp=sdp;
}
/** Gets the current remote session descriptor */
public String getRemoteSessionDescriptor()
{ return remote_sdp;
}
/** Whether the call is on (active). */
public boolean isOnCall()
{ return dialog.isSessionActive();
}
/** Waits for an incoming call */
public void listen()
{ dialog=new InviteDialog(sip_provider,this);
dialog.listen();
}
/** Starts a new call, inviting a remote user (<i>callee</i>) */
public void call(String callee)
{ call(callee,null,null,null);
}
/** Starts a new call, inviting a remote user (<i>callee</i>) */
public void call(String callee, String sdp)
{ call(callee,null,null,sdp);
}
/** Starts a new call, inviting a remote user (<i>callee</i>) */
public void call(String callee, String from, String contact, String sdp)
{ printLog("calling "+callee,LogLevel.HIGH);
if (from==null) from=from_url;
if (contact==null) contact=contact_url;
if (sdp!=null) local_sdp=sdp;
dialog=new InviteDialog(sip_provider,this);
if (local_sdp!=null)
dialog.invite(callee,from,contact,local_sdp);
else dialog.inviteWithoutOffer(callee,from,contact);
}
/** Starts a new call with the <i>invite</i> message request */
public void call(Message invite)
{ dialog=new InviteDialog(sip_provider,this);
local_sdp=invite.getBody();
if (local_sdp!=null)
dialog.invite(invite);
else dialog.inviteWithoutOffer(invite);
}
/** Answers at the 2xx/offer (in the ack message) */
public void ackWithAnswer(String sdp)
{ local_sdp=sdp;
dialog.ackWithAnswer(contact_url,sdp);
}
/** Rings back for the incoming call */
public void ring()
{ if (dialog!=null) dialog.ring();
}
/** Respond to a incoming call (invite) with <i>resp</i> */
public void respond(Message resp)
{ if (dialog!=null) dialog.respond(resp);
}
/** Accepts the incoming call */
/*public void accept()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -