Merge pull request #728 from ritzalam/keep-track-of-user-connections
- keep track of user's number of connections to red5 to manage auto-…
This commit is contained in:
commit
1d3faae800
@ -302,7 +302,7 @@ trait UsersApp {
|
||||
outGW.send(new MeetingState(mProps.meetingID, mProps.recorded, uvo.userID, meetingModel.getPermissions(), meetingModel.isMeetingMuted()))
|
||||
|
||||
// Become presenter if the only moderator
|
||||
if (usersModel.numModerators == 1) {
|
||||
if ((usersModel.numModerators == 1) || (usersModel.noPresenter())) {
|
||||
if (ru.role == Role.MODERATOR) {
|
||||
assignNewPresenter(msg.userID, ru.name, msg.userID)
|
||||
}
|
||||
|
@ -96,6 +96,10 @@ class UsersModel {
|
||||
uservos.values find (u => u.role == MODERATOR)
|
||||
}
|
||||
|
||||
def noPresenter(): Boolean = {
|
||||
!getCurrentPresenter().isDefined
|
||||
}
|
||||
|
||||
def getCurrentPresenter(): Option[UserVO] = {
|
||||
uservos.values find (u => u.presenter == true)
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ public class BigBlueButtonApplication extends MultiThreadedApplicationAdapter {
|
||||
private ConnectionInvokerService connInvokerService;
|
||||
private MessagePublisher red5InGW;
|
||||
|
||||
private final UserConnectionMapper userConnections = new UserConnectionMapper();
|
||||
|
||||
private final String APP = "BBB";
|
||||
private final String CONN = "RED5-";
|
||||
|
||||
@ -166,6 +168,8 @@ public class BigBlueButtonApplication extends MultiThreadedApplicationAdapter {
|
||||
|
||||
log.info("User joining bbb-apps: data={}", logStr);
|
||||
|
||||
userConnections.addUserConnection(userId, connId);
|
||||
|
||||
return super.roomConnect(connection, params);
|
||||
|
||||
}
|
||||
@ -214,10 +218,15 @@ public class BigBlueButtonApplication extends MultiThreadedApplicationAdapter {
|
||||
Gson gson = new Gson();
|
||||
String logStr = gson.toJson(logData);
|
||||
|
||||
log.info("User leaving bbb-apps: data={}", logStr);
|
||||
|
||||
red5InGW.userLeft(bbbSession.getRoom(), getBbbSession().getInternalUserID(), sessionId);
|
||||
|
||||
boolean removeUser = userConnections.userDisconnected(userId, connId);
|
||||
|
||||
if (removeUser) {
|
||||
log.info("User leaving bbb-apps: data={}", logStr);
|
||||
red5InGW.userLeft(bbbSession.getRoom(), getBbbSession().getInternalUserID(), sessionId);
|
||||
} else {
|
||||
log.info("User not leaving bbb-apps but just disconnected: data={}", logStr);
|
||||
}
|
||||
|
||||
super.roomDisconnect(conn);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,70 @@
|
||||
package org.bigbluebutton.red5;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* This class maintains the connections mapping of a user.
|
||||
* This tracks the connections for a user to manage auto-reconnects.
|
||||
* @author ralam
|
||||
*
|
||||
*/
|
||||
public class UserConnectionMapper {
|
||||
|
||||
private ConcurrentMap<String, UserConnection> users = new ConcurrentHashMap<String, UserConnection>(8, 0.9f, 1);;
|
||||
|
||||
/**
|
||||
* Adds a connection for a user.
|
||||
* @param userId
|
||||
* @param connId
|
||||
*/
|
||||
public synchronized void addUserConnection(String userId, String connId) {
|
||||
if (users.containsKey(userId)) {
|
||||
UserConnection user = users.get(userId);
|
||||
user.add(connId);
|
||||
} else {
|
||||
UserConnection user = new UserConnection();
|
||||
user.add(connId);
|
||||
users.put(userId, user);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed a connection for a user. Returns true if the user doesn't have any
|
||||
* connection left and thus can be removed.
|
||||
* @param userId
|
||||
* @param connId
|
||||
* @return boolean - no more connections
|
||||
*/
|
||||
public synchronized boolean userDisconnected(String userId, String connId) {
|
||||
if (users.containsKey(userId)) {
|
||||
UserConnection user = users.get(userId);
|
||||
user.remove(connId);
|
||||
if (user.isEmpty()) {
|
||||
users.remove(userId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private class UserConnection {
|
||||
private final Set<String> connections = new HashSet<String>();
|
||||
|
||||
public void add(String connId) {
|
||||
connections.add(connId);
|
||||
}
|
||||
|
||||
public void remove(String connId) {
|
||||
connections.remove(connId);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return connections.isEmpty();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user