aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/protocol/jabber/OperationSetDesktopSharingClientJabberImpl.java
blob: 190ddc739c69926729ad618e1c94b78e1246e50b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.protocol.jabber;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List; // disambiguation

import org.jivesoftware.smack.packet.*;

import net.java.sip.communicator.impl.protocol.jabber.extensions.inputevt.*;
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.util.*;

/**
 * Implements all desktop sharing client-side related functions for Jabber
 * protocol.
 *
 * @author Sebastien Vincent
 */
public class OperationSetDesktopSharingClientJabberImpl
    implements OperationSetDesktopSharingClient
{
    /**
     * Our class logger.
     */
    private static final Logger logger =
        Logger.getLogger(OperationSetDesktopSharingClientJabberImpl.class);

    /**
     * The Jabber <tt>ProtocolProviderService</tt> implementation which created
     * this instance and for which telephony conferencing services are being
     * provided by this instance.
     */
    private final ProtocolProviderServiceJabberImpl parentProvider;

    /**
     * List of listeners to be notified when a change occurred in remote control
     * access.
     */
    private List<RemoteControlListener> listeners =
        new ArrayList<RemoteControlListener>();

    /**
     * Initializes a new <tt>OperationSetDesktopSharingClientJabberImpl</tt>.
     *
     * @param parentProvider the Jabber <tt>ProtocolProviderService</tt>
     * implementation which has requested the creation of the new instance and
     * for which the new instance is to provide desktop sharing.
     */
    public OperationSetDesktopSharingClientJabberImpl(
            ProtocolProviderServiceJabberImpl parentProvider)
    {
        this.parentProvider = parentProvider;
    }

    /**
     * Fire a <tt>RemoteControlGrantedEvent</tt> to all registered listeners.
     */
    public void fireRemoteControlGranted()
    {
        RemoteControlGrantedEvent event = new RemoteControlGrantedEvent(this);

        for (RemoteControlListener l : listeners)
        {
            l.remoteControlGranted(event);
        }
    }

    /**
     * Fire a <tt>RemoteControlGrantedEvent</tt> to all registered listeners.
     */
    public void fireRemoteControlRevoked()
    {
        RemoteControlRevokedEvent event = new RemoteControlRevokedEvent(this);

        for (RemoteControlListener l : listeners)
        {
            l.remoteControlRevoked(event);
        }
    }

    /**
     * Add a <tt>RemoteControlListener</tt> to be notified when remote peer
     * accept to give us full control.
     *
     * @param listener <tt>RemoteControlListener</tt> to add
     */
    public void addRemoteControlListener(RemoteControlListener listener)
    {
        if (logger.isInfoEnabled())
            logger.info("Enable remote control");

        if (!listeners.contains(listener))
        {
            listeners.add(listener);
        }
    }

    /**
     * Remove a <tt>RemoteControlListener</tt> to be notified when remote peer
     * accept/revoke to give us full control.
     *
     * @param listener <tt>RemoteControlListener</tt> to remove
     */
    public void removeRemoteControlListener(RemoteControlListener listener)
    {
        if (logger.isInfoEnabled())
            logger.info("Disable remote control");

        if (listeners.contains(listener))
        {
            listeners.remove(listener);
        }
    }

    /**
     * Send a keyboard notification.
     *
     * @param callPeer <tt>CallPeer</tt> that will be notified
     * @param event <tt>KeyEvent</tt> received and that will be send to remote
     * peer
     */
    public void sendKeyboardEvent(CallPeer callPeer, KeyEvent event)
    {
        RemoteControlExtension payload = new RemoteControlExtension(event);
        InputEvtIQ inputIQ = new InputEvtIQ();

        inputIQ.setAction(InputEvtAction.NOTIFY);
        inputIQ.setType(IQ.Type.SET);
        inputIQ.setFrom(parentProvider.getOurJID());
        inputIQ.setTo(callPeer.getAddress());
        inputIQ.addRemoteControl(payload);
        parentProvider.getConnection().sendPacket(inputIQ);
    }

    /**
     * Send a mouse notification.
     *
     * @param callPeer <tt>CallPeer</tt> that will be notified
     * @param event <tt>MouseEvent</tt> received and that will be send to remote
     * peer
     */
    public void sendMouseEvent(CallPeer callPeer, MouseEvent event)
    {
        RemoteControlExtension payload = new RemoteControlExtension(event);
        InputEvtIQ inputIQ = new InputEvtIQ();

        inputIQ.setAction(InputEvtAction.NOTIFY);
        inputIQ.setType(IQ.Type.SET);
        inputIQ.setFrom(parentProvider.getOurJID());
        inputIQ.setTo(callPeer.getAddress());
        inputIQ.addRemoteControl(payload);
        parentProvider.getConnection().sendPacket(inputIQ);
    }

    /**
     * Send a mouse notification for specific "moved" <tt>MouseEvent</tt>. As
     * controller computer could have smaller desktop that controlled ones, we
     * should take care to send the percentage of point x and point y.
     *
     * @param callPeer <tt>CallPeer</tt> that will be notified
     * @param event <tt>MouseEvent</tt> received and that will be send to remote
     * peer
     * @param videoPanelSize size of the panel that contains video
     */
    public void sendMouseEvent(CallPeer callPeer, MouseEvent event,
            Dimension videoPanelSize)
    {
        RemoteControlExtension payload = new RemoteControlExtension(event,
                videoPanelSize);
        InputEvtIQ inputIQ = new InputEvtIQ();

        inputIQ.setAction(InputEvtAction.NOTIFY);
        inputIQ.setType(IQ.Type.SET);
        inputIQ.setFrom(parentProvider.getOurJID());
        inputIQ.setTo(callPeer.getAddress());
        inputIQ.addRemoteControl(payload);
        parentProvider.getConnection().sendPacket(inputIQ);
    }
}