diff options
author | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2012-10-19 19:40:11 +0000 |
---|---|---|
committer | Lyubomir Marinov <lyubomir.marinov@jitsi.org> | 2012-10-19 19:40:11 +0000 |
commit | 5874178227a1c730e563ffae6ca4d016e063cf36 (patch) | |
tree | 99ccf38d6f46196500607872b88d85e3dc8db8d7 /src/net/java | |
parent | 0fd021bc9e7bba85221a276871b8d20c8b30da16 (diff) | |
download | jitsi-5874178227a1c730e563ffae6ca4d016e063cf36.zip jitsi-5874178227a1c730e563ffae6ca4d016e063cf36.tar.gz jitsi-5874178227a1c730e563ffae6ca4d016e063cf36.tar.bz2 |
Renames a couple of methods upon request by Emil Ivov. Fixes an endless loop on hangup. Commits work in progress on sound notifications.
Diffstat (limited to 'src/net/java')
4 files changed, 301 insertions, 272 deletions
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 dd19e3e..fe6ed9b 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 @@ -1983,18 +1983,58 @@ public class CallManager } /** - * Invites a list of callees to a specific conference <tt>Call</tt>. If the - * specified <tt>Call</tt> is <tt>null</tt>, creates a brand new telephony - * conference. + * Invites a list of callees to a conference <tt>Call</tt>. If the specified + * <tt>Call</tt> is <tt>null</tt>, creates a brand new telephony conference. */ private static class InviteToConferenceCallThread extends Thread { + /** + * The addresses of the callees to be invited into the telephony + * conference to be organized by this instance. For further details, + * refer to the documentation on the <tt>callees</tt> parameter of the + * respective <tt>InviteToConferenceCallThread</tt> constructor. + */ private final Map<ProtocolProviderService, List<String>> callees; + /** + * The <tt>Call</tt>, if any, into the telephony conference of which + * {@link #callees} are to be invited. If non-<tt>null</tt>, its + * <tt>CallConference</tt> state will be shared with all <tt>Call</tt>s + * established by this instance for the purposes of having the + * <tt>callees</tt> into the same telephony conference. + */ private final Call call; + /** + * Initializes a new <tt>InviteToConferenceCallThread</tt> instance + * which is to invite a list of callees to a conference <tt>Call</tt>. + * If the specified <tt>call</tt> is <tt>null</tt>, creates a brand new + * telephony conference. + * + * @param callees the addresses of the callees to be invited into a + * telephony conference. The addresses are provided in multiple + * <tt>List<String></tt>s. Each such list of addresses is mapped + * by the <tt>ProtocolProviderService</tt> through which they are to be + * invited into the telephony conference. If there are multiple + * <tt>ProtocolProviderService</tt>s in the specified <tt>Map</tt>, the + * resulting telephony conference is known by the name + * "cross-protocol". It is also allowed to have a list of + * addresses mapped to <tt>null</tt> which means that the new instance + * will automatically choose a <tt>ProtocolProviderService</tt> to + * invite the respective callees into the telephony conference. + * @param call the <tt>Call</tt> to invite the specified + * <tt>callees</tt> into. If <tt>null</tt>, this instance will create a + * brand new telephony conference. Technically, a <tt>Call</tt> instance + * is protocol/account-specific and it is possible to have + * cross-protocol/account telephony conferences. That's why the + * specified <tt>callees</tt> are invited into one and the same + * <tt>CallConference</tt>: the one in which the specified <tt>call</tt> + * is participating or a new one if <tt>call</tt> is <tt>null</tt>. Of + * course, an attempt is made to have all callees from one and the same + * protocol/account into one <tt>Call</tt> instance. + */ public InviteToConferenceCallThread( Map<ProtocolProviderService, List<String>> callees, Call call) @@ -2003,13 +2043,15 @@ public class CallManager this.call = call; } + /** + * Invites {@link #callees} into a telephony conference which is + * optionally specified by {@link #call}. + */ @Override public void run() { - CallConference conference = null; - - if (call != null) - conference = call.getConference(); + CallConference conference + = (call == null) ? null : call.getConference(); for(Map.Entry<ProtocolProviderService, List<String>> entry : callees.entrySet()) @@ -2177,9 +2219,7 @@ public class CallManager else { for (String contact : callees) - { opSetVideoBridge.inviteCalleeToCall(contact, call); - } } } catch(Exception e) @@ -2285,7 +2325,7 @@ public class CallManager Iterator<? extends CallPeer> peerIter = call.getCallPeers(); while (peerIter.hasNext()) - peers.add(peer); + peers.add(peerIter.next()); } if (conference != null) peers.addAll(conference.getCallPeers()); diff --git a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java index fa44b06..556f1e6 100644 --- a/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java +++ b/src/net/java/sip/communicator/impl/gui/main/menus/ToolsMenu.java @@ -201,32 +201,30 @@ public class ToolsMenu } else if (itemName.equals("sound")) { - boolean isMute = GuiActivator.getAudioNotifier().isMute(); - - GuiActivator.getAudioNotifier().setMute(!isMute); + boolean mute = !GuiActivator.getAudioNotifier().isMute(); + GuiActivator.getAudioNotifier().setMute(mute); { - // also set mute to notification service and its - // sound handlers - for(NotificationHandler handler : - GuiActivator.getNotificationService() - .getActionHandlers(NotificationAction.ACTION_SOUND)) + // Distribute the mute state to the SoundNotificaitonHandler. + for(NotificationHandler handler + : GuiActivator.getNotificationService() + .getActionHandlers(NotificationAction.ACTION_SOUND)) { if(handler instanceof SoundNotificationHandler) { SoundNotificationHandler soundHandler - = (SoundNotificationHandler)handler; - soundHandler.setMute(!soundHandler.isMute()); + = (SoundNotificationHandler) handler; + + soundHandler.setMute(mute); } } } - String itemTextKey = !isMute - ? "service.gui.SOUND_ON" - : "service.gui.SOUND_OFF"; - menuItem.setText( - GuiActivator.getResources().getI18NString(itemTextKey)); + GuiActivator.getResources().getI18NString( + mute + ? "service.gui.SOUND_ON" + : "service.gui.SOUND_OFF")); } } @@ -529,7 +527,7 @@ public class ToolsMenu extends JMenuItem implements ActionListener { - private ProtocolProviderService protocolProvider; + private final ProtocolProviderService protocolProvider; /** * Creates an instance of <tt>VideoBridgeProviderMenuItem</tt> by diff --git a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java index c3e4ab2..5e6156f 100644 --- a/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java +++ b/src/net/java/sip/communicator/impl/notification/SoundNotificationHandlerImpl.java @@ -90,7 +90,10 @@ public class SoundNotificationHandlerImpl { case NOTIFICATION: case PLAYBACK: - audio = audioNotifService.createAudio(action.getDescriptor(), SCAudioClipDevice.PLAYBACK.equals(device)); + audio + = audioNotifService.createAudio( + action.getDescriptor(), + SCAudioClipDevice.PLAYBACK.equals(device)); break; case PC_SPEAKER: @@ -104,14 +107,25 @@ public class SoundNotificationHandlerImpl playedClips.put(audio, data); - @SuppressWarnings("unchecked") - Callable<Boolean> loopCondition - = (Callable<Boolean>) - data.getExtra( - NotificationData - .SOUND_NOTIFICATION_HANDLER_LOOP_CONDITION_EXTRA); + boolean played = false; - audio.play(action.getLoopInterval(), loopCondition); + try + { + @SuppressWarnings("unchecked") + Callable<Boolean> loopCondition + = (Callable<Boolean>) + data.getExtra( + NotificationData + .SOUND_NOTIFICATION_HANDLER_LOOP_CONDITION_EXTRA); + + audio.play(action.getLoopInterval(), loopCondition); + played = true; + } + finally + { + if (!played) + playedClips.remove(audio); + } } /** @@ -119,26 +133,17 @@ public class SoundNotificationHandlerImpl * * @param isMute mute or not currently playing sounds */ - public void setMute(boolean isMute) + public void setMute(boolean mute) { - this.mute = isMute; + this.mute = mute; - if(isMute) + if (mute) { - AudioNotifierService audioNotifService + AudioNotifierService ans = NotificationActivator.getAudioNotifier(); - if(audioNotifService == null) - return; - - // stop all sounds - for (Map.Entry<SCAudioClip, NotificationData> entry : playedClips - .entrySet()) - { - SCAudioClip audio = entry.getKey(); - audio.stop(); - audioNotifService.destroyAudio(audio); - } + if ((ans != null) && (ans.isMute() != this.mute)) + ans.setMute(this.mute); } } @@ -193,18 +198,26 @@ public class SoundNotificationHandlerImpl AudioNotifierService audioNotifService = NotificationActivator.getAudioNotifier(); - if(audioNotifService == null) - return; - - for (Map.Entry<SCAudioClip, NotificationData> entry - : playedClips.entrySet()) + if (audioNotifService != null) { - if(entry.getValue() == data) - { - SCAudioClip audio = entry.getKey(); + Iterator<Map.Entry<SCAudioClip, NotificationData>> i + = playedClips.entrySet().iterator(); - audio.stop(); - audioNotifService.destroyAudio(audio); + while (i.hasNext()) + { + Map.Entry<SCAudioClip, NotificationData> e = i.next(); + + if (e.getValue() == data) + { + try + { + e.getKey().stop(); + } + finally + { + i.remove(); + } + } } } } diff --git a/src/net/java/sip/communicator/service/protocol/CallConference.java b/src/net/java/sip/communicator/service/protocol/CallConference.java index 46fd84f..23674cc 100644 --- a/src/net/java/sip/communicator/service/protocol/CallConference.java +++ b/src/net/java/sip/communicator/service/protocol/CallConference.java @@ -40,6 +40,109 @@ public class CallConference public static final String CALLS = "calls"; /** + * Gets the number of <tt>CallPeer</tt>s associated with the <tt>Call</tt>s + * participating in the telephony conference-related state of a specific + * <tt>Call</tt>. + * + * @param call the <tt>Call</tt> for which the number of <tt>CallPeer</tt>s + * associated with the <tt>Call</tt>s participating in its associated + * telephony conference-related state + * @return the number of <tt>CallPeer</tt>s associated with the + * <tt>Call</tt>s participating in the telephony conference-related state + * of the specified <tt>call</tt> + */ + public static int getCallPeerCount(Call call) + { + CallConference conference = call.getConference(); + + /* + * A Call instance is supposed to always maintain a CallConference + * instance. Anyway, if it turns out that it is not the case, we will + * consider the Call as a representation of a telephony conference. + */ + return + (conference == null) + ? call.getCallPeerCount() + : conference.getCallPeerCount(); + } + + /** + * Gets a list of the <tt>CallPeer</tt>s associated with the <tt>Call</tt>s + * participating in the telephony conference in which a specific + * <tt>Call</tt> is participating. + * + * @param call the <tt>Call</tt> which specifies the telephony conference + * the <tt>CallPeer</tt>s of which are to be retrieved + * @return a list of the <tt>CallPeer</tt>s associated with the + * <tt>Call</tt>s participating in the telephony conference in which the + * specified <tt>call</tt> is participating + */ + public static List<CallPeer> getCallPeers(Call call) + { + CallConference conference = call.getConference(); + List<CallPeer> callPeers = new ArrayList<CallPeer>(); + + if (conference == null) + { + Iterator<? extends CallPeer> callPeerIt = call.getCallPeers(); + + while (callPeerIt.hasNext()) + callPeers.add(callPeerIt.next()); + } + else + conference.getCallPeers(callPeers); + return callPeers; + } + + /** + * Gets the list of <tt>Call</tt>s participating in the telephony conference + * in which a specific <tt>Call</tt> is participating. + * + * @param call the <tt>Call</tt> which participates in the telephony + * conference the list of participating <tt>Call</tt>s of which is to be + * returned + * @return the list of <tt>Call</tt>s participating in the telephony + * conference in which the specified <tt>call</tt> is participating + */ + public static List<Call> getCalls(Call call) + { + CallConference conference = call.getConference(); + List<Call> calls; + + if (conference == null) + calls = Collections.emptyList(); + else + calls = conference.getCalls(); + return calls; + } + + /** + * Determines whether a <tt>CallConference</tt> is to report the local + * peer/user as a conference focus judging by a specific list of + * <tt>Call</tt>s. + * + * @param calls the list of <tt>Call</tt> which are to be judged whether + * the local peer/user that they represent is to be considered as a + * conference focus + * @return <tt>true</tt> if the local peer/user represented by the specified + * <tt>calls</tt> is judged to be a conference focus; otherwise, + * <tt>false</tt> + */ + private static boolean isConferenceFocus(List<Call> calls) + { + int callCount = calls.size(); + boolean conferenceFocus; + + if (callCount < 1) + conferenceFocus = false; + else if (callCount > 1) + conferenceFocus = true; + else + conferenceFocus = (calls.get(0).getCallPeerCount() > 1); + return conferenceFocus; + } + + /** * The <tt>CallChangeListener</tt> which listens to changes in the * <tt>Call</tt>s participating in this telephony conference. */ @@ -48,12 +151,12 @@ public class CallConference { public void callPeerAdded(CallPeerEvent ev) { - CallConference.this.callPeerAdded(ev); + CallConference.this.onCallPeerEvent(ev); } public void callPeerRemoved(CallPeerEvent ev) { - CallConference.this.callPeerRemoved(ev); + CallConference.this.onCallPeerEvent(ev); } public void callStateChanged(CallChangeEvent ev) @@ -303,114 +406,6 @@ public class CallConference } /** - * Notifies this telephony conference that a <tt>CallPeer</tt> has been - * added to a <tt>Call</tt>. - * - * @param ev a <tt>CallPeerEvent</tt> which specifies the <tt>CallPeer</tt> - * which has been added and the <tt>Call</tt> to which it has been added - */ - private void callPeerAdded(CallPeerEvent ev) - { - /* - * XXX The callPeerRemoved method calls the callPeerAdded method because - * they both do pretty much the same thing. The callPeerAdded method - * makes the distinctions where necessary by examining the eventID of - * the CallPeerEvent. - */ - - Call call = ev.getSourceCall(); - - if (containsCall(call)) - { - /* - * Update the conferenceFocus state. Following the line of thinking - * expressed in the callAdded and callRemoved methods, only update - * it if the new conferenceFocus value is in accord with the - * expectations. - */ - int eventID = ev.getEventID(); - boolean conferenceFocus = isConferenceFocus(getCalls()); - - switch (eventID) - { - case CallPeerEvent.CALL_PEER_ADDED: - if (conferenceFocus) - setConferenceFocus(conferenceFocus); - break; - case CallPeerEvent.CALL_PEER_REMOVED: - if (!conferenceFocus) - setConferenceFocus(conferenceFocus); - break; - default: - /* - * We're interested in the adding and removing of CallPeers - * only. - */ - break; - } - - try - { - // Forward the CallPeerEvent to the callChangeListeners. - for (CallChangeListener l : getCallChangeListeners()) - { - switch (eventID) - { - case CallPeerEvent.CALL_PEER_ADDED: - l.callPeerAdded(ev); - break; - case CallPeerEvent.CALL_PEER_REMOVED: - l.callPeerRemoved(ev); - break; - default: - break; - } - } - } - finally - { - /* - * Add/remove the callPeerConferenceListener to/from the source - * CallPeer (for the purposes of the - * addCallPeerConferenceListener method of this CallConference). - */ - CallPeer callPeer = ev.getSourceCallPeer(); - - switch (eventID) - { - case CallPeerEvent.CALL_PEER_ADDED: - callPeer.addCallPeerConferenceListener( - callPeerConferenceListener); - break; - case CallPeerEvent.CALL_PEER_REMOVED: - callPeer.removeCallPeerConferenceListener( - callPeerConferenceListener); - break; - default: - break; - } - } - } - } - - /** - * Notifies this telephony conference that a <tt>CallPeer</tt> has been - * removed from a <tt>Call</tt>. - * - * @param ev a <tt>CallPeerEvent</tt> which specifies the <tt>CallPeer</tt> - * which has been removed and the <tt>Call</tt> from which it has been - * removed - */ - private void callPeerRemoved(CallPeerEvent ev) - { - /* - * The callPeerAdded method will take into account the eventID of the - * CallPeerEvent. - */ - callPeerAdded(ev); - } - - /** * Notifies this <tt>CallConference</tt> that a specific <tt>Call</tt> has * been removed from the list of <tt>Call</tt>s participating in this * telephony conference. @@ -575,33 +570,6 @@ public class CallConference } /** - * Gets the number of <tt>CallPeer</tt>s associated with the <tt>Call</tt>s - * participating in the telephony conference-related state of a specific - * <tt>Call</tt>. - * - * @param call the <tt>Call</tt> for which the number of <tt>CallPeer</tt>s - * associated with the <tt>Call</tt>s participating in its associated - * telephony conference-related state - * @return the number of <tt>CallPeer</tt>s associated with the - * <tt>Call</tt>s participating in the telephony conference-related state - * of the specified <tt>call</tt> - */ - public static int getCallPeerCount(Call call) - { - CallConference conference = call.getConference(); - - /* - * A Call instance is supposed to always maintain a CallConference - * instance. Anyway, if it turns out that it is not the case, we will - * consider the Call as a representation of a telephony conference. - */ - return - (conference == null) - ? call.getCallPeerCount() - : conference.getCallPeerCount(); - } - - /** * Gets a list of the <tt>CallPeer</tt>s associated with the <tt>Call</tt>s * participating in this telephony conference. * @@ -617,34 +585,6 @@ public class CallConference } /** - * Gets a list of the <tt>CallPeer</tt>s associated with the <tt>Call</tt>s - * participating in the telephony conference in which a specific - * <tt>Call</tt> is participating. - * - * @param call the <tt>Call</tt> which specifies the telephony conference - * the <tt>CallPeer</tt>s of which are to be retrieved - * @return a list of the <tt>CallPeer</tt>s associated with the - * <tt>Call</tt>s participating in the telephony conference in which the - * specified <tt>call</tt> is participating - */ - public static List<CallPeer> getCallPeers(Call call) - { - CallConference conference = call.getConference(); - List<CallPeer> callPeers = new ArrayList<CallPeer>(); - - if (conference == null) - { - Iterator<? extends CallPeer> callPeerIt = call.getCallPeers(); - - while (callPeerIt.hasNext()) - callPeers.add(callPeerIt.next()); - } - else - conference.getCallPeers(callPeers); - return callPeers; - } - - /** * Adds the <tt>CallPeer</tt>s associated with the <tt>Call</tt>s * participating in this telephony conference into a specific <tt>List</tt>. * @@ -680,28 +620,6 @@ public class CallConference } /** - * Gets the list of <tt>Call</tt>s participating in the telephony conference - * in which a specific <tt>Call</tt> is participating. - * - * @param call the <tt>Call</tt> which participates in the telephony - * conference the list of participating <tt>Call</tt>s of which is to be - * returned - * @return the list of <tt>Call</tt>s participating in the telephony - * conference in which the specified <tt>call</tt> is participating - */ - public static List<Call> getCalls(Call call) - { - CallConference conference = call.getConference(); - List<Call> calls; - - if (conference == null) - calls = Collections.emptyList(); - else - calls = conference.getCalls(); - return calls; - } - - /** * Determines whether the local peer/user associated with this instance and * represented by the <tt>Call</tt>s participating into it is acting as a * conference focus. @@ -715,32 +633,6 @@ public class CallConference } /** - * Determines whether a <tt>CallConference</tt> is to report the local - * peer/user as a conference focus judging by a specific list of - * <tt>Call</tt>s. - * - * @param calls the list of <tt>Call</tt> which are to be judged whether - * the local peer/user that they represent is to be considered as a - * conference focus - * @return <tt>true</tt> if the local peer/user represented by the specified - * <tt>calls</tt> is judged to be a conference focus; otherwise, - * <tt>false</tt> - */ - private static boolean isConferenceFocus(List<Call> calls) - { - int callCount = calls.size(); - boolean conferenceFocus; - - if (callCount < 1) - conferenceFocus = false; - else if (callCount > 1) - conferenceFocus = true; - else - conferenceFocus = (calls.get(0).getCallPeerCount() > 1); - return conferenceFocus; - } - - /** * Determines whether the current state of this instance suggests that the * telephony conference it represents has ended. Iterates over the * <tt>Call</tt>s participating in this telephony conference and looks for a @@ -808,6 +700,92 @@ public class CallConference } /** + * Notifies this telephony conference about a specific + * <tt>CallPeerEvent</tt> i.e. that a <tt>CallPeer</tt> was either added to + * or removed from a <tt>Call</tt>. + * + * @param ev a <tt>CallPeerEvent</tt> which specifies the <tt>CallPeer</tt> + * which was added or removed and the <tt>Call</tt> to which it was added or + * from which is was removed + */ + private void onCallPeerEvent(CallPeerEvent ev) + { + Call call = ev.getSourceCall(); + + if (containsCall(call)) + { + /* + * Update the conferenceFocus state. Following the line of thinking + * expressed in the callAdded and callRemoved methods, only update + * it if the new conferenceFocus value is in accord with the + * expectations. + */ + int eventID = ev.getEventID(); + boolean conferenceFocus = isConferenceFocus(getCalls()); + + switch (eventID) + { + case CallPeerEvent.CALL_PEER_ADDED: + if (conferenceFocus) + setConferenceFocus(conferenceFocus); + break; + case CallPeerEvent.CALL_PEER_REMOVED: + if (!conferenceFocus) + setConferenceFocus(conferenceFocus); + break; + default: + /* + * We're interested in the adding and removing of CallPeers + * only. + */ + break; + } + + try + { + // Forward the CallPeerEvent to the callChangeListeners. + for (CallChangeListener l : getCallChangeListeners()) + { + switch (eventID) + { + case CallPeerEvent.CALL_PEER_ADDED: + l.callPeerAdded(ev); + break; + case CallPeerEvent.CALL_PEER_REMOVED: + l.callPeerRemoved(ev); + break; + default: + break; + } + } + } + finally + { + /* + * Add/remove the callPeerConferenceListener to/from the source + * CallPeer (for the purposes of the + * addCallPeerConferenceListener method of this CallConference). + */ + CallPeer callPeer = ev.getSourceCallPeer(); + + switch (eventID) + { + case CallPeerEvent.CALL_PEER_ADDED: + callPeer.addCallPeerConferenceListener( + callPeerConferenceListener); + break; + case CallPeerEvent.CALL_PEER_REMOVED: + callPeer.removeCallPeerConferenceListener( + callPeerConferenceListener); + break; + default: + break; + } + } + } + } + + /** * Removes a specific <tt>Call</tt> from the list of <tt>Call</tt>s * participating in this telephony conference. * |