- process user left message

This commit is contained in:
Richard Alam 2015-05-20 16:04:20 -07:00
parent aa92b572b3
commit 9d437302f3
4 changed files with 582 additions and 3 deletions

View File

@ -0,0 +1,105 @@
package org.bigbluebutton.conference.service.messaging;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class UserLeftMessage implements IMessage {
public static final String USER_LEFT = "user_left_message";
public final String VERSION = "0.0.1";
public final String meetingId;
public final Map<String, Object> user;
public UserLeftMessage(String meetingID, Map<String, Object> user) {
this.meetingId = meetingID;
this.user = user;
}
public String toJson() {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.MEETING_ID, meetingId);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(USER_LEFT, VERSION, null);
return MessageBuilder.buildJson(header, payload);
}
public static UserLeftMessage fromJson(String message) {
JsonParser parser = new JsonParser();
JsonObject obj = (JsonObject) parser.parse(message);
if (obj.has("header") && obj.has("payload")) {
JsonObject header = (JsonObject) obj.get("header");
JsonObject payload = (JsonObject) obj.get("payload");
if (header.has("name")) {
String messageName = header.get("name").getAsString();
if (USER_LEFT.equals(messageName)) {
if (payload.has(Constants.MEETING_ID)
&& payload.has(Constants.USER)) {
String meetingID = payload.get(Constants.MEETING_ID).getAsString();
JsonObject user = (JsonObject) payload.get(Constants.USER);
if (user.has(Constants.USER_ID) &&
user.has("voiceUser")) {
Map<String, Object> userMap = new HashMap<String, Object>();
Map<String, Object> vuMap = new HashMap<String, Object>();
String userid = user.get(Constants.USER_ID).getAsString();
String username = user.get(Constants.NAME).getAsString();
Boolean hasStream = user.get("has_stream").getAsBoolean();
Boolean listenOnly = user.get("listenOnly").getAsBoolean();
Boolean raiseHand = user.get("raise_hand").getAsBoolean();
Boolean phoneUser = user.get("phone_user").getAsBoolean();
Boolean presenter = user.get("presenter").getAsBoolean();
Boolean locked = user.get("locked").getAsBoolean();
String extUserId = user.get("extern_userid").getAsString();
String role = user.get("role").getAsString();
userMap.put("userid", userid);
userMap.put("name", username);
userMap.put("listenOnly", listenOnly);
userMap.put("has_stream", hasStream);
userMap.put("raise_hand", raiseHand);
userMap.put("extern_userid", extUserId);
userMap.put("phone_user", phoneUser);
userMap.put("locked", locked);
userMap.put("role", role);
userMap.put("presenter", presenter);
JsonObject vu = (JsonObject) user.get("voiceUser");
Boolean talking = vu.get("talking").getAsBoolean();
Boolean voiceLocked = vu.get("locked").getAsBoolean();
Boolean muted = vu.get("muted").getAsBoolean();
Boolean joined = vu.get("joined").getAsBoolean();
String callername = vu.get("callername").getAsString();
String callernum = vu.get("callernum").getAsString();
String webUserId = vu.get("web_userid").getAsString();
String voiceUserId = vu.get("userid").getAsString();
vuMap.put("talking", talking);
vuMap.put("locked", voiceLocked);
vuMap.put("muted", muted);
vuMap.put("joined", joined);
vuMap.put("callername", callername);
vuMap.put("callernum", callernum);
vuMap.put("web_userid", webUserId);
vuMap.put("userid", voiceUserId);
userMap.put("voiceUser", vuMap);
return new UserLeftMessage(meetingID, userMap);
}
}
}
}
}
System.out.println("Failed to parse RegisterUserMessage");
return null;
}
}

View File

@ -0,0 +1,450 @@
package org.bigbluebutton.red5.client;
import java.util.HashMap;
import java.util.Map;
public class UserClientMessageSender {
/*
private Map<String, Object> buildPermissionsHashMap(Permissions perms) {
Map<String, Boolean> args = new HashMap<String, Boolean>();
args.put("disableCam", perms.disableCam);
args.put("disableMic", perms.disableMic);
args.put("disablePrivChat", perms.disablePrivChat);
args.put("disablePubChat", perms.disablePubChat);
args.put("lockedLayout", perms.lockedLayout);
args.put("lockOnJoin", perms.lockOnJoin);
args.put("lockOnJoinConfigurable", perms.lockOnJoinConfigurable);
return args;
}
private Map<String, Object> buildUserHashMap(Map<String, Object> msg) {
Map<String, Object> vuser = new HashMap<String, Object>();
vuser.put("userId", vu.userId);
vuser.put("webUserId", vu.webUserId);
vuser.put("callerName", vu.callerName);
vuser.put("callerNum", vu.callerNum);
vuser.put("joined", vu.joined);
vuser.put("locked", vu.locked);
vuser.put("muted", vu.muted);
vuser.put("talking", vu.talking);
Map<String, Object> wuser = new HashMap<String, Object>();
wuser.put("userId", user.userID);
wuser.put("externUserID", user.externUserID);
wuser.put("name", user.name);
wuser.put("role", user.role.toString());
wuser.put("raiseHand", user.raiseHand);
wuser.put("presenter", user.presenter);
wuser.put("hasStream", user.hasStream);
wuser.put("locked", user.locked);
wuser.put("webcamStream", user.webcamStreams mkString("|"));
wuser.put("phoneUser", user.phoneUser);
wuser.put("voiceUser", vuser);
wuser.put("listenOnly", user.listenOnly);
return wuser;
}
*/
/*
private def handleNewPermissionsSetting(msg: NewPermissionsSetting) {
val args = new java.util.HashMap[String, Object]();
args.put("disableCam", msg.permissions.disableCam:java.lang.Boolean);
args.put("disableMic", msg.permissions.disableMic:java.lang.Boolean);
args.put("disablePrivChat", msg.permissions.disablePrivChat:java.lang.Boolean);
args.put("disablePubChat", msg.permissions.disablePubChat:java.lang.Boolean);
args.put("lockedLayout", msg.permissions.lockedLayout:java.lang.Boolean);
args.put("lockOnJoin", msg.permissions.lockOnJoin:java.lang.Boolean);
args.put("lockOnJoinConfigurable", msg.permissions.lockOnJoinConfigurable:java.lang.Boolean);
var users = new ArrayList[java.util.HashMap[String, Object]];
msg.applyTo.foreach(uvo => {
users.add(buildUserHashMap(uvo))
})
args.put("users", users);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleNewPermissionsSetting \n" + message.get("msg") + "\n")
val m = new BroadcastClientMessage(msg.meetingID, "permissionsSettingsChanged", message);
service.sendMessage(m);
}
private def handleUserLocked(msg: UserLocked) {
val args = new java.util.HashMap[String, Object]();
args.put("meetingID", msg.meetingID);
args.put("user", msg.userId)
args.put("lock", msg.lock:java.lang.Boolean)
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
val m = new BroadcastClientMessage(msg.meetingID, "userLocked", message);
service.sendMessage(m);
}
private def handleRegisteredUser(msg: UserRegistered) {
val args = new java.util.HashMap[String, Object]();
args.put("userId", msg.user.id);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleRegisteredUser \n" + message.get("msg") + "\n")
}
private def handleValidateAuthTokenTimedOut(msg: ValidateAuthTokenTimedOut) {
val args = new java.util.HashMap[String, Object]();
args.put("userId", msg.requesterId);
args.put("valid", msg.valid:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
println("UsersClientMessageSender - handleValidateAuthTokenTimedOut \n" + message.get("msg") + "\n")
val m = new DirectClientMessage(msg.meetingID, msg.requesterId, "validateAuthTokenTimedOut", message);
service.sendMessage(m);
}
private def handleValidateAuthTokenReply(msg: ValidateAuthTokenReply) {
val args = new java.util.HashMap[String, Object]();
args.put("userId", msg.requesterId);
args.put("valid", msg.valid:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleValidateAuthTokenReply \n" + message.get("msg") + "\n")
// val m = new DirectClientMessage(msg.meetingID, msg.requesterId, "validateAuthTokenReply", message);
// service.sendMessage(m);
}
private def handleGetRecordingStatusReply(msg: GetRecordingStatusReply) {
val args = new java.util.HashMap[String, Object]();
args.put("userId", msg.userId);
args.put("recording", msg.recording:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleGetRecordingStatusReply \n" + message.get("msg") + "\n")
val m = new DirectClientMessage(msg.meetingID, msg.userId, "getRecordingStatusReply", message);
service.sendMessage(m);
}
private def handleRecordingStatusChanged(msg: RecordingStatusChanged) {
val args = new java.util.HashMap[String, Object]();
args.put("userId", msg.userId);
args.put("recording", msg.recording:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleRecordingStatusChanged \n" + message.get("msg") + "\n")
val m = new BroadcastClientMessage(msg.meetingID, "recordingStatusChanged", message);
service.sendMessage(m);
}
private def handleUserVoiceMuted(msg: UserVoiceMuted) {
val args = new java.util.HashMap[String, Object]();
args.put("meetingID", msg.meetingID);
args.put("userId", msg.user.userID);
args.put("voiceUserId", msg.user.voiceUser.userId);
args.put("muted", msg.user.voiceUser.muted:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserVoiceMuted \n" + message.get("msg") + "\n")
// log.debug("UsersClientMessageSender - handlePresentationConversionProgress \n" + message.get("msg") + "\n")
val m = new BroadcastClientMessage(msg.meetingID, "voiceUserMuted", message);
service.sendMessage(m);
}
private def handleUserVoiceTalking(msg: UserVoiceTalking) {
val args = new java.util.HashMap[String, Object]();
args.put("meetingID", msg.meetingID);
args.put("userId", msg.user.userID);
args.put("voiceUserId", msg.user.voiceUser.userId);
args.put("talking", msg.user.voiceUser.talking:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserVoiceTalking \n" + message.get("msg") + "\n")
// log.debug("UsersClientMessageSender - handlePresentationConversionProgress \n" + message.get("msg") + "\n")
val m = new BroadcastClientMessage(msg.meetingID, "voiceUserTalking", message);
service.sendMessage(m);
}
private def handleUserLeftVoice(msg: UserLeftVoice) {
val args = new java.util.HashMap[String, Object]();
args.put("meetingID", msg.meetingID);
args.put("user", buildUserHashMap(msg.user))
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserLeftVoice \n" + message.get("msg") + "\n")
// log.debug("UsersClientMessageSender - handleUserLeftVoice \n" + message.get("msg") + "\n")
val m = new BroadcastClientMessage(msg.meetingID, "userLeftVoice", message);
service.sendMessage(m);
}
private def handleUserJoinedVoice(msg: UserJoinedVoice) {
val args = new java.util.HashMap[String, Object]();
args.put("meetingID", msg.meetingID);
args.put("user", buildUserHashMap(msg.user))
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserJoinedVoice \n" + message.get("msg") + "\n")
// log.debug("UsersClientMessageSender - handlePresentationConversionProgress \n" + message.get("msg") + "\n")
val m = new BroadcastClientMessage(msg.meetingID, "userJoinedVoice", message);
service.sendMessage(m);
}
private def handleGetUsersReply(msg: GetUsersReply):Unit = {
var args = new HashMap[String, Object]();
args.put("count", msg.users.length:java.lang.Integer)
var users = new ArrayList[java.util.HashMap[String, Object]];
msg.users.foreach(uvo => {
users.add(buildUserHashMap(uvo))
})
args.put("users", users);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson()
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleGetUsersReply \n" + message.get("msg") + "\n")
var m = new DirectClientMessage(msg.meetingID, msg.requesterID, "getUsersReply", message)
service.sendMessage(m)
}
private def handleMeetingHasEnded(msg: MeetingHasEnded):Unit = {
var args = new HashMap[String, Object]();
args.put("status", "Meeting has already ended.");
var message = new HashMap[String, Object]();
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleMeetingHasEnded \n" + message.get("msg") + "\n")
var m = new DirectClientMessage(msg.meetingID, msg.userId, "meetingHasEnded", message)
service.sendMessage(m);
}
private def handleDisconnectUser(msg: DisconnectUser) {
// println("UsersClientMessageSender - handleDisconnectUser mid=[" + msg.meetingID + "], uid=[" + msg.userId + "]\n")
var m = new DisconnectClientMessage(msg.meetingID, msg.userId)
service.sendMessage(m);
}
private def handleMeetingState(msg: MeetingState) {
var args = new HashMap[String, Object]();
args.put("permissions", buildPermissionsHashMap(msg.permissions));
args.put("meetingMuted", msg.meetingMuted:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
var jmr = new DirectClientMessage(msg.meetingID, msg.userId, "meetingState", message);
service.sendMessage(jmr);
}
private def handleMeetingMuted(msg: MeetingMuted) {
var args = new HashMap[String, Object]();
args.put("meetingMuted", msg.meetingMuted:java.lang.Boolean);
var message = new HashMap[String, Object]();
val gson = new Gson();
message.put("msg", gson.toJson(args))
var m = new BroadcastClientMessage(msg.meetingID, "meetingMuted", message);
service.sendMessage(m);
}
private def handleMeetingEnded(msg: MeetingEnded):Unit = {
var args = new HashMap[String, Object]();
args.put("status", "Meeting has been ended.");
var message = new HashMap[String, Object]();
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleMeetingEnded \n" + msg.meetingID + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "meetingEnded", message);
service.sendMessage(m);
}
private def handleDisconnectAllUsers(msg: DisconnectAllUsers) {
var dm = new DisconnectAllClientsMessage(msg.meetingID)
service.sendMessage(dm)
}
private def handleAssignPresenter(msg:PresenterAssigned):Unit = {
var args = new HashMap[String, Object]();
args.put("newPresenterID", msg.presenter.presenterID);
args.put("newPresenterName", msg.presenter.presenterName);
args.put("assignedBy", msg.presenter.assignedBy);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleAssignPresenter \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "assignPresenterCallback", message);
service.sendMessage(m);
}
private def handleUserJoined(msg: UserJoined):Unit = {
var args = new HashMap[String, Object]();
args.put("user", buildUserHashMap(msg.user));
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - joinMeetingReply \n" + message.get("msg") + "\n")
var jmr = new DirectClientMessage(msg.meetingID, msg.user.userID, "joinMeetingReply", message);
service.sendMessage(jmr);
// println("UsersClientMessageSender - handleUserJoined \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "participantJoined", message);
service.sendMessage(m);
}
private def handleUserLeft(msg: UserLeft):Unit = {
var args = new HashMap[String, Object]();
args.put("user", buildUserHashMap(msg.user));
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserLeft \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "participantLeft", message);
service.sendMessage(m);
}
def handleUserRaisedHand(msg: UserRaisedHand) {
var args = new HashMap[String, Object]()
args.put("userId", msg.userID)
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserRaisedHand \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "userRaisedHand", message);
service.sendMessage(m);
}
def handleUserLoweredHand(msg: UserLoweredHand) {
var args = new HashMap[String, Object]();
args.put("userId", msg.userID)
args.put("loweredBy", msg.loweredBy)
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserLoweredHand \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "userLoweredHand", message);
service.sendMessage(m);
}
def handleUserSharedWebcam(msg: UserSharedWebcam) {
var args = new HashMap[String, Object]()
args.put("userId", msg.userID)
args.put("webcamStream", msg.stream)
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserSharedWebcam \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "userSharedWebcam", message);
service.sendMessage(m);
}
def handleUserUnshareWebcam(msg: UserUnsharedWebcam) {
var args = new HashMap[String, Object]()
args.put("userId", msg.userID)
args.put("webcamStream", msg.stream)
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserUnshareWebcam \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "userUnsharedWebcam", message);
service.sendMessage(m);
}
private def handleUserStatusChange(msg: UserStatusChange):Unit = {
var args = new HashMap[String, Object]();
args.put("userID", msg.userID);
args.put("status", msg.status);
args.put("value", msg.value);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserStatusChange \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "participantStatusChange", message);
service.sendMessage(m);
}
private def handleUserListeningOnly(msg: UserListeningOnly) {
var args = new HashMap[String, Object]();
args.put("userId", msg.userID);
args.put("listenOnly", msg.listenOnly:java.lang.Boolean);
val message = new java.util.HashMap[String, Object]()
val gson = new Gson();
message.put("msg", gson.toJson(args))
// println("UsersClientMessageSender - handleUserListeningOnly \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "user_listening_only", message);
service.sendMessage(m);
}
*/
}

View File

@ -3,6 +3,7 @@ package org.bigbluebutton.red5.pubsub.redis;
import java.util.HashMap;
import java.util.Map;
import org.bigbluebutton.conference.meeting.messaging.red5.BroadcastClientMessage;
import org.bigbluebutton.conference.meeting.messaging.red5.ConnectionInvokerService;
import org.bigbluebutton.conference.meeting.messaging.red5.DirectClientMessage;
import org.bigbluebutton.conference.service.messaging.CreateMeetingMessage;
@ -14,6 +15,7 @@ import org.bigbluebutton.conference.service.messaging.MessagingConstants;
import org.bigbluebutton.conference.service.messaging.RegisterUserMessage;
import org.bigbluebutton.conference.service.messaging.UserConnectedToGlobalAudio;
import org.bigbluebutton.conference.service.messaging.UserDisconnectedFromGlobalAudio;
import org.bigbluebutton.conference.service.messaging.UserLeftMessage;
import org.bigbluebutton.conference.service.messaging.ValidateAuthTokenMessage;
import org.bigbluebutton.conference.service.messaging.ValidateAuthTokenReplyMessage;
@ -69,7 +71,15 @@ public class RedisPubSubMessageHandler implements MessageHandler {
switch (messageName) {
case ValidateAuthTokenReplyMessage.VALIDATE_AUTH_TOKEN_REPLY:
ValidateAuthTokenReplyMessage m = ValidateAuthTokenReplyMessage.fromJson(message);
processValidateAuthTokenReply(m);
if (m != null) {
processValidateAuthTokenReply(m);
}
case UserLeftMessage.USER_LEFT:
UserLeftMessage ulm = UserLeftMessage.fromJson(message);
if (ulm != null) {
processUserLeftMessage(ulm);
}
}
}
}
@ -94,4 +104,18 @@ public class RedisPubSubMessageHandler implements MessageHandler {
service.sendMessage(m);
}
private void processUserLeftMessage(UserLeftMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("user", msg.user);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
System.out.println("RedisPubSubMessageHandler - handleUserLeft \n" + message.get("msg") + "\n");
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "participantLeft", message);
service.sendMessage(m);
}
}

View File

@ -398,8 +398,8 @@ class UsersClientMessageSender(service: ConnectionInvokerService) extends OutMes
// println("UsersClientMessageSender - handleUserLeft \n" + message.get("msg") + "\n")
var m = new BroadcastClientMessage(msg.meetingID, "participantLeft", message);
service.sendMessage(m);
// var m = new BroadcastClientMessage(msg.meetingID, "participantLeft", message);
// service.sendMessage(m);
}
def handleUserRaisedHand(msg: UserRaisedHand) {