backend.getMain().addToRosterMenu(I18N.gettext("jingle.voice"),new RosterMenuListener()
{
public void actionPerformed(JIDStatus jidStatus,nu.fw.jeti.backend.roster.JIDStatusGroup group)
{
JingleSession session = sessions.get(jidStatus.getCompleteJID());
if (session != null) {
try
{
session.terminate();
System.out.println("session removing because not yet removed");
} catch (XMPPException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
OutgoingJingleSession jos = manager.createOutgoingJingleSession(jidStatus.getCompleteJID());
jos.addListener(createSessionListener(jidStatus.getCompleteJID()));
jos.start();
sessions.put(jidStatus.getCompleteJID(),jos);
endVoiceMenu.setEnabled(true);
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
String stunServer = "stun.xten.net";
int stunPort = 3478;
// if (STUN.serviceAvailable(backend)) {
// STUN stun = STUN.getSTUNServer(backend);
// if (stun != null) {
// List<STUN.StunServerAddress> servers = stun.getServers();
//
// if (servers.size() > 0) {
// stunServer = servers.get(0).getServer();
// stunPort = Integer.parseInt(servers.get(0).getPort());
// }
// }
// }
JingleTransportManager transportManager = new ICETransportManager(
backend, stunServer, stunPort);
// if running on Windows use Direct Sound for better performance
//String locator = Spark.isWindows() && !Spark.isVista() ? "dsound://" : "javasound://";
String locator = "javasound://8000"; //48000 to fix os2 and mac bug
MultiMediaManager jingleMediaManager = new MultiMediaManager();
jingleMediaManager.addMediaManager(new JmfMediaManager(locator));
jingleMediaManager.addMediaManager(new SpeexMediaManager());
if (System.getProperty("codec") != null) {
try {
int codec = Integer.parseInt(System.getProperty("codec"));
jingleMediaManager.setPreferredPayloadType(jingleMediaManager
.getPayloads().get(codec));
} catch (NumberFormatException e) {
// do nothing
}
}
manager = new JingleManager(backend, transportManager, jingleMediaManager);
manager.addCreationListener((ICETransportManager)transportManager);
manager.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
JID from = request.getFrom();
JingleSession session = sessions.get(from);
if (session != null) {
try {
session.terminate();
System.out.println("incom session removing because not yet removed");
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return;
}
String name = from.getUser();
JIDStatus jidStatus = Roster.getJIDStatus(from);
if(jidStatus!=null) name = jidStatus.getNick();
Object[] options = { I18N.gettext("jeti.Decline") , I18N.gettext("jeti.Answer") };
Popups.showOptionDialog(MessageFormat.format(I18N.gettext("jingle.{0}_calls,_answer_call?"),name),
I18N.gettext("jingle.New Call"), JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null,
options,options[1], new Popups.OptionChoosed() {
public void optionChoosed(int option) {
if(option == JOptionPane.NO_OPTION){
try {
// Accept the call
IncomingJingleSession incoming = request.accept();
incoming.start();
incoming.addListener(createSessionListener(request.getFrom()));
}
catch (Exception e) {
e.printStackTrace();
}
}
else{
request.reject();
}
}
});
}
});
backend.addExtensionHandler("http://jabber.org/protocol/jingle",new JingleProvider(manager));
backend.addExtensionHandler("http://jabber.org/protocol/jingle/description/audio",
new JingleContentDescriptionProvider.Audio());
backend.addExtensionHandler("http://jabber.org/protocol/jingle/transport/ice",
new JingleTransportProvider.Ice());
backend.addExtensionHandler("http://jabber.org/protocol/jingle/transport/raw-udp",
new JingleTransportProvider.RawUdp());
backend.addExtensionHandler("http://jabber.org/protocol/jingle/info/audio",
new JingleContentInfoProvider.Audio());
backend.addExtensionHandler("http://www.jivesoftware.com/protocol/rtpbridge", new Provider());
backend.addExtensionHandler("google:jingleinfo", new STUN.Provider());
backend.addCapability("jingle","http://www.xmpp.org/extensions/xep-0166.html#ns");
backend.addListener(IQResultListener.class,new IQResultListener(){
public void iqResult(InfoQuery iq) {
for (JingleSession session : manager.getAllSessions()){
try {
session.respond(new Jingle(iq));
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}