// derive stun and turn server addresses from the connection:
StunTurnAddress sta = StunTurnAddress.getAddress( connection );
// create an ice agent using the stun/turn address. We will need this to figure out
// how to connect our clients:
final IceAgent iceAgent = new IceAgent(true, sta);
// setup our jingle stream manager using the default audio and video devices:
final JingleStreamManager jsm = new JingleStreamManager(CreatorEnum.initiator);
jsm.addDefaultMedia(MediaType.VIDEO, "video");
jsm.addDefaultMedia(MediaType.AUDIO, "audio");
// create ice streams that correspond to the jingle streams that we want
iceAgent.createStreams(jsm.getMediaNames());
// Handle all incoming Jingle packets with a Jingle Packet Handler.
// The main thing we need to do is ensure that created Jingle sessions
// are of our ReceiverJingleSession type.
new JinglePacketHandler(connection) {
@Override
public JingleSession createJingleSession( String sid, JingleIQ jiq ) {
return new CallerJingleSession(iceAgent, jsm, this, receiverJid, sid, this.connection);
}
} ;
// display all incoming packets:
connection.addPacketListener( new PacketListener() {
@Override
public void processPacket(Packet packet) {
System.out.println( CALLER + ": " + packet.toXML() );
}
},
new PacketFilter() {
@Override
public boolean accept(Packet packet) {
return packet.getClass() == JingleIQ.class;
}
} );
// PacketCollector collector = connection.createPacketCollector( new PacketFilter() {
// @Override
// public boolean accept(Packet packet) {
// return true;
// }} );
// log in:
log( CALLER, "logging on as " + username + "/" + CALLER );
connection.login(username, password, CALLER);
//this only works if they are in our roster
// log( CALLER, "Waiting for Receiver to become available." );
// while( running && !connection.getRoster().contains(receiverJid) ) {
// collector.nextResult(100);
// }
// Use Ice and JingleSessionManager to initiate session:
log( CALLER, "Ringing" );
List<ContentPacketExtension> contentList = jsm.createContentList(SendersEnum.both);
iceAgent.addLocalCandidateToContents(contentList);
JingleIQ sessionInitIQ = JinglePacketFactory.createSessionInitiate(
connection.getUser(),
receiverJid,
JingleIQ.generateSID(),