Skip to content

Commit

Permalink
- handle properly out of order recording started/stopped events from…
Browse files Browse the repository at this point in the history
… freeswitch
  • Loading branch information
ritzalam committed Feb 7, 2018
1 parent 4375ff1 commit 4714705
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object VoiceApp {
}

def startRecordingVoiceConference(liveMeeting: LiveMeeting, outGW: OutMsgRouter, stream: String): Unit = {
MeetingStatus2x.startRecordingVoice(liveMeeting.status)
MeetingStatus2x.voiceRecordingStart(liveMeeting.status, stream)
val event = MsgBuilder.buildStartRecordingVoiceConfSysMsg(
liveMeeting.props.meetingProp.intId,
liveMeeting.props.voiceProp.voiceConf,
Expand All @@ -25,12 +25,16 @@ object VoiceApp {
}

def stopRecordingVoiceConference(liveMeeting: LiveMeeting, outGW: OutMsgRouter): Unit = {
MeetingStatus2x.stopRecordingVoice(liveMeeting.status)

val event = MsgBuilder.buildStopRecordingVoiceConfSysMsg(
liveMeeting.props.meetingProp.intId,
liveMeeting.props.voiceProp.voiceConf, MeetingStatus2x.getVoiceRecordingFilename(liveMeeting.status)
)
outGW.send(event)
val recStreams = MeetingStatus2x.getVoiceRecordingStreams(liveMeeting.status)

recStreams foreach { rs =>
val event = MsgBuilder.buildStopRecordingVoiceConfSysMsg(
liveMeeting.props.meetingProp.intId,
liveMeeting.props.voiceProp.voiceConf, rs.stream
)
outGW.send(event)
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ case class MeetingExtensionProp(maxExtensions: Int = 2, numExtensions: Int = 0,
sent10MinNotice: Boolean = false, sent5MinNotice: Boolean = false)

object MeetingStatus2x {
def startRecordingVoice(status: MeetingStatus2x): Boolean = {
status.recordingVoice = true
status.recordingVoice
}

def stopRecordingVoice(status: MeetingStatus2x): Boolean = {
status.recordingVoice = false
status.recordingVoice
}

def isVoiceRecording(status: MeetingStatus2x): Boolean = {
status.recordingVoice
status.voiceRecordings.values.find(s => s.recording) match {
case Some(rec) => true
case None => false
}
}

def isExtensionAllowed(status: MeetingStatus2x): Boolean = status.extension.numExtensions < status.extension.maxExtensions
Expand All @@ -50,8 +44,41 @@ object MeetingStatus2x {
def recordingStarted(status: MeetingStatus2x) = status.recording = true
def recordingStopped(status: MeetingStatus2x) = status.recording = false
def isRecording(status: MeetingStatus2x): Boolean = status.recording
def setVoiceRecordingFilename(status: MeetingStatus2x, path: String) = status.voiceRecordingFilename = path
def getVoiceRecordingFilename(status: MeetingStatus2x): String = status.voiceRecordingFilename

def voiceRecordingStart(status2x: MeetingStatus2x, stream: String): VoiceRecordingStream = {
val vrs = new VoiceRecordingStream(stream, recording = false, createdOn = System.currentTimeMillis, ackedOn = None, stoppedOn = None)
status2x.voiceRecordings += vrs.stream -> vrs
vrs
}

def voiceRecordingStarted(status2x: MeetingStatus2x, stream: String): Option[VoiceRecordingStream] = {
val vrs = for {
recStream <- status2x.voiceRecordings.values find (s => s.stream == stream)
} yield {
val rs = recStream.copy(recording = true, ackedOn = Some(System.currentTimeMillis))
status2x.voiceRecordings += rs.stream -> rs
rs
}

vrs
}

def voiceRecordingStopped(status2x: MeetingStatus2x, stream: String): Option[VoiceRecordingStream] = {
val vrs = for {
recStream <- status2x.voiceRecordings.values find (s => s.stream == stream)
} yield {
val rs = recStream.copy(recording = false, stoppedOn = Some(System.currentTimeMillis))
status2x.voiceRecordings += rs.stream -> rs
rs
}

vrs
}

def getVoiceRecordingStreams(status2x: MeetingStatus2x): Vector[VoiceRecordingStream] = {
status2x.voiceRecordings.values.filter(s => s.recording).toVector
}

def setWebcamsOnlyForModerator(status: MeetingStatus2x, value: Boolean) = status.webcamsOnlyForModerator = value
def webcamsOnlyForModeratorEnabled(status: MeetingStatus2x): Boolean = status.webcamsOnlyForModerator
def permisionsInitialized(status: MeetingStatus2x): Boolean = status.permissionsInited
Expand All @@ -73,8 +100,8 @@ object MeetingStatus2x {
}

class MeetingStatus2x {
private var voiceRecordings: collection.immutable.HashMap[String, VoiceRecordingStream] = new collection.immutable.HashMap[String, VoiceRecordingStream]

private var recordingVoice = false
private var audioSettingsInited = false
private var permissionsInited = false
private var permissionsChangedOn: Long = System.currentTimeMillis()
Expand All @@ -84,10 +111,10 @@ class MeetingStatus2x {
private var meetingEnded = false
private var meetingMuted = false

private var voiceRecordingFilename: String = ""

private var extension = new MeetingExtensionProp

private var webcamsOnlyForModerator = false

}

case class VoiceRecordingStream(stream: String, recording: Boolean, createdOn: Long, ackedOn: Option[Long], stoppedOn: Option[Long])
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait RecordingStartedVoiceConfEvtMsgHdlr {

def handleRecordingStartedVoiceConfEvtMsg(msg: RecordingStartedVoiceConfEvtMsg) {
if (msg.body.recording) {
MeetingStatus2x.setVoiceRecordingFilename(liveMeeting.status, msg.body.stream)
MeetingStatus2x.voiceRecordingStarted(liveMeeting.status, msg.body.stream)

def buildVoiceRecordingStartedEvtMsg(meetingId: String, stream: String, timestamp: String,
voiceConf: String): BbbCommonEnvCoreMsg = {
Expand All @@ -30,7 +30,7 @@ trait RecordingStartedVoiceConfEvtMsgHdlr {
msg.body.timestamp, liveMeeting.props.voiceProp.voiceConf)
outGW.send(event)
} else {
MeetingStatus2x.setVoiceRecordingFilename(liveMeeting.status, "")
MeetingStatus2x.voiceRecordingStopped(liveMeeting.status, msg.body.stream)

def buildVoiceRecordingStoppedEvtMsg(meetingId: String, stream: String, timestamp: String,
voiceConf: String): BbbCommonEnvCoreMsg = {
Expand Down

0 comments on commit 4714705

Please sign in to comment.