Project

General

Profile

Patch #38 » beem-jingle-pour-manu.patch

Patch pour ceux qui veulent voir du code - Frédéric Barthéléry, 03/06/2009 11:20 PM

View differences:

build.xml Fri Feb 27 22:15:25 2009 +0100 → build.xml Fri Mar 06 23:07:22 2009 +0100
287 287
        <exec executable="${adb}" failonerror="true">
288 288
            <arg value="uninstall" />
289 289
            <arg value="${application-package}" />
290
        </exec>
290
	</exec>
291 291
    </target>
292 292

  
293
    <target name="clean"
294
	    description="Delete old build and dist directories">
295
	<delete verbose="false" dir="${outdir}"/>
296
    </target>
297

  
298

  
299

  
293 300
</project>
src/com/beem/project/beem/Beem.java Fri Feb 27 22:15:25 2009 +0100 → src/com/beem/project/beem/Beem.java Fri Mar 06 23:07:22 2009 +0100
3 3
import android.app.Activity;
4 4
import android.os.Bundle;
5 5

  
6
public class Beem extends Activity
7
{
8
    /** Called when the activity is first created. */
6
public class Beem extends Activity {
7
    
8
    /** Called when the activity is first created.
9
     * @param savedInstanceState toto
10
     */
9 11
    @Override
10
    public void onCreate(Bundle savedInstanceState)
11
    {
12
        super.onCreate(savedInstanceState);
13
        setContentView(R.layout.main);
12
    public void onCreate(Bundle savedInstanceState) {
13
	super.onCreate(savedInstanceState);
14
	setContentView(R.layout.main);
14 15
    }
15 16
}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/jingle/Caller.java Fri Mar 06 23:07:22 2009 +0100
1
package com.beem.project.beem.jingle;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.jivesoftware.smack.ConnectionConfiguration;
6
import org.jivesoftware.smack.XMPPConnection;
7
import org.jivesoftware.smack.XMPPException;
8
import org.jivesoftware.smackx.jingle.JingleManager;
9
import org.jivesoftware.smackx.jingle.JingleSession;
10
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
11
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
12
import org.jivesoftware.smackx.jingle.media.PayloadType;
13
import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
14
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
15

  
16
/**
17
 * @author darisk
18
 *
19
 */
20
public class Caller {
21

  
22
    private XMPPConnection con;
23
    private String login;
24
    private String password;
25
    private JingleManager jingleManager;
26
    private List<JingleMediaManager> mediaManagers;
27
    private JingleSession out;
28

  
29
    public Caller(final String login, final String pass, String server) {
30
	if (server == null || server.equals(""))
31
	    server = "localhost";
32
//	XMPPConnection.DEBUG_ENABLED = true;
33
	this.login = login;
34
	this.password = pass;
35
	ConnectionConfiguration conf = new ConnectionConfiguration(server);
36
	conf.setRosterLoadedAtLogin(false);
37

  
38
	con = new XMPPConnection(conf);
39
	try {
40
	    con.connect();
41
	    con.login(this.login, this.password, "Caller");
42
	    initialize();
43
	} catch (XMPPException e) {
44
	    // TODO Auto-generated catch block
45
	    System.err.println("Echec de la connexion au serveru");
46
	    e.printStackTrace();
47
	}
48
    }
49

  
50
    public void  call(final String destinataire) {
51
	try {
52
	    out = jingleManager.createOutgoingJingleSession(destinataire);
53
	    // TODO configure out avec addMediaSession et addNegociator
54
	    out.addListener(new JingleSessionListener() {
55

  
56
		@Override
57
		public void sessionRedirected(final String redirection,
58
		    final JingleSession jingleSession) {
59
		    // TODO Auto-generated method stub
60
		}
61

  
62
		@Override
63
		public void sessionMediaReceived(final JingleSession jingleSession,
64
		    final String participant) {
65
		    // TODO Auto-generated method stub
66
			System.out.println("Session Media received from " + participant);
67
		}
68

  
69
		@Override
70
		public void sessionEstablished(final PayloadType pt,
71
		    final TransportCandidate remoteCandidate,
72
		    final TransportCandidate localCandidate,
73
		    final JingleSession jingleSession) {
74
		    System.out.println("Session established");
75
		    String name = remoteCandidate.getName();
76
		    String ip = remoteCandidate.getIp();
77
		    int port = remoteCandidate.getPort();
78
		    System.out.println("Session established avec "+name+" sur "+ ip + ":" +port);
79
		    
80
		}
81

  
82
		@Override
83
		public void sessionDeclined(final String reason,
84
			final JingleSession jingleSession) {
85
		    System.out.println("Session " + jingleSession.getResponder()
86
			    + "declined because " + reason);
87
		}
88

  
89
		@Override
90
		public void sessionClosedOnError(final XMPPException e,
91
			final JingleSession jingleSession) {
92
		    System.out.println("Session " + jingleSession.getResponder() + " closed on error");
93

  
94
		}
95

  
96
		@Override
97
		public void sessionClosed(final String reason,
98
			final JingleSession jingleSession) {
99
		    System.out.println("Session " + jingleSession.getResponder() 
100
			    + "closed because " + reason);
101
		}
102
	    });
103
	    out.startOutgoing();
104

  
105

  
106
	} catch (XMPPException e) {
107
	    // TODO Auto-generated catch block
108
	    e.printStackTrace();
109
	}
110

  
111
    }
112

  
113
    private void initialize() {
114
	mediaManagers = new ArrayList<JingleMediaManager>();
115
	mediaManagers.add(new SenderMediaManager(new BasicTransportManager()));
116
	JingleManager.setJingleServiceEnabled();
117
	jingleManager = new JingleManager(con, mediaManagers);
118

  
119
    }
120

  
121
    /**
122
     * @param args Program args
123
     * @throws InterruptedException exception
124
     */
125
    public static void main(final String[] args) throws InterruptedException {
126
	if (args.length < 4) {
127
	    System.err.println("Not enough parameters");
128
	    System.err.println("Usage : Caller user password server jidtocall");
129
	}
130
	Caller test = new Caller(args[0], args[1], args[2]);
131
	test.call(args[3]);
132
	Thread.sleep(60000);
133
    }
134

  
135
}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/jingle/FileSender.java Fri Mar 06 23:07:22 2009 +0100
1
package com.beem.project.beem.jingle;
2

  
3
import java.io.BufferedInputStream;
4
import java.io.BufferedOutputStream;
5
import java.io.FileInputStream;
6
import java.io.FileNotFoundException;
7
import java.io.IOException;
8
import java.io.InputStream;
9
import java.io.OutputStream;
10
import java.net.Socket;
11

  
12
public class FileSender extends Thread {
13
    private String dest;
14
    private int port;
15
    private boolean started = false;
16
    private String filename;
17

  
18
    public FileSender(String dest, int port, String file){
19
	this.dest = dest;
20
	this.port = port;
21
	this.filename = file;
22
    }
23

  
24
    public void run(){
25
	try {
26
	    InputStream in = new BufferedInputStream(new FileInputStream(filename));
27
	    Socket sock = new Socket(dest, port);
28
	    OutputStream out = new BufferedOutputStream(sock.getOutputStream());
29

  
30
	    try {
31
		started = true;
32
		byte buf[] = new byte[1024];
33
		int nbbytes = 1;
34
		while (started && nbbytes != -1){
35
		    nbbytes = in.read(buf, 0, 1024);
36
		    out.write(buf, 0, 1024);
37
		}
38
		started = false;
39
	    } finally {
40
		if (in != null)
41
		    in.close();
42
		if (out != null)
43
		    out.close();
44
		if (sock != null)
45
		    sock.close();
46
	    }
47
	} catch (FileNotFoundException e){
48
	    System.err.println("Impossible d'ouvrir " + filename +" " + e.getLocalizedMessage());
49
	} catch (IOException e) {
50
	    System.err.println("Imposible de se connecter a " + dest + " " + e.getLocalizedMessage());
51
	}
52
    }
53

  
54
    public void setStarted(){
55
	started = false;
56
    }
57

  
58

  
59
}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/jingle/Receiver.java Fri Mar 06 23:07:22 2009 +0100
1
package com.beem.project.beem.jingle;
2

  
3
import java.io.IOException;
4
import java.io.InputStream;
5
import java.net.ServerSocket;
6
import java.net.Socket;
7
import java.util.ArrayList;
8
import java.util.List;
9
import org.jivesoftware.smack.ConnectionConfiguration;
10
import org.jivesoftware.smack.XMPPConnection;
11
import org.jivesoftware.smack.XMPPException;
12
import org.jivesoftware.smackx.jingle.JingleManager;
13
import org.jivesoftware.smackx.jingle.JingleSession;
14
import org.jivesoftware.smackx.jingle.JingleSessionRequest;
15
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
16
import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener;
17
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
18
import org.jivesoftware.smackx.jingle.media.PayloadType;
19
import org.jivesoftware.smackx.jingle.nat.BasicTransportManager;
20
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
21

  
22

  
23
public class Receiver {
24

  
25
    private XMPPConnection con;
26
    private JingleManager jingleManager;
27
    private List<JingleMediaManager> mediaManagers;
28
    private JingleSession in;
29

  
30
    public Receiver(String username, String pass) {
31
	//		XMPPConnection.DEBUG_ENABLED = true;
32
	ConnectionConfiguration conf = new ConnectionConfiguration("localhost");
33
	conf.setRosterLoadedAtLogin(false);
34
	con = new XMPPConnection(conf);
35
	try {
36
	    con.connect();
37
	    con.login(username, pass, "Receiver");
38
	    initialize();
39

  
40
	} catch (XMPPException e) {
41
	    // TODO Auto-generated catch block
42
	    e.printStackTrace();
43
	}
44
    }
45

  
46
    private void initialize()
47
    {
48
	mediaManagers = new ArrayList<JingleMediaManager>();
49
	mediaManagers.add(new SenderMediaManager(new BasicTransportManager()));
50
	JingleManager.setJingleServiceEnabled();
51
	jingleManager = new JingleManager(con, mediaManagers);
52
	jingleManager.addJingleSessionRequestListener(new JingleSessionRequestListener() {
53

  
54
	    @Override
55
	    public void sessionRequested(JingleSessionRequest request) {
56
		System.out.println("Jingle Session request from "+request.getFrom());
57
		try {
58
		    in = request.accept();
59
		    // TODO configure in
60
		    in.addListener(new JingleSessionListener() {
61

  
62
			@Override
63
			public void sessionRedirected(String redirection,
64
			    JingleSession jingleSession) {
65
			    // TODO Auto-generated method stub
66

  
67
			}
68

  
69
			@Override
70
			public void sessionMediaReceived(JingleSession jingleSession,
71
			    String participant) {
72
			    // TODO Auto-generated method stub
73
			    System.out.println("Session Media received from " + participant);
74
			}
75

  
76
			@Override
77
			public void sessionEstablished(PayloadType pt,
78
			    TransportCandidate remoteCandidate,
79
			    TransportCandidate localCandidate, JingleSession jingleSession) {
80
			    // TODO Auto-generated method stub
81
			    System.out.println("Session established");
82
			    try{
83
				System.out.println("Je recois sur " + localCandidate.getIp() + ":" + localCandidate.getPort() );
84
				receiveData(localCandidate.getIp(), localCandidate.getPort());
85
			    } catch (IOException e){
86
				e.printStackTrace();
87
			    }
88
			}
89

  
90
			@Override
91
			public void sessionDeclined(String reason, JingleSession jingleSession) {
92
			    // TODO Auto-generated method stub
93
			    System.out.println("Session "+ jingleSession.getResponder() +"declined because "+ reason);
94
			}
95

  
96
			@Override
97
			public void sessionClosedOnError(XMPPException e,
98
				JingleSession jingleSession) {
99
			    // TODO Auto-generated method stub
100
			    System.out.println("Session "+ jingleSession.getResponder() + " closed"); 
101

  
102
			}
103

  
104
			@Override
105
			public void sessionClosed(String reason, JingleSession jingleSession) {
106
			    // TODO Auto-generated method stub
107
			    System.out.println("Session "+ jingleSession.getResponder() +"closedd because "+ reason);
108
			}
109
		    });
110
		    in.startIncoming();
111
		} catch (XMPPException e) {
112
		    // TODO Auto-generated catch block
113
		    e.printStackTrace();
114
		}
115
	    }
116
	});
117

  
118
    }
119

  
120

  
121
    private void receiveData(String ip, int port) throws IOException {
122
	ServerSocket serv = null;
123
	Socket s = null;
124
	try {
125
	    serv = new ServerSocket(port);
126
	    System.out.println("Waiting data");
127
	    s = serv.accept();
128
	    InputStream in = s.getInputStream();
129
	    int a;
130
	    while ( (a = in.read()) != -1) {
131
		System.out.println("Received " + a);
132
	    }
133
	    System.out.println("End receiving data");
134
	} finally {
135
	    if (serv != null)
136
		serv.close();
137
	    if (s != null)
138
		s.close();
139
	}
140
    }
141

  
142
    /**
143
     * @param args
144
     * @throws InterruptedException 
145
     * @throws InterruptedException 
146
     */
147
    public static void main(String[] args) throws InterruptedException {
148
	// TODO Auto-generated method stub
149
	Receiver rec = new Receiver("test2", "test2");
150
	System.out.println("Receiver initialized");
151

  
152
	Thread.sleep(60000);
153

  
154
    }
155

  
156
}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/jingle/ReceiverMediaManager.java Fri Mar 06 23:07:22 2009 +0100
1
package com.beem.project.beem.jingle;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5

  
6
import org.jivesoftware.smackx.jingle.JingleSession;
7
import org.jivesoftware.smackx.jingle.SmackLogger;
8
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
9
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
10
import org.jivesoftware.smackx.jingle.media.PayloadType;
11
import org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaSession;
12
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
13
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
14

  
15
public class ReceiverMediaManager extends JingleMediaManager {
16
	
17
	private static final SmackLogger LOGGER = SmackLogger.getLogger(ReceiverMediaManager.class);
18

  
19
	public static final String MEDIA_NAME = "69Test";
20
	
21
	private List<PayloadType> payloads;
22

  
23
	public ReceiverMediaManager(JingleTransportManager transportManager) {
24
		super(transportManager);
25
		// TODO Auto-generated constructor stub
26
		setupPayloads();
27
		LOGGER.info("A TestMedia Manager is created");
28
	}
29

  
30
	@Override
31
	public JingleMediaSession createMediaSession(PayloadType payloadType,
32
			TransportCandidate remote, TransportCandidate local,
33
			JingleSession jingleSession) {
34
		// TODO Auto-generated method stub
35
		return new TestMediaSession(payloadType, remote, local, null, jingleSession);
36
	}
37

  
38
	@Override
39
	public List<PayloadType> getPayloads() {
40
		// TODO Auto-generated method stub
41
		return payloads;
42
	}
43

  
44
	private void setupPayloads() {
45
		payloads = new ArrayList<PayloadType>();
46
		payloads.add(new PayloadType.Audio(42, "Test"));
47
		payloads.add(new PayloadType.Audio(69, "Test2"));
48
	}
49
	
50
	public String getName() {
51
		return MEDIA_NAME;
52
	}
53
}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/jingle/SenderMediaManager.java Fri Mar 06 23:07:22 2009 +0100
1
package com.beem.project.beem.jingle;
2

  
3
import java.util.ArrayList;
4
import java.util.List;
5
import org.jivesoftware.smackx.jingle.JingleSession;
6
import org.jivesoftware.smackx.jingle.SmackLogger;
7
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
8
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
9
import org.jivesoftware.smackx.jingle.media.PayloadType;
10
import org.jivesoftware.smackx.jingle.nat.JingleTransportManager;
11
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
12

  
13
public class SenderMediaManager extends JingleMediaManager {
14

  
15
    private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaManager.class);
16

  
17
    public static final String MEDIA_NAME = "42Test";
18

  
19
    private List<PayloadType> payloads;
20

  
21
    public SenderMediaManager(JingleTransportManager transportManager) {
22
	super(transportManager);
23
	// TODO Auto-generated constructor stub
24
	setupPayloads();
25
	LOGGER.info("A TestMedia Manager is created");
26
    }
27

  
28
    @Override
29
    public JingleMediaSession createMediaSession(PayloadType payloadType,
30
	    TransportCandidate remote, TransportCandidate local,
31
	    JingleSession jingleSession) {
32
	// TODO Auto-generated method stub
33
	return new SenderMediaSession(payloadType, remote, local, null, jingleSession);
34
    }
35

  
36
    @Override
37
    public List<PayloadType> getPayloads() {
38
	return payloads;
39
    }
40

  
41
    private void setupPayloads() {
42
	payloads = new ArrayList<PayloadType>();
43
	payloads.add(new PayloadType.Audio(42, "Test"));
44
    }
45

  
46
    @Override
47
    public String getName() {
48
	return MEDIA_NAME;
49
    }
50
}
/dev/null Thu Jan 01 00:00:00 1970 +0000 → src/com/beem/project/beem/jingle/SenderMediaSession.java Fri Mar 06 23:07:22 2009 +0100
1
/**
2
 *
3
 */
4
package com.beem.project.beem.jingle;
5

  
6
import org.jivesoftware.smackx.jingle.JingleSession;
7
import org.jivesoftware.smackx.jingle.SmackLogger;
8
import org.jivesoftware.smackx.jingle.media.JingleMediaSession;
9
import org.jivesoftware.smackx.jingle.media.PayloadType;
10
import org.jivesoftware.smackx.jingle.nat.TransportCandidate;
11

  
12
/**
13
 * @author darisk
14
 *
15
 */
16
public class SenderMediaSession extends JingleMediaSession {
17

  
18
    private static final SmackLogger LOGGER = SmackLogger.getLogger(SenderMediaSession.class);
19
    private static final String filename = "/tmp/test.jpg";
20
    private boolean active = false;
21
    private boolean started = false;
22
    private FileSender fileSender;
23

  
24
    /**
25
     * @param payloadType
26
     * @param remote
27
     * @param local
28
     * @param mediaLocator
29
     * @param jingleSession
30
     */
31
    public SenderMediaSession(PayloadType payloadType, TransportCandidate remote,
32
	    TransportCandidate local, String mediaLocator,
33
	    JingleSession jingleSession) {
34
	super(payloadType, remote, local, mediaLocator, jingleSession);
35
	initialize();
36
	LOGGER.info("Demarrage d'une session avec local: "+ local +" #remote: "+remote );
37
    }
38

  
39
    /* (non-Javadoc)
40
     * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#initialize()
41
     */
42
    @Override
43
    public void initialize() {
44
	fileSender = new FileSender(this.getRemote().getIp(), getRemote().getPort(), filename);
45
    }
46

  
47
    /* (non-Javadoc)
48
     * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#setTrasmit(boolean)
49
     */
50
    @Override
51
    public void setTrasmit(boolean active) {
52
	// TODO Auto-generated method stub
53
	this.active = active;
54
    }
55

  
56
    /* (non-Javadoc)
57
     * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#startReceive()
58
     */
59
    @Override
60
    public void startReceive() {
61
	// TODO Auto-generated method stub
62

  
63
    }
64

  
65
    /* (non-Javadoc)
66
     * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#startTrasmit()
67
     */
68
    @Override
69
    public void startTrasmit() {
70
	fileSender.start();
71
    }
72

  
73
    /* (non-Javadoc)
74
     * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#stopReceive()
75
     */
76
    @Override
77
    public void stopReceive() {
78
	// TODO Auto-generated method stub
79

  
80
    }
81

  
82
    /* (non-Javadoc)
83
     * @see org.jivesoftware.smackx.jingle.media.JingleMediaSession#stopTrasmit()
84
     */
85
    @Override
86
    public void stopTrasmit() {
87
	// TODO Auto-generated method stub
88
	started = false;
89
    }
90

  
91

  
92

  
93
}
(2-2/2)