Search in sources :

Example 1 with ImageReceiver

use of org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageReceiver in project Smack by igniterealtime.

the class ScreenShareSession method initialize.

/**
     * Initialize the screen share channels.
     */
@Override
public void initialize() {
    JingleSession session = getJingleSession();
    if ((session != null) && (session.getInitiator().equals(session.getConnection().getUser()))) {
        // If the initiator of the jingle session is us then we transmit a screen share.
        try {
            InetAddress remote = InetAddress.getByName(getRemote().getIp());
            transmitter = new ImageTransmitter(new DatagramSocket(getLocal().getPort()), remote, getRemote().getPort(), new Rectangle(0, 0, width, height));
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
    } else {
        // Otherwise we receive a screen share.
        JFrame window = new JFrame();
        JPanel jp = new JPanel();
        window.add(jp);
        window.setLocation(0, 0);
        window.setSize(600, 600);
        window.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosed(WindowEvent e) {
                receiver.stop();
            }
        });
        try {
            receiver = new ImageReceiver(InetAddress.getByName("0.0.0.0"), getRemote().getPort(), getLocal().getPort(), width, height);
            LOGGER.fine("Receiving on:" + receiver.getLocalPort());
        } catch (UnknownHostException e) {
            LOGGER.log(Level.WARNING, "exception", e);
        }
        jp.add(receiver);
        receiver.setVisible(true);
        window.setAlwaysOnTop(true);
        window.setVisible(true);
    }
}
Also used : JPanel(javax.swing.JPanel) ImageTransmitter(org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageTransmitter) UnknownHostException(java.net.UnknownHostException) Rectangle(java.awt.Rectangle) JingleSession(org.jivesoftware.smackx.jingleold.JingleSession) WindowAdapter(java.awt.event.WindowAdapter) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ImageReceiver(org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageReceiver) DatagramSocket(java.net.DatagramSocket) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) InetAddress(java.net.InetAddress)

Aggregations

Rectangle (java.awt.Rectangle)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 IOException (java.io.IOException)1 DatagramSocket (java.net.DatagramSocket)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 JFrame (javax.swing.JFrame)1 JPanel (javax.swing.JPanel)1 JingleSession (org.jivesoftware.smackx.jingleold.JingleSession)1 ImageReceiver (org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageReceiver)1 ImageTransmitter (org.jivesoftware.smackx.jingleold.mediaimpl.sshare.api.ImageTransmitter)1