start implementing logic for polling

This commit is contained in:
Richard Alam 2013-06-17 21:51:49 +00:00
parent 4fc7a40faf
commit 0c9fb34243
9 changed files with 141 additions and 74 deletions

View File

@ -5,12 +5,14 @@ import java.util.Map;
import org.bigbluebutton.conference.MeetingsManager;
import org.bigbluebutton.conference.service.messaging.MessagingConstants;
import org.bigbluebutton.conference.service.messaging.redis.MessageHandler;
import org.bigbluebutton.core.api.IBigBlueButtonInGW;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class MeetingMessageHandler implements MessageHandler {
private MeetingsManager meetingManager;
private IBigBlueButtonInGW bbbGW;
@Override
public void handleMessage(String pattern, String channel, String message) {
@ -21,14 +23,14 @@ public class MeetingMessageHandler implements MessageHandler {
String messageId = map.get("messageId");
if (messageId != null){
if (MessagingConstants.END_MEETING_REQUEST_EVENT.equalsIgnoreCase(messageId)){
meetingManager.endMeeting(meetingId);
bbbGW.endMeeting(meetingId);
}
}
}
}
public void setMeetingManager(MeetingsManager manager) {
meetingManager = manager;
public void setBigBlueButtonInGW(IBigBlueButtonInGW bbbGW) {
this.bbbGW = bbbGW;
}
}

View File

@ -4,6 +4,10 @@ import java.util.Map;
public interface IBigBlueButtonInGW {
void isAliveAudit();
void statusMeetingAudit(String meetingID);
void endMeeting(String meetingID);
void endAllMeetings();
void createMeeting2(String meetingID, boolean recorded, String voiceBridge);
void destroyMeeting(String meetingID);

View File

@ -19,8 +19,7 @@ class Meeting(val meetingID: String, val recorded: Boolean, val voiceBridge: Str
val usersApp = new UsersApp(meetingID, recorded, outGW)
val presentationApp = new PresentationApp(meetingID, recorded, outGW, usersApp)
//val polls = new PollApp(outGW)
val pollApp = new PollApp(outGW)
def act() = {
loop {

View File

@ -7,4 +7,13 @@ object Role extends Enumeration {
}
case class Presenter(presenterID: String, presenterName: String, assignedBy: String)
case class UserVO(userID: String, externUserID: String, name: String, role: String, raiseHand: Boolean, presenter: Boolean, hasStream: Boolean)
case class UserVO(userID: String, externUserID: String, name: String, role: String, raiseHand: Boolean, presenter: Boolean, hasStream: Boolean)
case class MeetingConfig(name: String, id: MeetingID, passwords: MeetingPasswords, welcomeMsg: String, logoutUrl: String,
maxUsers: Int, record: Boolean=false, duration: MeetingDuration,
defaultAvatarURL: String, defaultConfigToken: String)
case class MeetingName(name: String)
case class MeetingID(internal:String, external: String)
case class VoiceConfig(telVoice: String, webVoice: String, dialNumber: String)
case class MeetingPasswords(moderatorPass: String, viewerPass: String)
case class MeetingDuration(duration: Int = 0, createdTime: Long = 0, startTime: Long = 0, endTime: Long = 0)

View File

@ -3,10 +3,8 @@ package org.bigbluebutton.core.apps.poll
import scala.collection.mutable.HashMap
import QuestionType._
class Poll(val id: String, val title: String) {
class Poll(val id: String, val title: String, questions: Array[Question]) {
private var _active: Boolean = false
private var questions = new HashMap[Int, Question]()
def active = _active
@ -18,32 +16,23 @@ class Poll(val id: String, val title: String) {
_active = false;
}
def addQuestion(id: Int, questionType: QuestionType, question: String) {
questions += id -> new Question(id, questionType, question)
def clear() {
}
def deleteQuestion(id: Int) {
questions -= id
def hasResponses():Boolean = {
questions.foreach(q => {
if (q.hasResponders) return true
})
return false
}
def addResponse(questionID: Int, responseID: Int, responseText: String) {
questions.get(questionID) match {
case Some(q) => q.addResponse(new Response(responseID, responseText))
case None => // do nothing
}
}
def deleteResponse(questionID: Int, responseID: Int) {
questions.get(questionID) match {
case Some(q) => q.deleteResponse(responseID)
case None => // do nothing
}
}
def respondToQuestion(questionID: Int, responseID: Int, userID: String, username: String):Unit = {
questions.get(questionID) match {
case Some(q) => q.respondToQuestion(responseID, new Responder(userID, username))
case None => // do nothing
}
def respondToQuestion(questionID: String, responseID: String, userID: String, username: String) {
questions.foreach(q => {
if (q.id.equals(questionID)) {
q.respondToQuestion(responseID, new Responder(userID, username))
}
})
}
}

View File

@ -1,22 +1,87 @@
package org.bigbluebutton.core.apps.poll
import scala.collection.mutable.HashMap
import org.bigbluebutton.core.User
import org.bigbluebutton.core.api.InMessage
import org.bigbluebutton.core.api.MessageOutGateway
import scala.collection.mutable.ArrayBuffer
class PollApp() {
class PollApp(meetingID: String, recorded: Boolean, outGW: MessageOutGateway) {
import org.bigbluebutton.core.apps.poll.messages._
private val polls = new HashMap[String, Poll]()
def handleMessage(msg: InMessage):Unit = {
msg match {
case create: CreatePoll => createPoll(create)
case createPoll: CreatePoll => handleCreatePoll(createPoll)
case updatePoll: UpdatePoll => handleUpdatePoll(updatePoll)
case destroyPoll: DestroyPoll => handleDestroyPoll(destroyPoll)
case removePoll: RemovePoll => handleRemovePoll(removePoll)
case sharePoll: SharePoll => handleSharePoll(sharePoll)
case stopPoll: StopPoll => handleStopPoll(stopPoll)
case startPoll: StartPoll => handleStartPoll(startPoll)
case clearPoll: ClearPoll => handleClearPoll(clearPoll)
}
}
private def createPoll(msg: CreatePoll) {
var poll = new Poll(msg.poll.id, msg.poll.title)
private def handleClearPoll(msg: ClearPoll) {
polls.get(msg.pollID) match {
case None => // send poll not found message
case Some(p) => {
p.clear
}
}
}
private def handleStartPoll(msg: StartPoll) {
}
private def handleStopPoll(msg: StopPoll) {
}
private def handleSharePoll(msg: SharePoll) {
}
private def handleRemovePoll(msg: RemovePoll) {
}
private def handleDestroyPoll(msg: DestroyPoll) {
}
private def handleUpdatePoll(msg: UpdatePoll) {
}
private def handleCreatePoll(msg: CreatePoll) {
val pollVO = msg.poll
val questions = new ArrayBuffer[Question]
pollVO.questions.foreach(qv => {
val responses = new ArrayBuffer[Response]
qv.responses.foreach(rv => {
val response = new Response(rv.id, rv.text)
responses += response
})
val rArray = new Array[Response](responses.length)
responses.copyToArray(rArray)
questions += new Question(qv.id, qv.questionType, qv.question, rArray)
})
val qArray = new Array[Question](questions.length)
questions.copyToArray(qArray)
val poll = new Poll(msg.poll.id, msg.poll.title, qArray)
polls += poll.id -> poll
}
}

View File

@ -3,32 +3,22 @@ package org.bigbluebutton.core.apps.poll
import scala.collection.mutable.HashMap
import QuestionType._
class Question(val id: Int, val questionType: QuestionType, val question: String) {
class Question(val id: String, val questionType: QuestionType, val question: String, val responses: Array[Response]) {
def clear() {
responses.foreach(r => r.clear)
}
def hasResponders():Boolean = {
responses.foreach(r => {
if (r.numResponders > 0) return true
})
return false
}
def respondToQuestion(id: String, resp: Responder) {
private val responses = new HashMap[Int, Response]()
def addResponse(resp: Response):Unit = {
responses.get(resp.id) match {
case None => responses += resp.id -> resp
}
}
def deleteResponse(id: Int) {
responses -= id
}
def respondToQuestion(id: Int, resp: Responder) {
responses.get(id) match {
case Some(r) => r.addResponder(resp)
case None => // do nothing
}
}
def getResponses():Array[Response] = {
var r = new Array[Response](responses.size)
responses.values.copyToArray(r)
return r
}
}

View File

@ -4,10 +4,13 @@ import scala.collection.mutable.ArrayBuffer
case class Responder(val userID: String, val name: String)
class Response(val id: Int, val response: String) {
class Response(val id: String, val response: String) {
val responders = new ArrayBuffer[Responder]()
def clear() {
responders.clear
}
def addResponder(responder: Responder) {
responders += responder
}

View File

@ -3,16 +3,22 @@ package org.bigbluebutton.core.apps.poll.messages
import org.bigbluebutton.core.apps.poll.QuestionType._
import org.bigbluebutton.core.api.InMessage
import org.bigbluebutton.core.api.IOutMessage
// Poll Messages
case class CreatePoll(meetingID:String, poll: PollVO) extends InMessage
case class StopPoll(meetingID:String, id: String) extends InMessage
case class StartPoll(meetingID:String, id: String) extends InMessage
case class AddQuestion(meetingID:String, pollID: String, question: QuestionVO)
case class DeleteQuestion(meetingID:String, pollID: String, questionID: Int)
case class AddResponse(meetingID:String, pollID: String, questionID: Int, responseVO: ResponseVO)
case class DeleteResponse(meetingID:String, pollID: String, questionID: Int, responseID: Int)
case class CreatePoll(meetingID:String, poll: PollVO, requesterID: String) extends InMessage
case class UpdatePoll(meetingID: String, poll: PollVO) extends InMessage
case class DestroyPoll(meetingID: String, pollID: String) extends InMessage
case class RemovePoll(meetingID: String, pollID: String) extends InMessage
case class SharePoll(meetingID: String, pollID: String) extends InMessage
case class StopPoll(meetingID:String, pollID: String) extends InMessage
case class StartPoll(meetingID:String, pollID: String) extends InMessage
case class ClearPoll(meetingID: String, pollID: String, requesterID: String, force: Boolean=false) extends InMessage
case class ResponseVO(meetingID:String, id: Int, text: String)
case class QuestionVO(meetingID:String, id: Int, questionType: QuestionType, question: String, responses: Array[ResponseVO])
case class PollVO(meetingID:String, id: String, title: String, questions: Array[QuestionVO])
case class ResponseVO(meetingID:String, id: String, order: Int, text: String)
case class QuestionVO(meetingID:String, id: String, order: Int, questionType: QuestionType, question: String, responses: Array[ResponseVO])
case class PollVO(meetingID:String, id: String, title: String, questions: Array[QuestionVO], preCreated: Boolean=false)
// Out Messages
case class ClearPollFailed(meetingID: String, pollID: String, requesterID: String, reason: String) extends IOutMessage