diff options
author | Yana Stamcheva <yana@jitsi.org> | 2010-11-07 19:00:37 +0000 |
---|---|---|
committer | Yana Stamcheva <yana@jitsi.org> | 2010-11-07 19:00:37 +0000 |
commit | baea06ffedf852b7b6181c9afcd959a0bc0a2227 (patch) | |
tree | 4fea4dbbfc3225d338be19de7fdfa0ca20382e62 /src/net/java/sip/communicator | |
parent | 5e6ebdca849eb862cd23c671669a5e9f39909f74 (diff) | |
download | jitsi-baea06ffedf852b7b6181c9afcd959a0bc0a2227.zip jitsi-baea06ffedf852b7b6181c9afcd959a0bc0a2227.tar.gz jitsi-baea06ffedf852b7b6181c9afcd959a0bc0a2227.tar.bz2 |
Desktop Sharing: manage enabling/disabling local video and desktop sharing.
Diffstat (limited to 'src/net/java/sip/communicator')
8 files changed, 198 insertions, 117 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallDialog.java b/src/net/java/sip/communicator/impl/gui/main/call/CallDialog.java index 7af41f1..43ecd22 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallDialog.java @@ -171,22 +171,15 @@ public class CallDialog private Timer callDurationTimer;
/**
- * Indicates if the associated call is a desktop sharing call.
- */
- private boolean isDesktopSharing;
-
- /**
* Creates a <tt>CallDialog</tt> by specifying the underlying call panel.
*
* @param call the <tt>call</tt> that this dialog represents
- * @param isDesktopSharing indicates if the desktop sharing is enabled
*/
- public CallDialog(Call call, boolean isDesktopSharing)
+ public CallDialog(Call call)
{
super(false);
this.call = call;
- this.isDesktopSharing = isDesktopSharing;
this.callDurationTimer = new Timer(1000, new CallTimerListener());
this.callDurationTimer.setRepeats(true);
@@ -485,7 +478,10 @@ public class CallDialog */
public void setVideoButtonSelected(boolean isSelected)
{
- this.videoButton.setSelected(true);
+ if (isSelected && !videoButton.isSelected())
+ videoButton.setSelected(true);
+ else if (!isSelected && videoButton.isSelected())
+ videoButton.setSelected(false);
}
/**
@@ -507,10 +503,12 @@ public class CallDialog .getOperationSet(
OperationSetDesktopSharingServer.class) != null)
{
- ((OneToOneCallPanel) callPanel).addDesktopSharingComponents();
+ ((OneToOneCallPanel) callPanel)
+ .addDesktopSharingComponents();
}
else
- ((OneToOneCallPanel) callPanel).removeDesktopSharingComponents();
+ ((OneToOneCallPanel) callPanel)
+ .removeDesktopSharingComponents();
}
}
@@ -901,29 +899,6 @@ public class CallDialog }
/**
- * Indicates if the associated call is a desktop sharing.
- *
- * @return <tt>true</tt> if the associated call is a desktop sharing,
- * otherwise returns false
- */
- public boolean isDesktopSharing()
- {
- return isDesktopSharing;
- }
-
- /**
- * Sets the desktop sharing property to indicate that the corresponding call
- * has become or is no longer a desktop sharing.
- *
- * @param isDesktopSharing indicates if the corresponding call has become
- * a desktop sharing or is no longer a desktop sharing
- */
- public void setDesktopSharing(boolean isDesktopSharing)
- {
- this.isDesktopSharing = isDesktopSharing;
- }
-
- /**
* Replaces the current call panel with the given one.
* @param callPanel the <tt>JComponent</tt> to replace the current
* call panel
diff --git a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java index 6e0fc4a..c86b5ca 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/CallManager.java @@ -56,11 +56,6 @@ public class CallManager private static MissedCallsListener missedCallsListener; /** - * Indicates if an outgoing call is a desktop sharing. - */ - private static boolean isDesktopSharing = false; - - /** * The property indicating if the user should be warned when starting a * desktop sharing session. */ @@ -155,9 +150,7 @@ public class CallManager { Call sourceCall = event.getSourceCall(); - CallManager.openCallDialog(sourceCall, isDesktopSharing); - - isDesktopSharing = false; + CallManager.openCallDialog(sourceCall); } } @@ -206,7 +199,7 @@ public class CallManager */ public static void answerCall(final Call call) { - CallManager.openCallDialog(call, false); + CallManager.openCallDialog(call); new AnswerCallThread(call).start(); } @@ -272,6 +265,70 @@ public class CallManager } /** + * Enables/disables local video for the given call. + * + * @param enable indicates whether to enable or disable the local video + * @param call the call for which the local video should be enabled/disabled + */ + public static void enableLocalVideo(Call call, boolean enable) + { + OperationSetVideoTelephony telephony + = call.getProtocolProvider() + .getOperationSet(OperationSetVideoTelephony.class); + + boolean enableSucceeded = false; + + if (telephony != null) + { + // First disable desktop sharing if it's currently enabled. + if (enable && isDesktopSharingEnabled(call)) + enableDesktopSharing(call, false); + + try + { + telephony.setLocalVideoAllowed( + call, + enable); + + enableSucceeded = true; + } + catch (OperationFailedException ex) + { + logger.error( + "Failed to toggle the streaming of local video.", + ex); + } + } + + // If the operation didn't succeeded for some reason we make sure + // to unselect the video button. + if (enable && !enableSucceeded) + getActiveCallDialog(call).setVideoButtonSelected(false); + } + + /** + * Indicates if the desktop sharing is currently enabled for the given + * <tt>call</tt>. + * + * @param call the <tt>Call</tt>, for which we would to check if the desktop + * sharing is currently enabled + * @return <tt>true</tt> if the desktop sharing is currently enabled for the + * given <tt>call</tt>, <tt>false</tt> otherwise + */ + public static boolean isLocalVideoEnabled(Call call) + { + OperationSetVideoTelephony telephony + = call.getProtocolProvider() + .getOperationSet(OperationSetVideoTelephony.class); + + if (telephony != null + && telephony.isLocalVideoAllowed(call)) + return true; + + return false; + } + + /** * Creates a desktop sharing call to the contact represented by the given * string. * @@ -301,10 +358,6 @@ public class CallManager { if (showDesktopSharingWarning()) { - // Indicate to the outgoing call event which will be received later - // that this is a desktop sharing call. - isDesktopSharing = true; - new CreateDesktopSharingThread( protocolProvider, contact, mediaDevice).start(); @@ -315,12 +368,12 @@ public class CallManager * Enables the desktop sharing in an existing <tt>call</tt>. * * @param call the call for which desktop sharing should be enabled - * @param isEnable indicates if the desktop sharing should be enabled or + * @param enable indicates if the desktop sharing should be enabled or * disabled */ - public static void enableDesktopSharing(Call call, boolean isEnable) + public static void enableDesktopSharing(Call call, boolean enable) { - enableDesktopSharing(call, null, isEnable); + enableDesktopSharing(call, null, enable); } /** @@ -328,48 +381,76 @@ public class CallManager * * @param call the call for which desktop sharing should be enabled * @param mediaDevice the media device corresponding to the screen to share - * @param isEnable indicates if the desktop sharing should be enabled or + * @param enable indicates if the desktop sharing should be enabled or * disabled */ public static void enableDesktopSharing(Call call, MediaDevice mediaDevice, - boolean isEnable) + boolean enable) { OperationSetDesktopSharingServer desktopOpSet = call.getProtocolProvider().getOperationSet( OperationSetDesktopSharingServer.class); + boolean enableSucceeded = false; + // This shouldn't happen at this stage, because we disable the button // if the operation set isn't available. - if (desktopOpSet == null) - return; - - if (!isEnable || showDesktopSharingWarning()) + if (desktopOpSet != null) { - try - { - boolean isDesktopSharing - = desktopOpSet.isLocalVideoAllowed(call); + // First make sure to disable the local video if it's currently + // enabled. + if (enable && isLocalVideoEnabled(call)) + enableLocalVideo(call, false); - CallDialog callDialog = activeCalls.get(call); - callDialog.setDesktopSharing(!isDesktopSharing); - - if (mediaDevice != null) - desktopOpSet.setLocalVideoAllowed( - call, - mediaDevice, - !isDesktopSharing); - else - desktopOpSet.setLocalVideoAllowed( - call, - !isDesktopSharing); - } - catch (OperationFailedException ex) + if (!enable || showDesktopSharingWarning()) { - logger.error( - "Failed to toggle the streaming of local video.", ex); + try + { + if (mediaDevice != null) + desktopOpSet.setLocalVideoAllowed( + call, + mediaDevice, + enable); + else + desktopOpSet.setLocalVideoAllowed( + call, + enable); + + enableSucceeded = true; + } + catch (OperationFailedException ex) + { + logger.error( + "Failed to toggle the streaming of local video.", ex); + } } } + + if (enable && !enableSucceeded) + getActiveCallDialog(call).setDesktopSharingButtonSelected(false); + } + + /** + * Indicates if the desktop sharing is currently enabled for the given + * <tt>call</tt>. + * + * @param call the <tt>Call</tt>, for which we would to check if the desktop + * sharing is currently enabled + * @return <tt>true</tt> if the desktop sharing is currently enabled for the + * given <tt>call</tt>, <tt>false</tt> otherwise + */ + public static boolean isDesktopSharingEnabled(Call call) + { + OperationSetDesktopSharingServer desktopOpSet + = call.getProtocolProvider().getOperationSet( + OperationSetDesktopSharingServer.class); + + if (desktopOpSet != null + && desktopOpSet.isLocalVideoAllowed(call)) + return true; + + return false; } /** @@ -538,14 +619,12 @@ public class CallManager * Opens a call dialog. * * @param call the call object to pass to the call dialog - * @param isDesktopSharing indicates if the dialog to open is for desktop - * sharing * * @return the opened call dialog */ - public static CallDialog openCallDialog(Call call, boolean isDesktopSharing) + public static CallDialog openCallDialog(Call call) { - CallDialog callDialog = new CallDialog(call, isDesktopSharing); + CallDialog callDialog = new CallDialog(call); activeCalls.put(call, callDialog); @@ -639,6 +718,19 @@ public class CallManager } /** + * Returns the <tt>CallDialog</tt> corresponding to the given <tt>call</tt>. + * If the call has been finished and no active <tt>CallDialog</tt> could be + * found it returns null. + * + * @param call the <tt>Call</tt>, which dialog we're looking for + * @return the <tt>CallDialog</tt> corresponding to the given <tt>call</tt> + */ + public static CallDialog getActiveCallDialog(Call call) + { + return activeCalls.get(call); + } + + /** * Sets the given <tt>MissedCallsListener</tt> that would be notified on * any changes in missed calls count. * @param l the listener to set diff --git a/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java b/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java index c83287d..00dc29d 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/DesktopSharingButton.java @@ -62,19 +62,12 @@ public class DesktopSharingButton { if (call != null) { - OperationSetDesktopSharingServer desktopOpSet - = call.getProtocolProvider().getOperationSet( - OperationSetDesktopSharingServer.class); - - // This shouldn't happen at this stage, because we disable the button - // if the operation set isn't available. - if (desktopOpSet == null) - return; - - boolean isDesktopSharing = desktopOpSet.isLocalVideoAllowed(call); - - if (isDesktopSharing) // If it's already enabled, we disable it. + // If it's already enabled, we disable it. + if (CallManager.isDesktopSharingEnabled(call)) + { CallManager.enableDesktopSharing(call, false); + } + // Otherwise we enable the desktop sharing. else { MediaService mediaService = GuiActivator.getMediaService(); diff --git a/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java b/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java index 31a6c8a..85a8dd3 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/LocalVideoButton.java @@ -72,24 +72,7 @@ public class LocalVideoButton */ public void buttonPressed() { - OperationSetVideoTelephony telephony - = call.getProtocolProvider() - .getOperationSet(OperationSetVideoTelephony.class); - - if (telephony != null) - { - try - { - telephony.setLocalVideoAllowed( - call, - !telephony.isLocalVideoAllowed(call)); - } - catch (OperationFailedException ex) - { - logger.error( - "Failed to toggle the streaming of local video.", - ex); - } - } + CallManager.enableLocalVideo(call, + !CallManager.isLocalVideoEnabled(call)); } } diff --git a/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java b/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java index 15f2285..e875ba0 100644 --- a/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java +++ b/src/net/java/sip/communicator/impl/gui/main/call/OneToOneCallPeerPanel.java @@ -445,7 +445,22 @@ public class OneToOneCallPeerPanel { if (OperationSetVideoTelephony.LOCAL_VIDEO_STREAMING .equals(event.getPropertyName())) + { + boolean oldValue = (Boolean) event.getOldValue(); + boolean newValue = (Boolean) event.getNewValue(); + + // We ensure that when the local video property changes to + // false our related buttons would be disabled. + if (oldValue && !newValue) + { + CallDialog callDialog = callRenderer.getCallDialog(); + + callDialog.setVideoButtonSelected(false); + callDialog.setDesktopSharingButtonSelected(false); + } + handleLocalVideoStreamingChange(this); + } } /** @@ -829,18 +844,20 @@ public class OneToOneCallPeerPanel videoContainer.add(localVideo, VideoLayout.LOCAL, 0); CallDialog callDialog = callRenderer.getCallDialog(); + Call call = callPeer.getCall(); /* * If the local video or desktop sharing is turned on, we ensure * that the button is selected. */ - if (callDialog.isDesktopSharing()) + if (CallManager.isDesktopSharingEnabled(call)) { callDialog.setDesktopSharingButtonSelected(true); } - else if (!callDialog.isDesktopSharing() - && !callDialog.isVideoButtonSelected()) + else if (CallManager.isLocalVideoEnabled(call)) + { callDialog.setVideoButtonSelected(true); + } } videoContainer.validate(); diff --git a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetDesktopStreamingSipImpl.java b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetDesktopStreamingSipImpl.java index bda1b02..ace910b 100644 --- a/src/net/java/sip/communicator/impl/protocol/sip/OperationSetDesktopStreamingSipImpl.java +++ b/src/net/java/sip/communicator/impl/protocol/sip/OperationSetDesktopStreamingSipImpl.java @@ -146,6 +146,22 @@ public class OperationSetDesktopStreamingSipImpl } /** + * Implements OperationSetVideoTelephony#isLocalVideoAllowed(Call). Modifies + * the local media setup to reflect the requested setting for the streaming + * of the local video. + * + * @param call the <tt>Call</tt> whose video transmission properties we are + * interested in. + * + * @return <tt>true</tt> if the streaming of local video for the specified + * <tt>Call</tt> is allowed; otherwise, <tt>false</tt> + */ + public boolean isLocalVideoAllowed(Call call) + { + return ((CallSipImpl)call).isLocalVideoAllowed(MediaUseCase.DESKTOP); + } + + /** * Sets the indicator which determines whether the streaming of local video * in a specific <tt>Call</tt> is allowed. The setting does not reflect * the availability of actual video capture devices, it just expresses the diff --git a/src/net/java/sip/communicator/service/protocol/media/AbstractOperationSetVideoTelephony.java b/src/net/java/sip/communicator/service/protocol/media/AbstractOperationSetVideoTelephony.java index 05edb58..5a9fc90 100644 --- a/src/net/java/sip/communicator/service/protocol/media/AbstractOperationSetVideoTelephony.java +++ b/src/net/java/sip/communicator/service/protocol/media/AbstractOperationSetVideoTelephony.java @@ -188,7 +188,7 @@ public abstract class AbstractOperationSetVideoTelephony< @SuppressWarnings("unchecked") // work with MediaAware* in media package public boolean isLocalVideoAllowed(Call call) { - return ((V)call).isLocalVideoAllowed(); + return ((V)call).isLocalVideoAllowed(MediaUseCase.CALL); } /** diff --git a/src/net/java/sip/communicator/service/protocol/media/MediaAwareCall.java b/src/net/java/sip/communicator/service/protocol/media/MediaAwareCall.java index 8fc179c..07e5036 100644 --- a/src/net/java/sip/communicator/service/protocol/media/MediaAwareCall.java +++ b/src/net/java/sip/communicator/service/protocol/media/MediaAwareCall.java @@ -529,12 +529,17 @@ public abstract class MediaAwareCall< * desire of the user) to have the local video streamed in the case the * system is actually able to do so. * + * @param useCase the use case of the video (i.e video call or desktop + * streaming/sharing session) * @return <tt>true</tt> if the streaming of local video for this * <tt>Call</tt> is allowed; otherwise, <tt>false</tt> */ - public boolean isLocalVideoAllowed() + public boolean isLocalVideoAllowed(MediaUseCase useCase) { - return localVideoAllowed; + if (mediaUseCase.equals(useCase)) + return localVideoAllowed; + else + return false; } /** |