Skip to content

Commit

Permalink
Added request breakout rooms list feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
GhaziTriki committed Jan 15, 2016
1 parent b24ae09 commit 058a217
Show file tree
Hide file tree
Showing 24 changed files with 392 additions and 82 deletions.
108 changes: 78 additions & 30 deletions akka-bbb-apps/scala/JsonTest.sc
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
import org.bigbluebutton.core.api._
import scala.util.{Try, Success, Failure}
import scala.util.{ Try, Success, Failure }
import org.bigbluebutton.core.JsonMessageDecoder
//import org.bigbluebutton.core.JsonMessageDecoder

import org.bigbluebutton.messages.BreakoutRoomsList
import org.bigbluebutton.messages.payload.BreakoutRoomsListPayload
import java.util.ArrayList
import org.bigbluebutton.core.messaging.Util
import org.bigbluebutton.messages.payload.BreakoutRoomPayload
import org.bigbluebutton.core.pubsub.senders.MeetingMessageToJsonConverter
import spray.json._
import DefaultJsonProtocol._
import com.google.gson.JsonArray
import scala.collection.mutable.ListBuffer

object JsonTest {
import org.bigbluebutton.core.UserMessagesProtocol._
import spray.json._

println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet

val xroom1 = new BreakoutRoomInPayload("foo", Vector("a", "b", "c"))
//> xroom1 : org.bigbluebutton.core.api.BreakoutRoomInPayload = BreakoutRoomInP
//| ayload(foo,Vector(a, b, c))
Expand All @@ -18,25 +27,23 @@ object JsonTest {
val xroom3 = new BreakoutRoomInPayload("baz", Vector("q", "r", "s"))
//> xroom3 : org.bigbluebutton.core.api.BreakoutRoomInPayload = BreakoutRoomInP
//| ayload(baz,Vector(q, r, s))


val xmsg = new CreateBreakoutRooms("test-meeting", 10, Vector(xroom1, xroom2, xroom3))
//> xmsg : org.bigbluebutton.core.api.CreateBreakoutRooms = CreateBreakoutRooms
//| (test-meeting,10,Vector(BreakoutRoomInPayload(foo,Vector(a, b, c)), Breakout
//| RoomInPayload(bar,Vector(x, y, z)), BreakoutRoomInPayload(baz,Vector(q, r, s
//| ))))

val xjsonAst = xmsg.toJson //> xjsonAst : spray.json.JsValue = {"meetingId":"test-meeting","durationInMinu
//| tes":10,"rooms":[{"name":"foo","users":["a","b","c"]},{"name":"bar","users":
//> xmsg : org.bigbluebutton.core.api.CreateBreakoutRooms = CreateBreakoutRoom
//| s(test-meeting,10,Vector(BreakoutRoomInPayload(foo,Vector(a, b, c)), Breako
//| utRoomInPayload(bar,Vector(x, y, z)), BreakoutRoomInPayload(baz,Vector(q, r
//| , s))))

val xjsonAst = xmsg.toJson //> xjsonAst : spray.json.JsValue = {"meetingId":"test-meeting","durationInMin
//| utes":10,"rooms":[{"name":"foo","users":["a","b","c"]},{"name":"bar","users
//| ":["x","y","z"]},{"name":"baz","users":["q","r","s"]}]}
val xjson = xjsonAst.asJsObject //> xjson : spray.json.JsObject = {"meetingId":"test-meeting","durationInMinut
//| es":10,"rooms":[{"name":"foo","users":["a","b","c"]},{"name":"bar","users":
//| ["x","y","z"]},{"name":"baz","users":["q","r","s"]}]}
val xjson = xjsonAst.asJsObject //> xjson : spray.json.JsObject = {"meetingId":"test-meeting","durationInMinute
//| s":10,"rooms":[{"name":"foo","users":["a","b","c"]},{"name":"bar","users":["
//| x","y","z"]},{"name":"baz","users":["q","r","s"]}]}
val meetingId = for {
meetingId <- xjson.fields.get("meetingId")
meetingId <- xjson.fields.get("meetingId")
} yield meetingId //> meetingId : Option[spray.json.JsValue] = Some("test-meeting")




val cbrm = """
{"header":{"name":"CreateBreakoutRoomsRequest"},"payload":{"meetingId":"abc123","rooms":[{"name":"room1","users":["Tidora","Nidora","Tinidora"]},{"name":"room2","users":["Jose","Wally","Paolo"]},{"name":"room3","users":["Alden","Yaya Dub"]}],"durationInMinutes":20}}
""" //> cbrm : String = "
Expand All @@ -45,27 +52,68 @@ object JsonTest {
//| ame":"room2","users":["Jose","Wally","Paolo"]},{"name":"room3","users":["Al
//| den","Yaya Dub"]}],"durationInMinutes":20}}
//| "

JsonMessageDecoder.decode(cbrm) //> res0: Option[org.bigbluebutton.core.api.InMessage] = Some(CreateBreakoutRoo
//| ms(abc123,20,Vector(BreakoutRoomInPayload(room1,Vector(Tidora, Nidora, Tini
//| dora)), BreakoutRoomInPayload(room2,Vector(Jose, Wally, Paolo)), BreakoutRo
//| omInPayload(room3,Vector(Alden, Yaya Dub)))))
val rbju = """
val rbju = """
{"header":{"name":"RequestBreakoutJoinURL"},"payload":{"userId":"id6pa5t8m1c9_1","meetingId":"183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452692983357","breakoutId":"183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452692983357-2"}}
""" //> rbju : String = "
//| {"header":{"name":"RequestBreakoutJoinURL"},"payload":{"userId":"id6pa5t8
//| m1c9_1","meetingId":"183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452692983357
//| ","breakoutId":"183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452692983357-2"}}
//|
//| "
JsonMessageDecoder.decode(rbju) //> res1: Option[org.bigbluebutton.core.api.InMessage] = Some(RequestBreakoutJo

JsonMessageDecoder.decode(rbju) //> res1: Option[org.bigbluebutton.core.api.InMessage] = Some(RequestBreakoutJo
//| inURLInMessage(183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452692983357,183f0
//| bf3a0982a127bdb8161e0c44eb696b3e75c-1452692983357-2,id6pa5t8m1c9_1))

// JsonMessageDecoder.unmarshall(cbrm) match {
// case Success(validMsg) => println(validMsg)
// case Failure(ex) => println("Unhandled message: [{}]")
// }


val brl = """
{"payload":{"meetingId":"183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452849036428","rooms":{"startIndex":0,"endIndex":0,"focus":0,"dirty":false,"depth":0}},"header":{"timestamp":33619724,"name":"BreakoutRoomsList","current_time":1452849043547,"version":"0.0.1"}}
""" //> brl : String = "
//| {"payload":{"meetingId":"183f0bf3a0982a127bdb8161e0c44eb696b3e75c-1452849
//| 036428","rooms":{"startIndex":0,"endIndex":0,"focus":0,"dirty":false,"depth
//| ":0}},"header":{"timestamp":33619724,"name":"BreakoutRoomsList","current_ti
//| me":1452849043547,"version":"0.0.1"}}
//| "

val brb = new BreakoutRoomBody("Breakout Room", "br-id-1");
//> brb : org.bigbluebutton.core.api.BreakoutRoomBody = BreakoutRoomBody(Break
//| out Room,br-id-1)

val jsObj = JsObject(
"name" -> JsString(brb.name),
"breakoutId" -> JsString(brb.breakoutId)) //> jsObj : spray.json.JsObject = {"name":"Breakout Room","breakoutId":"br-id-
//| 1"}

val vector = Vector(jsObj) //> vector : scala.collection.immutable.Vector[spray.json.JsObject] = Vector({
//| "name":"Breakout Room","breakoutId":"br-id-1"})

val brlum = new BreakoutRoomsListOutMessage("main-meeting-1", Vector(brb))
//> brlum : org.bigbluebutton.core.api.BreakoutRoomsListOutMessage = BreakoutR
//| oomsListOutMessage(main-meeting-1,Vector(BreakoutRoomBody(Breakout Room,br-
//| id-1)))
var roomsJsVector: ListBuffer[JsObject] = new ListBuffer[JsObject]()
//> roomsJsVector : scala.collection.mutable.ListBuffer[spray.json.JsObject] =
//| ListBuffer()
brlum.rooms.foreach { r =>
roomsJsVector.append(JsObject("name" -> JsString(r.name), "breakoutId" -> JsString(r.breakoutId)))
}

roomsJsVector.length //> res2: Int = 1
JsArray(roomsJsVector.toVector).toString() //> res3: String = [{"name":"Breakout Room","breakoutId":"br-id-1"}]

MeetingMessageToJsonConverter.breakoutRoomsListOutMessageToJson(brlum);
//> res4: String = {"payload":{"meetingId":"main-meeting-1","rooms":"[{\"name\"
//| :\"Breakout Room\",\"breakoutId\":\"br-id-1\"}]"},"header":{"timestamp":132
//| 888341,"name":"BreakoutRoomsList","current_time":1452892184834,"version":"0
//| .0.1"}}

// JsonMessageDecoder.unmarshall(cbrm) match {
// case Success(validMsg) => println(validMsg)
// case Failure(ex) => println("Unhandled message: [{}]")
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public void handleMessage(String pattern, String channel, String message) {
case EjectUserFromVoiceRequestMessage.EJECT_USER_FROM_VOICE_REQUEST:
processEjectUserFromVoiceRequestMessage(message);
break;
case GetBreakoutRoomsList.NAME:
bbbInGW.handleJsonMessage(message);
break;
case CreateBreakoutRoomsRequest.NAME:
bbbInGW.handleJsonMessage(message);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class BigBlueButtonInGW(

def forwardMessage(msg: InMessage) = {
msg match {
case m: BreakoutRoomsListMessage => eventBus.publish(BigBlueButtonEvent(m.meetingId, m))
case m: CreateBreakoutRooms => eventBus.publish(BigBlueButtonEvent(m.meetingId, m))
case m: RequestBreakoutJoinURLInMessage => eventBus.publish(BigBlueButtonEvent(m.meetingId, m))
case m: EndAllBreakoutRooms => eventBus.publish(BigBlueButtonEvent(m.meetingId, m))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ object JsonMessageDecoder {

def convertMessage(msg: InHeaderAndJsonPayload): InMessage = {
msg.header.name match {
case GetBreakoutRoomsList.NAME => {
msg.payload.convertTo[BreakoutRoomsListMessage]
}
case CreateBreakoutRoomsRequest.NAME => {
msg.payload.convertTo[CreateBreakoutRooms]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,11 @@ import scala.collection.JavaConversions._
import org.bigbluebutton.core.apps.SimplePollResultOutVO
import org.bigbluebutton.core.apps.SimplePollOutVO
import org.bigbluebutton.core.pubsub.senders.UsersMessageToJsonConverter
import org.bigbluebutton.common.messages.GetUsersFromVoiceConfRequestMessage
import org.bigbluebutton.common.messages.MuteUserInVoiceConfRequestMessage
import org.bigbluebutton.common.messages.EjectUserFromVoiceConfRequestMessage
import org.bigbluebutton.common.messages.GetCurrentLayoutReplyMessage
import org.bigbluebutton.common.messages.BroadcastLayoutMessage
import org.bigbluebutton.common.messages.LockLayoutMessage
import org.bigbluebutton.common.messages._
import org.bigbluebutton.core.pubsub.senders.WhiteboardMessageToJsonConverter
import org.bigbluebutton.common.converters.ToJsonEncoder
import org.bigbluebutton.messages.payload.BreakoutRoomPayload
import org.bigbluebutton.messages.BreakoutRoomStarted
import org.bigbluebutton.messages.payload.CreateBreakoutRoomRequestPayload
import org.bigbluebutton.messages.CreateBreakoutRoomRequest
import org.bigbluebutton.messages.payload.BreakoutRoomJoinURLPayload
import org.bigbluebutton.messages.BreakoutRoomJoinURL
import org.bigbluebutton.messages.payload.UpdateBreakoutUsersPayload
import org.bigbluebutton.messages.payload.BreakoutUserPayload
import org.bigbluebutton.messages.UpdateBreakoutUsers
import org.bigbluebutton.messages.payload.MeetingTimeRemainingPayload
import org.bigbluebutton.messages.TimeRemainingUpdate
import org.bigbluebutton.messages.payload._
import org.bigbluebutton.messages._

object JsonMessageSenderActor {
def props(msgSender: MessageSender): Props =
Expand All @@ -50,13 +36,14 @@ class JsonMessageSenderActor(val service: MessageSender)
def receive = {

// Breakout
case msg: CreateBreakoutRoom => handleCreateBreakoutRoom(msg)
case msg: CreateBreakoutRoom => handleCreateBreakoutRoom(msg)
case msg: BreakoutRoomsListOutMessage => handleBreakoutRoomsList(msg)
case msg: BreakoutRoomJoinURLOutMessage => handleBreakoutRoomJoinURL(msg)
case msg: BreakoutRoomStartedOutMessage => handleBreakoutRoomStarted(msg)
case msg: UpdateBreakoutUsersOutMessage => handleUpdateBreakoutUsers(msg)
case msg: MeetingTimeRemainingUpdate => handleMeetingTimeRemainingUpdate(msg)
case msg: MeetingTimeRemainingUpdate => handleMeetingTimeRemainingUpdate(msg)

case _ => // do nothing
case _ => // do nothing
}

// Breakout
Expand All @@ -80,6 +67,14 @@ class JsonMessageSenderActor(val service: MessageSender)
service.send(MessagingConstants.FROM_MEETING_CHANNEL, request.toJson())
}

private def handleBreakoutRoomsList(msg: BreakoutRoomsListOutMessage) {
val rooms = new java.util.ArrayList[BreakoutRoomPayload]()
msg.rooms.foreach(r => rooms.add(new BreakoutRoomPayload(msg.meetingId, r.breakoutId, r.name)))
val payload = new BreakoutRoomsListPayload(msg.meetingId, rooms)
val request = new BreakoutRoomsList(payload)
service.send(MessagingConstants.FROM_MEETING_CHANNEL, request.toJson())
}

private def handleCreateBreakoutRoom(msg: CreateBreakoutRoom) {
val payload = new CreateBreakoutRoomRequestPayload(msg.room.breakoutId, msg.room.parentId, msg.room.name,
msg.room.voiceConfId, msg.room.viewerPassword, msg.room.moderatorPassword,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ class MeetingActor(val mProps: MeetingProperties,
case msg: GetPollRequest => liveMeeting.handleGetPollRequest(msg)
case msg: GetCurrentPollRequest => liveMeeting.handleGetCurrentPollRequest(msg)
// Breakout rooms
case msg: BreakoutRoomsListMessage => liveMeeting.handleBreakoutRoomsList(msg)
case msg: CreateBreakoutRooms => liveMeeting.handleCreateBreakoutRooms(msg)
case msg: BreakoutRoomCreated => liveMeeting.handleBreakoutRoomCreated(msg)
case msg: RequestBreakoutJoinURLInMessage => liveMeeting.handleRequestBreakoutJoinURL(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class MessageSenderActor(val service: MessageSender)
case msg: WhiteboardEnabledEvent => handleWhiteboardEnabledEvent(msg)
case msg: IsWhiteboardEnabledReply => handleIsWhiteboardEnabledReply(msg)
// breakout room cases
case msg: BreakoutRoomsListOutMessage => handleBreakoutRoomsListOutMessage(msg)
case msg: BreakoutRoomStartedOutMessage => handleBreakoutRoomStartedOutMessage(msg)
case msg: BreakoutRoomJoinURLOutMessage => handleBreakoutRoomJoinURLOutMessage(msg)
case msg: UpdateBreakoutUsersOutMessage => handleUpdateBreakoutUsersOutMessage(msg)
Expand Down Expand Up @@ -664,6 +665,11 @@ class MessageSenderActor(val service: MessageSender)
service.send(MessagingConstants.FROM_WHITEBOARD_CHANNEL, json)
}

private def handleBreakoutRoomsListOutMessage(msg:BreakoutRoomsListOutMessage) {
val json = MeetingMessageToJsonConverter.breakoutRoomsListOutMessageToJson(msg)
service.send(MessagingConstants.FROM_USERS_CHANNEL, json)
}

private def handleBreakoutRoomStartedOutMessage(msg: BreakoutRoomStartedOutMessage) {
val json = MeetingMessageToJsonConverter.breakoutRoomStartedOutMessageToJson(msg)
service.send(MessagingConstants.FROM_USERS_CHANNEL, json)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package org.bigbluebutton.core

import spray.json.{ DefaultJsonProtocol, JsValue, JsString, DeserializationException, JsonFormat }
import org.bigbluebutton.core.api.BreakoutRoomInPayload
import org.bigbluebutton.core.api.CreateBreakoutRooms
import org.bigbluebutton.core.api.InMessageHeader
import org.bigbluebutton.core.api.RequestBreakoutJoinURLInMessage
import org.bigbluebutton.core.api.EndAllBreakoutRooms
import org.bigbluebutton.core.api._

object UserMessagesProtocol extends DefaultJsonProtocol {
/*
Expand All @@ -30,6 +26,7 @@ object UserMessagesProtocol extends DefaultJsonProtocol {

implicit val breakoutRoomInPayloadFormat = jsonFormat2(BreakoutRoomInPayload)
implicit val createBreakoutRoomsFormat = jsonFormat3(CreateBreakoutRooms)
implicit val breakoutRoomsListMessageFormat = jsonFormat1(BreakoutRoomsListMessage)
implicit val requestBreakoutJoinURLInMessageFormat = jsonFormat3(RequestBreakoutJoinURLInMessage)
implicit val endBreakoutRoomsFormat = jsonFormat1(EndAllBreakoutRooms)
implicit val inMsgHeaderFormat = jsonFormat1(InMessageHeader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ case class LockSetting(meetingID: String, locked: Boolean, settings: Map[String,
// Breakout room
/////////////////////////////////////////////////////////////////////////////////////

// Sent by user to request the breakout rooms list of a room
case class BreakoutRoomsListMessage(meetingId: String) extends InMessage
// Sent by user to request creation of breakout rooms
case class CreateBreakoutRooms(meetingId: String, durationInMinutes: Int,
rooms: Vector[BreakoutRoomInPayload]) extends InMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ case class PubSubPong(system: String, timestamp: Long) extends IOutMessage
case object IsAliveMessage extends IOutMessage

// Breakout Rooms
case class BreakoutRoomsListOutMessage(meetingId: String, rooms: Vector[BreakoutRoomBody]) extends IOutMessage
case class CreateBreakoutRoom(meetingId: String, recorded: Boolean, room: BreakoutRoomOutPayload) extends IOutMessage
case class BreakoutRoomOutPayload(breakoutId: String, name: String, parentId: String,
voiceConfId: String, durationInMinutes: Int, moderatorPassword: String, viewerPassword: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ trait BreakoutRoomApp extends SystemConfiguration {
}
presURL
}


def handleBreakoutRoomsList(msg:BreakoutRoomsListMessage) {
val breakoutRooms = breakoutModel.getRooms().toVector map { r => new BreakoutRoomBody(r.id, r.name) }
outGW.send(new BreakoutRoomsListOutMessage(mProps.meetingID, breakoutRooms));
}

def handleCreateBreakoutRooms(msg: CreateBreakoutRooms) {
var i = 0
for (room <- msg.rooms) {
Expand Down
Loading

0 comments on commit 058a217

Please sign in to comment.