smackx jingle语音通话实例

关于jingle ,资料网上少之又少,官方提供的Demo无法运行(原因:问声明客户端支持Jingle,所以服务端返回501异常)。

这个问题困然我几天,然后在Ignite Realtime看到一篇可以很好工作的JIngle示例:

public static void main(String[] args) throws Exception {
    // enable Jingle service
    JingleManager.setJingleServiceEnabled();
 
    // user1 connect to a XMPP Server
    XMPPConnection x1 = new XMPPConnection("localhost");
    x1.connect();
    x1.login("user1", "user1");
 
    // Create a JingleManager using a BasicTransportManager
    List<JingleMediaManager> mediaManagers1 = new ArrayList<JingleMediaManager>();
    mediaManagers1.add(new JmfMediaManager(new BasicTransportManager()));
    final JingleManager jm1 = new JingleManager(x1, mediaManagers1);
 
    // Listen for incoming calls
    jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
        public void sessionRequested(JingleSessionRequest request) {
 
            try {
                // Accept the call
                JingleSession session = request.accept();
 
                // Start the call
                session.startIncoming();
            }
            catch (XMPPException e) {
                e.printStackTrace();
            }
 
        }
    });
 
    // user2 connect to a XMPP Server
    XMPPConnection x0 = new XMPPConnection("localhost");
    x0.connect();
    x0.login("user2", "user2");
 
    // Create a JingleManager using a BasicTransportManager
    List<JingleMediaManager> mediaManagers0 = new ArrayList<JingleMediaManager>();
    mediaManagers0.add(new JmfMediaManager(new BasicTransportManager()));
    final JingleManager jm0 = new JingleManager(x0, mediaManagers0);
 
    // Create a new Jingle Call with a full JID
    JingleSession js0 = jm0
                    .createOutgoingJingleSession("user1@localhost/Smack");
 
    // Start the call
    js0.startOutgoing();
 
    Thread.sleep(30000);
    js0.terminate();
 
    Thread.sleep(3000);
 
}
For the JMFMediaManager to work you have to add the jmf.jar and maybe some OS dependent libraries to the classpath. These can be found in the svn repository /smack/jingle/extensions/build/lib

转自:http://community.igniterealtime.org/thread/37786


你可能感兴趣的:(smackx jingle语音通话实例)