/** * Activates the listenerJingles on a Jingle session request. * * @param initJin the packet that must be passed to the jingleSessionRequestListener. */ void triggerSessionRequested(Jingle initJin) { JingleSessionRequestListener[] jingleSessionRequestListeners = null; // Make a synchronized copy of the listenerJingles synchronized (this.jingleSessionRequestListeners) { jingleSessionRequestListeners = new JingleSessionRequestListener[this.jingleSessionRequestListeners.size()]; this.jingleSessionRequestListeners.toArray(jingleSessionRequestListeners); } // ... and let them know of the event JingleSessionRequest request = new JingleSessionRequest(this, initJin); for (int i = 0; i < jingleSessionRequestListeners.length; i++) { jingleSessionRequestListeners[i].sessionRequested(request); } }
/** * Adds Jingle and ChatRoom listeners. */ private void addListeners() { if (jingleManager == null) { if (readyToConnect) { Log.error("Unable to resolve Jingle Connection (Host: "+stunServer+" Port: "+stunPort+")"); } return; } // Listen in for new incoming Jingle requests. jingleManager.addJingleSessionRequestListener(new JingleSessionRequestListener() { public void sessionRequested(final JingleSessionRequest request) { SwingUtilities.invokeLater(new Runnable() { public void run() { incomingJingleSession(request); } }); } }); }
public void initialize() { ICETransportManager icetm0 = new ICETransportManager(xmppConnection, "10.47.47.53", 3478); List<JingleMediaManager> mediaManagers = new ArrayList<JingleMediaManager>(); //mediaManagers.add(new JmfMediaManager(icetm0)); mediaManagers.add(new SpeexMediaManager(icetm0)); mediaManagers.add(new ScreenShareMediaManager(icetm0)); jm = new JingleManager(xmppConnection, mediaManagers); jm.addCreationListener(icetm0); jm.addJingleSessionRequestListener(new JingleSessionRequestListener() { public void sessionRequested(JingleSessionRequest request) { // if (incoming != null) // return; try { // Accept the call incoming = request.accept(); // Start the call incoming.startIncoming(); } catch (XMPPException e) { e.printStackTrace(); } } }); createGUI(); }
/** * Add a Jingle session request listenerJingle to listen to incoming session * requests. * * @param jingleSessionRequestListener an implemented JingleSessionRequestListener * @see #removeJingleSessionRequestListener(JingleSessionRequestListener) * @see JingleListener */ public synchronized void addJingleSessionRequestListener(final JingleSessionRequestListener jingleSessionRequestListener) { if (jingleSessionRequestListener != null) { if (jingleSessionRequestListeners == null) { initJingleSessionRequestListeners(); } synchronized (jingleSessionRequestListeners) { jingleSessionRequestListeners.add(jingleSessionRequestListener); } } }
/** * Removes a Jingle session listenerJingle. * * @param jingleSessionRequestListener The jingle session jingleSessionRequestListener to be removed * @see #addJingleSessionRequestListener(JingleSessionRequestListener) * @see JingleListener */ public void removeJingleSessionRequestListener(JingleSessionRequestListener jingleSessionRequestListener) { if (jingleSessionRequestListeners == null) { return; } synchronized (jingleSessionRequestListeners) { jingleSessionRequestListeners.remove(jingleSessionRequestListener); } }
/** * Register the listenerJingles, waiting for a Jingle packet that tries to * establish a new session. */ private void initJingleSessionRequestListeners() { PacketFilter initRequestFilter = new PacketFilter() { // Return true if we accept this packet public boolean accept(Packet pin) { if (pin instanceof IQ) { IQ iq = (IQ) pin; if (iq.getType().equals(IQ.Type.SET)) { if (iq instanceof Jingle) { Jingle jin = (Jingle) pin; if (jin.getAction().equals(JingleActionEnum.SESSION_INITIATE)) { return true; } } } } return false; } }; jingleSessionRequestListeners = new ArrayList<JingleSessionRequestListener>(); // Start a packet listener for session initiation requests connection.addPacketListener(new PacketListener() { public void processPacket(Packet packet) { triggerSessionRequested((Jingle) packet); } }, initRequestFilter); }
/** * High level API test. This is a simple test to use with an XMPP client and * check if the client receives the message 1. User_1 will send an * invitation to user_2. */ public void testSendSimpleMessage() { resetCounter(); try { FixedResolver tr0 = new FixedResolver("127.0.0.1", 54222); FixedTransportManager ftm0 = new FixedTransportManager(tr0); TestMediaManager tmm0 = new TestMediaManager(ftm0); tmm0.setPayloads(getTestPayloads1()); List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>(); trl0.add(tmm0); FixedResolver tr1 = new FixedResolver("127.0.0.1", 54567); FixedTransportManager ftm1 = new FixedTransportManager(tr1); TestMediaManager tmm1 = new TestMediaManager(ftm1); tmm1.setPayloads(getTestPayloads1()); List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>(); trl1.add(tmm1); JingleManager man0 = new JingleManager(getConnection(0), trl0); JingleManager man1 = new JingleManager(getConnection(1), trl1); // Session 1 waits for connections man1.addJingleSessionRequestListener(new JingleSessionRequestListener() { /** * Called when a new session request is detected */ public void sessionRequested(final JingleSessionRequest request) { incCounter(); System.out.println("Session request detected, from " + request.getFrom()); } }); // Session 0 starts a request System.out.println("Starting session request, to " + getFullJID(1) + "..."); JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1)); session0.startOutgoing(); Thread.sleep(5000); assertTrue(valCounter() > 0); } catch (Exception e) { e.printStackTrace(); fail("An error occured with Jingle"); } }