Skip to content

Commit

Permalink
first try and adding caption ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
capilkey committed Dec 9, 2015
1 parent 0990c2c commit 71f8ff0
Show file tree
Hide file tree
Showing 31 changed files with 510 additions and 138 deletions.
Expand Up @@ -113,5 +113,6 @@ void lockLayout(String meetingID, String setById,

// Caption
void sendCaptionHistory(String meetingID, String requesterID);
void editCaptionHistory(String meetingID, Integer startIndex, Integer endIndex, String locale, String text);
void updateCaptionOwner(String meetingID, String locale, String ownerID);
void editCaptionHistory(String meetingID, String userID, Integer startIndex, Integer endIndex, String locale, String text);
}
Expand Up @@ -3,6 +3,7 @@
import org.bigbluebutton.common.messages.MessagingConstants;
import org.bigbluebutton.common.messages.EditCaptionHistoryMessage;
import org.bigbluebutton.common.messages.SendCaptionHistoryRequestMessage;
import org.bigbluebutton.common.messages.UpdateCaptionOwnerMessage;

import com.google.gson.JsonParser;
import com.google.gson.JsonObject;
Expand All @@ -26,13 +27,16 @@ public void handleMessage(String pattern, String channel, String message) {
JsonObject header = (JsonObject) obj.get("header");
if (header.has("name")) {
String messageName = header.get("name").getAsString();
if (EditCaptionHistoryMessage.EDIT_CAPTION_HISTORY.equals(messageName)) {
EditCaptionHistoryMessage msg = EditCaptionHistoryMessage.fromJson(message);
bbbGW.editCaptionHistory(msg.meetingID, msg.startIndex, msg.endIndex, msg.locale, msg.text);
} else if (SendCaptionHistoryRequestMessage.SEND_CAPTION_HISTORY_REQUEST.equals(messageName)){
if (SendCaptionHistoryRequestMessage.SEND_CAPTION_HISTORY_REQUEST.equals(messageName)){
SendCaptionHistoryRequestMessage msg = SendCaptionHistoryRequestMessage.fromJson(message);
bbbGW.sendCaptionHistory(msg.meetingID, msg.requesterID);
}
} else if (UpdateCaptionOwnerMessage.UPDATE_CAPTION_OWNER.equals(messageName)) {
UpdateCaptionOwnerMessage msg = UpdateCaptionOwnerMessage.fromJson(message);
bbbGW.updateCaptionOwner(msg.meetingID, msg.locale, msg.ownerID);
} else if (EditCaptionHistoryMessage.EDIT_CAPTION_HISTORY.equals(messageName)) {
EditCaptionHistoryMessage msg = EditCaptionHistoryMessage.fromJson(message);
bbbGW.editCaptionHistory(msg.meetingID, msg.userID, msg.startIndex, msg.endIndex, msg.locale, msg.text);
}
}
}
}
Expand Down
Expand Up @@ -480,7 +480,11 @@ class BigBlueButtonInGW(val system: ActorSystem, recorderApp: RecorderApplicatio
bbbActor ! new SendCaptionHistoryRequest(meetingID, requesterID)
}

def editCaptionHistory(meetingID: String, startIndex: Integer, endIndex: Integer, locale: String, text: String) {
bbbActor ! new EditCaptionHistoryRequest(meetingID, startIndex, endIndex, locale, text)
def updateCaptionOwner(meetingID: String, locale: String, ownerID: String) {
bbbActor ! new UpdateCaptionOwnerRequest(meetingID, locale, ownerID)
}

def editCaptionHistory(meetingID: String, userID: String, startIndex: Integer, endIndex: Integer, locale: String, text: String) {
bbbActor ! new EditCaptionHistoryRequest(meetingID, userID, startIndex, endIndex, locale, text)
}
}
Expand Up @@ -172,6 +172,8 @@ class MeetingActor(val mProps: MeetingProperties, val outGW: OutMessageGateway)
handleGetCurrentPollRequest(msg)
case msg: SendCaptionHistoryRequest =>
handleSendCaptionHistoryRequest(msg)
case msg: UpdateCaptionOwnerRequest =>
handleUpdateCaptionOwnerRequest(msg)
case msg: EditCaptionHistoryRequest =>
handleEditCaptionHistoryRequest(msg)

Expand Down
Expand Up @@ -114,6 +114,7 @@ class MessageSenderActor(val meetingId: String, val service: MessageSender)
case msg: WhiteboardEnabledEvent => handleWhiteboardEnabledEvent(msg)
case msg: IsWhiteboardEnabledReply => handleIsWhiteboardEnabledReply(msg)
case msg: SendCaptionHistoryReply => handleSendCaptionHistoryReply(msg)
case msg: UpdateCaptionOwnerReply => handleUpdateCaptionOwnerReply(msg)
case msg: EditCaptionHistoryReply => handleEditCaptionHistoryReply(msg)
case _ => // do nothing
}
Expand Down Expand Up @@ -653,6 +654,11 @@ class MessageSenderActor(val meetingId: String, val service: MessageSender)
service.send(MessagingConstants.FROM_CAPTION_CHANNEL, json)
}

private def handleUpdateCaptionOwnerReply(msg: UpdateCaptionOwnerReply) {
val json = CaptionMessageToJsonConverter.updateCaptionOwnerReplyToJson(msg)
service.send(MessagingConstants.FROM_CAPTION_CHANNEL, json)
}

private def handleEditCaptionHistoryReply(msg: EditCaptionHistoryReply) {
println("handleEditCaptionHistoryReply")
val json = CaptionMessageToJsonConverter.editCaptionHistoryReplyToJson(msg)
Expand Down
Expand Up @@ -118,4 +118,5 @@ case class GetAllMeetingsRequest(meetingID: String /** Not used. Just to satisfy

// Caption
case class SendCaptionHistoryRequest(meetingID: String, requesterID: String) extends InMessage
case class EditCaptionHistoryRequest(meetingID: String, startIndex: Integer, endIndex: Integer, locale: String, text: String) extends InMessage
case class UpdateCaptionOwnerRequest(meetingID: String, locale: String, ownerID: String) extends InMessage
case class EditCaptionHistoryRequest(meetingID: String, userID: String, startIndex: Integer, endIndex: Integer, locale: String, text: String) extends InMessage
Expand Up @@ -163,5 +163,6 @@ object MessageNames {
val USER_LISTEN_ONLY = "user_listening_only"
val GET_ALL_MEETINGS_REPLY = "get_all_meetings_reply_message"
val EDIT_CAPTION_HISTORY = "edit_caption_history_message"
val UPDATE_CAPTION_OWNER = "update_caption_owner_message"
val SEND_CAPTION_HISTORY_REPLY = "send_caption_history_reply_message"
}
Expand Up @@ -131,8 +131,9 @@ case class IsWhiteboardEnabledReply(meetingID: String, recorded: Boolean, reques
case class GetAllMeetingsReply(meetings: Array[MeetingInfo]) extends IOutMessage

// Chat
case class SendCaptionHistoryReply(meetingID: String, recorded: Boolean, requesterID: String, history: Map[String, String]) extends IOutMessage
case class EditCaptionHistoryReply(meetingID: String, recorded: Boolean, startIndex: Integer, endIndex: Integer, locale: String, text: String) extends IOutMessage
case class SendCaptionHistoryReply(meetingID: String, recorded: Boolean, requesterID: String, history: Map[String, Array[String]]) extends IOutMessage
case class UpdateCaptionOwnerReply(meetingID: String, recorded: Boolean, locale: String, ownerID: String) extends IOutMessage
case class EditCaptionHistoryReply(meetingID: String, recorded: Boolean, userID: String, startIndex: Integer, endIndex: Integer, locale: String, text: String) extends IOutMessage

// Value Objects
case class MeetingVO(id: String, recorded: Boolean)
Expand Down
Expand Up @@ -15,20 +15,43 @@ trait CaptionApp {

outGW.send(new SendCaptionHistoryReply(mProps.meetingID, mProps.recorded, msg.requesterID, history))
}
/*
def handleUpdateCaptionInfo(msg: UpdateCaptionInfo) {

def handleUpdateCaptionOwnerRequest(msg: UpdateCaptionOwnerRequest) {
// clear owner from previous locale
if (msg.ownerID.length > 0) {
captionModel.findLocaleByOwnerId(msg.ownerID).foreach(t => {
captionModel.changeTranscriptOwner(t, "")

// send notification that owner has changed
outGW.send(new UpdateCaptionOwnerReply(mProps.meetingID, mProps.recorded, t, ""))
})
}
// create the locale if it doesn't exist
if (captionModel.transcripts contains msg.locale) {
captionModel.changeTranscriptOwner(msg.locale, msg.ownerID)
} else { // change the owner if it does exist
captionModel.newTranscript(msg.locale, msg.ownerID)
}

outGW.send(new UpdateCaptionOwnerReply(mProps.meetingID, mProps.recorded, msg.locale, msg.ownerID))
}
*/

def handleEditCaptionHistoryRequest(msg: EditCaptionHistoryRequest) {
captionModel.editHistory(msg.startIndex, msg.endIndex, msg.locale, msg.text)
captionModel.findLocaleByOwnerId(msg.userID).foreach(t => {
if (t == msg.locale) {
captionModel.editHistory(msg.startIndex, msg.endIndex, msg.locale, msg.text)

outGW.send(new EditCaptionHistoryReply(mProps.meetingID, mProps.recorded, msg.startIndex, msg.endIndex, msg.locale, msg.text))
outGW.send(new EditCaptionHistoryReply(mProps.meetingID, mProps.recorded, msg.userID, msg.startIndex, msg.endIndex, msg.locale, msg.text))
}
})
}

def checkCaptionOwnerLogOut(userId: String) {
//var transcript = findTranscriptByOwnerId(userId)
captionModel.findLocaleByOwnerId(userId).foreach(t => {
captionModel.changeTranscriptOwner(t, "")

//if (transcript
// send notification that owner has changed
outGW.send(new UpdateCaptionOwnerReply(mProps.meetingID, mProps.recorded, t, ""))
})
}
}
Expand Up @@ -4,44 +4,50 @@ import scala.collection.mutable.ArrayBuffer
import scala.collection.immutable.HashMap

class CaptionModel {
var transcripts = Map[String, String]()
var transcripts = Map[String, Array[String]]()

def newTranscript(locale: String, ownerId: String) {
// transcripts += locale -> Array(ownerId, "")
transcripts += locale -> Array(ownerId, "")
}
/*
def findLocaleByOwnerId(userId: String): Option[String] {
transcripts.foreach(t => {
if (t._2[0] == userId) {
return Some(t._1)
}

def findLocaleByOwnerId(userId: String): Option[String] = {
transcripts.find(_._2(0) == userId).foreach(t => {
return Some(t._1)
})
return None

return None
}
*/
def getHistory(): Map[String, String] = {
var history = Map[String, String]()

def changeTranscriptOwner(locale: String, ownerId: String) {
if (transcripts contains locale) {
transcripts(locale)(0) = ownerId
}
}

def getHistory(): Map[String, Array[String]] = {
var history = Map[String, Array[String]]()

transcripts.foreach(t => {
history += t._1 -> t._2
history += t._1 -> Array(t._2(0), t._2(1))
})

history
}

def editHistory(startIndex: Integer, endIndex: Integer, locale: String, text: String) {
println("editHistory entered")
if (transcripts contains locale) {
var oText: String = transcripts(locale)
println("editHistory found locale:" + locale)
var oText: String = transcripts(locale)(1)

if (startIndex >= 0 && endIndex < oText.length && startIndex <= endIndex) {
if (startIndex >= 0 && endIndex <= oText.length && startIndex <= endIndex) {
println("editHistory passed index test")
var sText: String = oText.substring(0, startIndex)
var eText: String = oText.substring(endIndex)

transcripts += locale -> (sText + text + eText)
transcripts(locale)(1) = (sText + text + eText)
println("editHistory new history is: " + transcripts(locale)(1))
}
} else {
transcripts += locale -> text
}
}
}
Expand Up @@ -19,9 +19,20 @@ object CaptionMessageToJsonConverter {
Util.buildJson(header, payload)
}

def updateCaptionOwnerReplyToJson(msg: UpdateCaptionOwnerReply): String = {
val payload = new java.util.HashMap[String, Any]()
payload.put(Constants.MEETING_ID, msg.meetingID)
payload.put(Constants.LOCALE, msg.locale)
payload.put(Constants.OWNER_ID, msg.ownerID)

val header = Util.buildHeader(MessageNames.UPDATE_CAPTION_OWNER, None)
Util.buildJson(header, payload)
}

def editCaptionHistoryReplyToJson(msg: EditCaptionHistoryReply): String = {
val payload = new java.util.HashMap[String, Any]()
payload.put(Constants.MEETING_ID, msg.meetingID)
payload.put(Constants.USER_ID, msg.userID)
payload.put(Constants.START_INDEX, msg.startIndex)
payload.put(Constants.END_INDEX, msg.endIndex)
payload.put(Constants.LOCALE, msg.locale)
Expand Down
Expand Up @@ -128,5 +128,6 @@ public class Constants {
public static final String END_INDEX = "end_index";
public static final String LOCALE = "locale";
public static final String TEXT = "text";
public static final String OWNER_ID = "owner_id";
public static final String CAPTION_HISTORY = "caption_history";
}
Expand Up @@ -10,24 +10,27 @@ public class EditCaptionHistoryMessage implements ISubscribedMessage {
public static final String VERSION = "0.0.1";

public final String meetingID;
public final String userID;
public final Integer startIndex;
public final Integer endIndex;
public final Integer endIndex;
public final String locale;
public final String text;

public EditCaptionHistoryMessage(String meetingID, Integer startIndex, Integer endIndex, String locale, String text) {
public EditCaptionHistoryMessage(String meetingID, String userID, Integer startIndex, Integer endIndex, String locale, String text) {
this.meetingID = meetingID;
this.userID = userID;
this.startIndex = startIndex;
this.endIndex = endIndex;
this.endIndex = endIndex;
this.locale = locale;
this.text = text;
}

public String toJson() {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.MEETING_ID, meetingID);
payload.put(Constants.MEETING_ID, meetingID);
payload.put(Constants.USER_ID, userID);
payload.put(Constants.START_INDEX, startIndex);
payload.put(Constants.END_INDEX, endIndex);
payload.put(Constants.END_INDEX, endIndex);
payload.put(Constants.LOCALE, locale);
payload.put(Constants.TEXT, text);

Expand All @@ -47,18 +50,20 @@ public static EditCaptionHistoryMessage fromJson(String message) {
if (header.has("name")) {
String messageName = header.get("name").getAsString();
if (EDIT_CAPTION_HISTORY.equals(messageName)) {
if (payload.has(Constants.MEETING_ID)
if (payload.has(Constants.MEETING_ID)
&& payload.has(Constants.USER_ID)
&& payload.has(Constants.START_INDEX)
&& payload.has(Constants.END_INDEX)
&& payload.has(Constants.END_INDEX)
&& payload.has(Constants.LOCALE)
&& payload.has(Constants.TEXT)) {
String meetingID = payload.get(Constants.MEETING_ID).getAsString();
String userID = payload.get(Constants.USER_ID).getAsString();
Integer startIndex = payload.get(Constants.START_INDEX).getAsInt();
Integer endIndex = payload.get(Constants.END_INDEX).getAsInt();
Integer endIndex = payload.get(Constants.END_INDEX).getAsInt();
String locale = payload.get(Constants.LOCALE).getAsString();
String text = payload.get(Constants.TEXT).getAsString();

return new EditCaptionHistoryMessage(meetingID, startIndex, endIndex, locale, text);
return new EditCaptionHistoryMessage(meetingID, userID, startIndex, endIndex, locale, text);
}
}
}
Expand Down
Expand Up @@ -14,9 +14,9 @@ public class SendCaptionHistoryReplyMessage implements ISubscribedMessage {

public final String meetingID;
public final String requesterID;
public final Map<String, String> captionHistory;
public final Map<String, String[]> captionHistory;

public SendCaptionHistoryReplyMessage(String meetingID, String requesterID, Map<String, String> captionHistory) {
public SendCaptionHistoryReplyMessage(String meetingID, String requesterID, Map<String, String[]> captionHistory) {
this.meetingID = meetingID;
this.captionHistory = captionHistory;
this.requesterID = requesterID;
Expand Down Expand Up @@ -52,7 +52,7 @@ public static SendCaptionHistoryReplyMessage fromJson(String message) {

Util util = new Util();

Map<String, String> captionHistory = util.extractCaptionHistory(history);
Map<String, String[]> captionHistory = util.extractCaptionHistory(history);

return new SendCaptionHistoryReplyMessage(meetingID, requesterID, captionHistory);
}
Expand Down
@@ -0,0 +1,59 @@
package org.bigbluebutton.common.messages;

import java.util.HashMap;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;


public class UpdateCaptionOwnerMessage implements ISubscribedMessage {
public static final String UPDATE_CAPTION_OWNER = "update_caption_owner_message";
public static final String VERSION = "0.0.1";

public final String meetingID;
public final String locale;
public final String ownerID;

public UpdateCaptionOwnerMessage(String meetingID, String locale, String ownerID) {
this.meetingID = meetingID;
this.locale = locale;
this.ownerID = ownerID;
}

public String toJson() {
HashMap<String, Object> payload = new HashMap<String, Object>();
payload.put(Constants.MEETING_ID, meetingID);
payload.put(Constants.LOCALE, locale);
payload.put(Constants.OWNER_ID, ownerID);

java.util.HashMap<String, Object> header = MessageBuilder.buildHeader(UPDATE_CAPTION_OWNER, VERSION, null);

return MessageBuilder.buildJson(header, payload);
}

public static UpdateCaptionOwnerMessage 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 (UPDATE_CAPTION_OWNER.equals(messageName)) {
if (payload.has(Constants.MEETING_ID)
&& payload.has(Constants.LOCALE)
&& payload.has(Constants.OWNER_ID)) {
String meetingID = payload.get(Constants.MEETING_ID).getAsString();
String locale = payload.get(Constants.LOCALE).getAsString();
String ownerID = payload.get(Constants.OWNER_ID).getAsString();

return new UpdateCaptionOwnerMessage(meetingID, locale, ownerID);
}
}
}
}
return null;

}
}

0 comments on commit 71f8ff0

Please sign in to comment.