- convert more voice messages

This commit is contained in:
Richard Alam 2015-05-25 15:04:13 +00:00
parent d52795f66b
commit 8ad21545b8
5 changed files with 263 additions and 51 deletions

View File

@ -0,0 +1,66 @@
package org.bigbluebutton.red5.pubsub.messages;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class UserLeftVoiceMessage implements IMessage {
public static final String USER_LEFT_VOICE = "user_left_voice_message";
public static final String VERSION = "0.0.1";
public final String meetingId;
public final Map<String, Object> user;
public final String voiceConf;
public UserLeftVoiceMessage(String meetingId, Map<String, Object> user, String voiceConf) {
this.meetingId = meetingId;
this.user = user;
this.voiceConf = voiceConf;
}
public String toJson() {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.MEETING_ID, meetingId);
payload.put(Constants.USER, user);
payload.put(Constants.VOICE_CONF, voiceConf);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(USER_LEFT_VOICE, VERSION, null);
return MessageBuilder.buildJson(header, payload);
}
public static UserLeftVoiceMessage 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_VOICE.equals(messageName)) {
if (payload.has(Constants.MEETING_ID)
&& payload.has(Constants.USER)) {
String id = payload.get(Constants.MEETING_ID).getAsString();
String voiceConf = payload.get(Constants.VOICE_CONF).getAsString();
JsonObject user = (JsonObject) payload.get(Constants.USER);
Util util = new Util();
Map<String, Object> userMap = util.extractUser(user);
if (userMap != null) {
return new UserLeftVoiceMessage(id, userMap, voiceConf);
}
}
}
}
}
return null;
}
}

View File

@ -0,0 +1,59 @@
package org.bigbluebutton.red5.pubsub.messages;
import java.util.HashMap;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class UserListeningOnlyMessage implements IMessage {
public static final String USER_LISTENING_ONLY = "user_listening_only";
public static final String VERSION = "0.0.1";
public final String meetingId;
public final String userId;
public final Boolean listenOnly;
public UserListeningOnlyMessage(String meetingId, String userId, Boolean listenOnly) {
this.meetingId = meetingId;
this.userId = userId;
this.listenOnly = listenOnly;
}
public String toJson() {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.MEETING_ID, meetingId);
payload.put(Constants.USER_ID, userId);
payload.put(Constants.LISTEN_ONLY, listenOnly);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(USER_LISTENING_ONLY, VERSION, null);
return MessageBuilder.buildJson(header, payload);
}
public static UserListeningOnlyMessage 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_LISTENING_ONLY.equals(messageName)) {
if (payload.has(Constants.MEETING_ID)
&& payload.has(Constants.USER_ID)
&& payload.has(Constants.LISTEN_ONLY)) {
String id = payload.get(Constants.MEETING_ID).getAsString();
String userid = payload.get(Constants.USER_ID).getAsString();
Boolean listenOnly = payload.get(Constants.LISTEN_ONLY).getAsBoolean();
return new UserListeningOnlyMessage(id, userid, listenOnly);
}
}
}
}
return null;
}
}

View File

@ -0,0 +1,66 @@
package org.bigbluebutton.red5.pubsub.messages;
import java.util.HashMap;
import java.util.Map;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
public class UserVoiceTalkingMessage implements IMessage {
public static final String USER_VOICE_TALKING = "user_voice_talking_message";
public static final String VERSION = "0.0.1";
public final String meetingId;
public final Map<String, Object> user;
public final String voiceConf;
public UserVoiceTalkingMessage(String meetingId, Map<String, Object> user, String voiceConf) {
this.meetingId = meetingId;
this.user = user;
this.voiceConf = voiceConf;
}
public String toJson() {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.MEETING_ID, meetingId);
payload.put(Constants.USER, user);
payload.put(Constants.VOICE_CONF, voiceConf);
java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(USER_VOICE_TALKING, VERSION, null);
return MessageBuilder.buildJson(header, payload);
}
public static UserVoiceTalkingMessage 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_VOICE_TALKING.equals(messageName)) {
if (payload.has(Constants.MEETING_ID)
&& payload.has(Constants.USER)) {
String id = payload.get(Constants.MEETING_ID).getAsString();
String voiceConf = payload.get(Constants.VOICE_CONF).getAsString();
JsonObject user = (JsonObject) payload.get(Constants.USER);
Util util = new Util();
Map<String, Object> userMap = util.extractUser(user);
if (userMap != null) {
return new UserVoiceTalkingMessage(id, userMap, voiceConf);
}
}
}
}
}
return null;
}
}

View File

@ -17,12 +17,15 @@ import org.bigbluebutton.red5.pubsub.messages.UserJoinedMessage;
import org.bigbluebutton.red5.pubsub.messages.UserJoinedVoiceMessage;
import org.bigbluebutton.red5.pubsub.messages.UserLeftMessage;
import org.bigbluebutton.red5.pubsub.messages.DisconnectUserMessage;
import org.bigbluebutton.red5.pubsub.messages.UserLeftVoiceMessage;
import org.bigbluebutton.red5.pubsub.messages.UserListeningOnlyMessage;
import org.bigbluebutton.red5.pubsub.messages.UserLoweredHandMessage;
import org.bigbluebutton.red5.pubsub.messages.UserRaisedHandMessage;
import org.bigbluebutton.red5.pubsub.messages.UserSharedWebcamMessage;
import org.bigbluebutton.red5.pubsub.messages.UserStatusChangedMessage;
import org.bigbluebutton.red5.pubsub.messages.UserUnsharedWebcamMessage;
import org.bigbluebutton.red5.pubsub.messages.UserVoiceMutedMessage;
import org.bigbluebutton.red5.pubsub.messages.UserVoiceTalkingMessage;
import org.bigbluebutton.red5.pubsub.messages.ValidateAuthTokenReplyMessage;
import org.bigbluebutton.red5.pubsub.messages.ValidateAuthTokenTimeoutMessage;
@ -153,6 +156,12 @@ public class RedisPubSubMessageHandler implements MessageHandler {
processUserRaisedHandMessage(urhm);
}
break;
case UserListeningOnlyMessage.USER_LISTENING_ONLY:
UserListeningOnlyMessage ulom = UserListeningOnlyMessage.fromJson(message);
if (ulom != null) {
processUserListeningOnlyMessage(ulom);
}
break;
case UserLoweredHandMessage.USER_LOWERED_HAND:
UserLoweredHandMessage ulhm = UserLoweredHandMessage.fromJson(message);
if (ulhm != null) {
@ -177,12 +186,24 @@ public class RedisPubSubMessageHandler implements MessageHandler {
processUserJoinedVoiceMessage(ujvm);
}
break;
case UserLeftVoiceMessage.USER_LEFT_VOICE:
UserLeftVoiceMessage ulvm = UserLeftVoiceMessage.fromJson(message);
if (ulvm != null) {
processUserLeftVoiceMessage(ulvm);
}
break;
case UserVoiceMutedMessage.USER_VOICE_MUTED:
UserVoiceMutedMessage uvmm = UserVoiceMutedMessage.fromJson(message);
if (uvmm != null) {
processUserVoiceMutedMessage(uvmm);
}
break;
case UserVoiceTalkingMessage.USER_VOICE_TALKING:
UserVoiceTalkingMessage uvtm = UserVoiceTalkingMessage.fromJson(message);
if (uvtm != null) {
processUserVoiceTalkingMessage(uvtm);
}
break;
}
}
}
@ -326,6 +347,21 @@ public class RedisPubSubMessageHandler implements MessageHandler {
service.sendMessage(m);
}
private void processUserListeningOnlyMessage(UserListeningOnlyMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("userId", msg.userId);
args.put("listenOnly", msg.listenOnly);
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
System.out.println("RedisPubSubMessageHandler - processUserListeningOnlyMessage \n" + message.get("msg") + "\n");
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "user_listening_only", message);
service.sendMessage(m);
}
private void processUserLoweredHandMessage(UserLoweredHandMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("userId", msg.userId);
@ -404,6 +440,21 @@ public class RedisPubSubMessageHandler implements MessageHandler {
service.sendMessage(m);
}
private void processUserLeftVoiceMessage(UserLeftVoiceMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("meetingID", msg.meetingId);
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 - processUserLeftVoiceMessage \n" + message.get("msg") + "\n");
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "userLeftVoice", message);
service.sendMessage(m);
}
private void processUserVoiceMutedMessage(UserVoiceMutedMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("meetingID", msg.meetingId);
@ -424,4 +475,25 @@ public class RedisPubSubMessageHandler implements MessageHandler {
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "voiceUserMuted", message);
service.sendMessage(m);
}
private void processUserVoiceTalkingMessage(UserVoiceTalkingMessage msg) {
Map<String, Object> args = new HashMap<String, Object>();
args.put("meetingID", msg.meetingId);
args.put("userId", msg.user.get("userId"));
Map<String, Object> vuMap = (Map<String, Object>) msg.user.get("voiceUser");
args.put("voiceUserId", (String) vuMap.get("userId"));
args.put("talking", (Boolean) vuMap.get("talking"));
Map<String, Object> message = new HashMap<String, Object>();
Gson gson = new Gson();
message.put("msg", gson.toJson(args));
System.out.println("RedisPubSubMessageHandler - processUserVoiceTalkingMessage \n" + message.get("msg") + "\n");
BroadcastClientMessage m = new BroadcastClientMessage(msg.meetingId, "voiceUserTalking", message);
service.sendMessage(m);
}
}

View File

@ -19,11 +19,8 @@ class UsersClientMessageSender(service: ConnectionInvokerService) extends OutMes
def handleMessage(msg: IOutMessage) {
msg match {
case msg: GetUsersReply => handleGetUsersReply(msg)
case msg: UserVoiceTalking => handleUserVoiceTalking(msg)
case msg: UserLeftVoice => handleUserLeftVoice(msg)
case msg: RecordingStatusChanged => handleRecordingStatusChanged(msg)
case msg: GetRecordingStatusReply => handleGetRecordingStatusReply(msg)
case msg: UserListeningOnly => handleUserListeningOnly(msg)
case msg: NewPermissionsSetting => handleNewPermissionsSetting(msg)
case msg: UserLocked => handleUserLocked(msg)
case msg: MeetingMuted => handleMeetingMuted(msg)
@ -143,39 +140,6 @@ class UsersClientMessageSender(service: ConnectionInvokerService) extends OutMes
}
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 handleGetUsersReply(msg: GetUsersReply):Unit = {
var args = new HashMap[String, Object]();
args.put("count", msg.users.length:java.lang.Integer)
@ -223,19 +187,4 @@ class UsersClientMessageSender(service: ConnectionInvokerService) extends OutMes
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);
}
}