From 9d670d948652a610eeee75ece6dd59821ce07860 Mon Sep 17 00:00:00 2001 From: Richard Alam Date: Tue, 9 Dec 2008 20:10:38 +0000 Subject: [PATCH] Fix issue where multiple notification are sent to the client if the user is muted/talking. git-svn-id: http://bigbluebutton.googlecode.com/svn/trunk@775 af16638f-c34d-0410-8cfa-b39d5352b314 --- .../asterisk/AsteriskVoiceService.java | 1 + .../asterisk/meetme/Application.java | 31 ++++--- .../meetme/ConferenceRoomListener.java | 80 +++++++++++++------ 3 files changed, 76 insertions(+), 36 deletions(-) diff --git a/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/AsteriskVoiceService.java b/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/AsteriskVoiceService.java index 2bd2588329..616a84743e 100644 --- a/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/AsteriskVoiceService.java +++ b/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/AsteriskVoiceService.java @@ -142,6 +142,7 @@ public class AsteriskVoiceService implements IVoiceService { * @see org.bigbluebuttonproject.asterisk.IVoiceService#addAsteriskServerListener(org.asteriskjava.live.AsteriskServerListener) */ public void addAsteriskServerListener(AsteriskServerListener listener) throws ManagerCommunicationException { + logger.info("Adding ConferenceRoomListener"); asteriskServer.addAsteriskServerListener(listener); } diff --git a/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/Application.java b/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/Application.java index 24c5cb07fc..dd3b36d20b 100644 --- a/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/Application.java +++ b/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/Application.java @@ -61,18 +61,19 @@ public class Application extends ApplicationAdapter implements /** The room listener. */ private ConferenceRoomListener roomListener; + private boolean listenerStarted = false; /** * @see org.red5.server.adapter.MultiThreadedApplicationAdapter#appStart(org.red5.server.api.IScope) */ @Override - public boolean appStart (IScope app ) + public boolean appStart(IScope app ) { super.appStart(app); log.info( "MeetMe::appStart - " ); appScope = app; - + //initialize(); return true; } @@ -81,9 +82,11 @@ public class Application extends ApplicationAdapter implements */ private void initialize() { - // roomListener = new ConferenceRoomListener(); try { - voiceService.addAsteriskServerListener(roomListener); + if (! listenerStarted) { + voiceService.addAsteriskServerListener(roomListener); + listenerStarted = true; + } } catch (ManagerCommunicationException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -106,13 +109,6 @@ public class Application extends ApplicationAdapter implements super.appConnect(conn, params); log.info( "MeetMe::appConnect - " + conn.getClient().getId() ); - -// initialize(); - -// boolean accept = ((Boolean)params[0]).booleanValue(); - -// if ( !accept ) rejectClient( "you passed false..." ); - return true; } @@ -129,10 +125,21 @@ public class Application extends ApplicationAdapter implements */ public boolean roomStart(IScope room) { log.info( "MeetMe::roomStart - " + room.getName() ); + if (!super.roomStart(room)) return false; - + initialize(); + + if (!hasSharedObject(room, "meetMeUsersSO")) { + createSharedObject(room, "meetMeUsersSO", false); + ISharedObject so = getSharedObject(room, "meetMeUsersSO", false); + roomListener.addRoom(room.getName(), so); + } else { + ISharedObject so = getSharedObject(room, "meetMeUsersSO", false); + } + + roomListener.initializeConferenceUsers(room.getName()); return true; } diff --git a/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/ConferenceRoomListener.java b/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/ConferenceRoomListener.java index 7cb92975d1..3c41e70e29 100644 --- a/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/ConferenceRoomListener.java +++ b/bigbluebutton-server/webapps/astmeetme/WEB-INF/src/org/bigbluebuttonproject/asterisk/meetme/ConferenceRoomListener.java @@ -27,10 +27,11 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.lang.Boolean; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import org.asteriskjava.live.ManagerCommunicationException; import org.asteriskjava.live.AbstractAsteriskServerListener; import org.asteriskjava.live.MeetMeUser; import org.asteriskjava.live.MeetMeUserState; @@ -68,6 +69,16 @@ public class ConferenceRoomListener extends AbstractAsteriskServerListener { log.debug("RoomListener started..."); } + private void initialize() + { + try { + voiceService.addAsteriskServerListener(this); + } catch (ManagerCommunicationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + /** * @see org.asteriskjava.live.AbstractAsteriskServerListener#onNewMeetMeUser(org.asteriskjava.live.MeetMeUser) */ @@ -133,10 +144,26 @@ public class ConferenceRoomListener extends AbstractAsteriskServerListener { return oneUser; } } - } - + } return null; } + + public void initializeConferenceUsers(String room) { + if (meetMeSOs.containsKey(room)) { + ISharedObject so = (ISharedObject) meetMeSOs.get(room); + + // Get the users in the room + Collection currentUsers = voiceService.getUsers(room); + + log.info("initializeConferenceUsers - There are " + currentUsers.size() + + " current users in room [" + room + "]"); + + for (Iterator it = currentUsers.iterator(); it.hasNext();) { + MeetMeUser oneUser = (MeetMeUser) it.next(); + oneUser.addPropertyChangeListener(new ParticipantPropertyChangeListener(so)); + } + } + } /** * Gets the current users. @@ -157,7 +184,7 @@ public class ConferenceRoomListener extends AbstractAsteriskServerListener { for (Iterator it = currentUsers.iterator(); it.hasNext();) { MeetMeUser oneUser = (MeetMeUser) it.next(); - oneUser.addPropertyChangeListener(new ParticipantPropertyChangeListener(so)); + //oneUser.addPropertyChangeListener(new ParticipantPropertyChangeListener(so)); } return currentUsers; @@ -194,6 +221,9 @@ public class ConferenceRoomListener extends AbstractAsteriskServerListener { */ private class ParticipantPropertyChangeListener implements PropertyChangeListener { + private Boolean talking = null; + private Boolean muted = null; + /** The so. */ private ISharedObject so; @@ -216,32 +246,34 @@ public class ConferenceRoomListener extends AbstractAsteriskServerListener { " old = '" + evt.getOldValue() + "' new = '" + evt.getNewValue() + "' room = '" + ((MeetMeUser) evt.getSource()).getRoom() + "'"); - log.info("New data mute = " + changedUser.isMuted()); - -// MeetMeUserVo userVo = new MeetMeUserVo(changedUser); -// -// List args1 = new ArrayList(); -// args1.add(userVo); -// so.sendMessage("newStatus", args1); - - if (evt.getPropertyName().equals("muted")) { - List args = new ArrayList(); - args.add(changedUser.getUserNumber()); - args.add(changedUser.isMuted()); - so.sendMessage("userMute", args); - - log.info("User mute event: [" + changedUser.getUserNumber() + if (evt.getPropertyName().equals("muted")) { + if ((muted == null) || (muted.booleanValue() != changedUser.isMuted())) { + List args = new ArrayList(); + args.add(changedUser.getUserNumber()); + log.info("User mute changed: [" + changedUser.getUserNumber() + + ",old=" + muted + ",new=" + changedUser.isMuted() + "]"); + muted = changedUser.isMuted(); + args.add(muted); + so.sendMessage("userMute", args); + } else { + log.info("User mute same: [" + changedUser.getUserNumber() + "," + changedUser.isMuted() + "]"); + } } else if (evt.getPropertyName().equals("talking")) { List args = new ArrayList(); args.add(changedUser.getUserNumber()); - args.add(changedUser.isTalking()); - so.sendMessage("userTalk", args); - - log.info("User talk event: [" + changedUser.getUserNumber() + if ((talking == null) || (talking.booleanValue() != changedUser.isTalking())) { + log.info("User talk changed: [" + changedUser.getUserNumber() + + ",old=" + talking + ",new="+ changedUser.isTalking() + "]"); + talking = changedUser.isTalking(); + args.add(talking); + so.sendMessage("userTalk", args); + } else { + log.info("User talk same: [" + changedUser.getUserNumber() + "," + changedUser.isTalking() + "]"); + } } else if ("state".equals(evt.getPropertyName())) { - log.info("User is changing state to [" + evt.getNewValue() + "]"); + log.info("User [" + changedUser.getUserNumber() + "," + evt.getNewValue() + "]"); List args = new ArrayList(); args.add(changedUser.getUserNumber());