Merge with my personnal branch which contains a simple test for xmpp.
--- a/build.xml Wed Mar 11 17:29:46 2009 +0100
+++ b/build.xml Thu Mar 12 22:27:36 2009 +0100
@@ -287,7 +287,14 @@
<exec executable="${adb}" failonerror="true">
<arg value="uninstall" />
<arg value="${application-package}" />
- </exec>
+ </exec>
</target>
+ <target name="clean"
+ description="Delete old build and dist directories">
+ <delete verbose="false" dir="${outdir}"/>
+ </target>
+
+
+
</project>
Binary file libs/smack.jar has changed
Binary file libs/smackx-debug.jar has changed
Binary file libs/smackx-jingle.jar has changed
Binary file libs/smackx.jar has changed
--- a/src/com/beem/project/beem/Beem.java Wed Mar 11 17:29:46 2009 +0100
+++ b/src/com/beem/project/beem/Beem.java Thu Mar 12 22:27:36 2009 +0100
@@ -3,13 +3,14 @@
import android.app.Activity;
import android.os.Bundle;
-public class Beem extends Activity
-{
- /** Called when the activity is first created. */
+public class Beem extends Activity {
+
+ /** Called when the activity is first created.
+ * @param savedInstanceState toto
+ */
@Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.main);
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/Caller.java Thu Mar 12 22:27:36 2009 +0100
@@ -0,0 +1,135 @@
+package com.beem.project.beem.jingle;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smackx.jingle.JingleManager;
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
+import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+/**
+ * @author darisk
+ *
+ */
+public class Caller {
+
+ private XMPPConnection con;
+ private String login;
+ private String password;
+ private JingleManager jingleManager;
+ private List<JingleMediaManager> mediaManagers;
+ private JingleSession out;
+
+ public Caller(final String login, final String pass, String server) {
+ if (server == null || server.equals(""))
+ server = "localhost";
+// XMPPConnection.DEBUG_ENABLED = true;
+ this.login = login;
+ this.password = pass;
+ ConnectionConfiguration conf = new ConnectionConfiguration(server);
+ conf.setRosterLoadedAtLogin(false);
+
+ con = new XMPPConnection(conf);
+ try {
+ con.connect();
+ con.login(this.login, this.password, "Caller");
+ initialize();
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ System.err.println("Echec de la connexion au serveru");
+ e.printStackTrace();
+ }
+ }
+
+ public void call(final String destinataire) {
+ try {
+ out = jingleManager.createOutgoingJingleSession(destinataire);
+ // TODO configure out avec addMediaSession et addNegociator
+ out.addListener(new JingleSessionListener() {
+
+ @Override
+ public void sessionRedirected(final String redirection,
+ final JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ }
+
+ @Override
+ public void sessionMediaReceived(final JingleSession jingleSession,
+ final String participant) {
+ // TODO Auto-generated method stub
+ System.out.println("Session Media received from " + participant);
+ }
+
+ @Override
+ public void sessionEstablished(final PayloadType pt,
+ final TransportCandidate remoteCandidate,
+ final TransportCandidate localCandidate,
+ final JingleSession jingleSession) {
+ System.out.println("Session established");
+ String name = remoteCandidate.getName();
+ String ip = remoteCandidate.getIp();
+ int port = remoteCandidate.getPort();
+ System.out.println("Session established avec "+name+" sur "+ ip + ":" +port);
+
+ }
+
+ @Override
+ public void sessionDeclined(final String reason,
+ final JingleSession jingleSession) {
+ System.out.println("Session " + jingleSession.getResponder()
+ + "declined because " + reason);
+ }
+
+ @Override
+ public void sessionClosedOnError(final XMPPException e,
+ final JingleSession jingleSession) {
+ System.out.println("Session " + jingleSession.getResponder() + " closed on error");
+
+ }
+
+ @Override
+ public void sessionClosed(final String reason,
+ final JingleSession jingleSession) {
+ System.out.println("Session " + jingleSession.getResponder()
+ + "closed because " + reason);
+ }
+ });
+ out.startOutgoing();
+
+
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ private void initialize() {
+ mediaManagers = new ArrayList<JingleMediaManager>();
+ mediaManagers.add(new SenderMediaManager(new BasicTransportManager()));
+ JingleManager.setJingleServiceEnabled();
+ jingleManager = new JingleManager(con, mediaManagers);
+
+ }
+
+ /**
+ * @param args Program args
+ * @throws InterruptedException exception
+ */
+ public static void main(final String[] args) throws InterruptedException {
+ if (args.length < 4) {
+ System.err.println("Not enough parameters");
+ System.err.println("Usage : Caller user password server jidtocall");
+ }
+ Caller test = new Caller(args[0], args[1], args[2]);
+ test.call(args[3]);
+ Thread.sleep(60000);
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/FileSender.java Thu Mar 12 22:27:36 2009 +0100
@@ -0,0 +1,59 @@
+package com.beem.project.beem.jingle;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+public class FileSender extends Thread {
+ private String dest;
+ private int port;
+ private boolean started = false;
+ private String filename;
+
+ public FileSender(String dest, int port, String file){
+ this.dest = dest;
+ this.port = port;
+ this.filename = file;
+ }
+
+ public void run(){
+ try {
+ InputStream in = new BufferedInputStream(new FileInputStream(filename));
+ Socket sock = new Socket(dest, port);
+ OutputStream out = new BufferedOutputStream(sock.getOutputStream());
+
+ try {
+ started = true;
+ byte buf[] = new byte[1024];
+ int nbbytes = 1;
+ while (started && nbbytes != -1){
+ nbbytes = in.read(buf, 0, 1024);
+ out.write(buf, 0, 1024);
+ }
+ started = false;
+ } finally {
+ if (in != null)
+ in.close();
+ if (out != null)
+ out.close();
+ if (sock != null)
+ sock.close();
+ }
+ } catch (FileNotFoundException e){
+ System.err.println("Impossible d'ouvrir " + filename +" " + e.getLocalizedMessage());
+ } catch (IOException e) {
+ System.err.println("Imposible de se connecter a " + dest + " " + e.getLocalizedMessage());
+ }
+ }
+
+ public void setStarted(){
+ started = false;
+ }
+
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/Receiver.java Thu Mar 12 22:27:36 2009 +0100
@@ -0,0 +1,156 @@
+package com.beem.project.beem.jingle;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.List;
+import org.jivesoftware.smack.ConnectionConfiguration;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smackx.jingle.JingleManager;
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.JingleSessionRequest;
+import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
+import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener;
+import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+
+public class Receiver {
+
+ private XMPPConnection con;
+ private JingleManager jingleManager;
+ private List<JingleMediaManager> mediaManagers;
+ private JingleSession in;
+
+ public Receiver(String username, String pass) {
+ // XMPPConnection.DEBUG_ENABLED = true;
+ ConnectionConfiguration conf = new ConnectionConfiguration("localhost");
+ conf.setRosterLoadedAtLogin(false);
+ con = new XMPPConnection(conf);
+ try {
+ con.connect();
+ con.login(username, pass, "Receiver");
+ initialize();
+
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ private void initialize()
+ {
+ mediaManagers = new ArrayList<JingleMediaManager>();
+ mediaManagers.add(new SenderMediaManager(new BasicTransportManager()));
+ JingleManager.setJingleServiceEnabled();
+ jingleManager = new JingleManager(con, mediaManagers);
+ jingleManager.addJingleSessionRequestListener(new JingleSessionRequestListener() {
+
+ @Override
+ public void sessionRequested(JingleSessionRequest request) {
+ System.out.println("Jingle Session request from "+request.getFrom());
+ try {
+ in = request.accept();
+ // TODO configure in
+ in.addListener(new JingleSessionListener() {
+
+ @Override
+ public void sessionRedirected(String redirection,
+ JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void sessionMediaReceived(JingleSession jingleSession,
+ String participant) {
+ // TODO Auto-generated method stub
+ System.out.println("Session Media received from " + participant);
+ }
+
+ @Override
+ public void sessionEstablished(PayloadType pt,
+ TransportCandidate remoteCandidate,
+ TransportCandidate localCandidate, JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ System.out.println("Session established");
+ try{
+ System.out.println("Je recois sur " + localCandidate.getIp() + ":" + localCandidate.getPort() );
+ receiveData(localCandidate.getIp(), localCandidate.getPort());
+ } catch (IOException e){
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void sessionDeclined(String reason, JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ System.out.println("Session "+ jingleSession.getResponder() +"declined because "+ reason);
+ }
+
+ @Override
+ public void sessionClosedOnError(XMPPException e,
+ JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ System.out.println("Session "+ jingleSession.getResponder() + " closed");
+
+ }
+
+ @Override
+ public void sessionClosed(String reason, JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ System.out.println("Session "+ jingleSession.getResponder() +"closedd because "+ reason);
+ }
+ });
+ in.startIncoming();
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ });
+
+ }
+
+
+ private void receiveData(String ip, int port) throws IOException {
+ ServerSocket serv = null;
+ Socket s = null;
+ try {
+ serv = new ServerSocket(port);
+ System.out.println("Waiting data");
+ s = serv.accept();
+ InputStream in = s.getInputStream();
+ int a;
+ while ( (a = in.read()) != -1) {
+ System.out.println("Received " + a);
+ }
+ System.out.println("End receiving data");
+ } finally {
+ if (serv != null)
+ serv.close();
+ if (s != null)
+ s.close();
+ }
+ }
+
+ /**
+ * @param args
+ * @throws InterruptedException
+ * @throws InterruptedException
+ */
+ public static void main(String[] args) throws InterruptedException {
+ // TODO Auto-generated method stub
+ Receiver rec = new Receiver("test2", "test2");
+ System.out.println("Receiver initialized");
+
+ Thread.sleep(60000);
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/ReceiverMediaManager.java Thu Mar 12 22:27:36 2009 +0100
@@ -0,0 +1,53 @@
+package com.beem.project.beem.jingle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.SmackLogger;
+import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
+import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaSession;
+import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+public class ReceiverMediaManager extends JingleMediaManager {
+
+ private static final SmackLogger LOGGER = SmackLogger.getLogger(ReceiverMediaManager.class);
+
+ public static final String MEDIA_NAME = "69Test";
+
+ private List<PayloadType> payloads;
+
+ public ReceiverMediaManager(JingleTransportManager transportManager) {
+ super(transportManager);
+ // TODO Auto-generated constructor stub
+ setupPayloads();
+ LOGGER.info("A TestMedia Manager is created");
+ }
+
+ @Override
+ public JingleMediaSession createMediaSession(PayloadType payloadType,
+ TransportCandidate remote, TransportCandidate local,
+ JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ return new TestMediaSession(payloadType, remote, local, null, jingleSession);
+ }
+
+ @Override
+ public List<PayloadType> getPayloads() {
+ // TODO Auto-generated method stub
+ return payloads;
+ }
+
+ private void setupPayloads() {
+ payloads = new ArrayList<PayloadType>();
+ payloads.add(new PayloadType.Audio(42, "Test"));
+ payloads.add(new PayloadType.Audio(69, "Test2"));
+ }
+
+ public String getName() {
+ return MEDIA_NAME;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/SenderMediaManager.java Thu Mar 12 22:27:36 2009 +0100
@@ -0,0 +1,50 @@
+package com.beem.project.beem.jingle;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.SmackLogger;
+import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
+import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+public class SenderMediaManager extends JingleMediaManager {
+
+ private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaManager.class);
+
+ public static final String MEDIA_NAME = "42Test";
+
+ private List<PayloadType> payloads;
+
+ public SenderMediaManager(JingleTransportManager transportManager) {
+ super(transportManager);
+ // TODO Auto-generated constructor stub
+ setupPayloads();
+ LOGGER.info("A TestMedia Manager is created");
+ }
+
+ @Override
+ public JingleMediaSession createMediaSession(PayloadType payloadType,
+ TransportCandidate remote, TransportCandidate local,
+ JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ return new SenderMediaSession(payloadType, remote, local, null, jingleSession);
+ }
+
+ @Override
+ public List<PayloadType> getPayloads() {
+ return payloads;
+ }
+
+ private void setupPayloads() {
+ payloads = new ArrayList<PayloadType>();
+ payloads.add(new PayloadType.Audio(42, "Test"));
+ }
+
+ @Override
+ public String getName() {
+ return MEDIA_NAME;
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/jingle/SenderMediaSession.java Thu Mar 12 22:27:36 2009 +0100
@@ -0,0 +1,93 @@
+/**
+ *
+ */
+package com.beem.project.beem.jingle;
+
+import org.jivesoftware.smackx.jingle.JingleSession;
+import org.jivesoftware.smackx.jingle.SmackLogger;
+import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
+import org.jivesoftware.smackx.jingle.media.PayloadType;
+import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
+
+/**
+ * @author darisk
+ *
+ */
+public class SenderMediaSession extends JingleMediaSession {
+
+ private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaSession.class);
+ private static final String filename = "/tmp/test.jpg";
+ private boolean active = false;
+ private boolean started = false;
+ private FileSender fileSender;
+
+ /**
+ * @param payloadType
+ * @param remote
+ * @param local
+ * @param mediaLocator
+ * @param jingleSession
+ */
+ public SenderMediaSession(PayloadType payloadType, TransportCandidate remote,
+ TransportCandidate local, String mediaLocator,
+ JingleSession jingleSession) {
+ super(payloadType, remote, local, mediaLocator, jingleSession);
+ initialize();
+ LOGGER.info("Demarrage d'une session avec local: "+ local +" #remote: "+remote );
+ }
+
+ /* (non-Javadoc)
+ * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#initialize()
+ */
+ @Override
+ public void initialize() {
+ fileSender = new FileSender(this.getRemote().getIp(), getRemote().getPort(), filename);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#setTrasmit(boolean)
+ */
+ @Override
+ public void setTrasmit(boolean active) {
+ // TODO Auto-generated method stub
+ this.active = active;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#startReceive()
+ */
+ @Override
+ public void startReceive() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#startTrasmit()
+ */
+ @Override
+ public void startTrasmit() {
+ fileSender.start();
+ }
+
+ /* (non-Javadoc)
+ * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#stopReceive()
+ */
+ @Override
+ public void stopReceive() {
+ // TODO Auto-generated method stub
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#stopTrasmit()
+ */
+ @Override
+ public void stopTrasmit() {
+ // TODO Auto-generated method stub
+ started = false;
+ }
+
+
+
+}