- user inactivity audit message sending and receiving

This commit is contained in:
Richard Alam 2018-04-09 12:22:00 -07:00
parent 837453454e
commit 48de7625c9
5 changed files with 29 additions and 22 deletions

View File

@ -5,13 +5,13 @@ import org.bigbluebutton.core.models.Users2x
import org.bigbluebutton.core.running.MeetingActor
trait UserInactivityAuditResponseMsgHdlr {
this: MeetingActor =>
this: MeetingActor =>
def handleUserInactivityAuditResponseMsg(msg: UserInactivityAuditResponseMsg):Unit = {
for {
user <- Users2x.findWithIntId(liveMeeting.users2x, msg.body.userId)
} yield {
Users2x.updateInactivityResponse(liveMeeting.users2x, user)
}
}
def handleUserInactivityAuditResponseMsg(msg: UserInactivityAuditResponseMsg): Unit = {
for {
user <- Users2x.findWithIntId(liveMeeting.users2x, msg.body.userId)
} yield {
Users2x.updateInactivityResponse(liveMeeting.users2x, user)
}
}
}

View File

@ -1,6 +1,7 @@
package org.bigbluebutton.core.models
import com.softwaremill.quicklens._
import org.bigbluebutton.core.util.TimeUtil
object Users2x {
def findWithIntId(users: Users2x, intId: String): Option[UserState] = {
@ -26,11 +27,11 @@ object Users2x {
users.toVector.filter(u => !u.presenter)
}
def updateInactivityResponse(users: Users2x, u: UserState): UserState = {
val newUserState = modify(u)(_.inactivityResponseOn).setTo(System.currentTimeMillis())
users.save(newUserState)
newUserState
}
def updateInactivityResponse(users: Users2x, u: UserState): UserState = {
val newUserState = modify(u)(_.inactivityResponseOn).setTo(TimeUtil.timeNowInMs())
users.save(newUserState)
newUserState
}
def changeRole(users: Users2x, u: UserState, newRole: String): UserState = {
val newUserState = modify(u)(_.role).setTo(newRole).modify(_.roleChangedOn).setTo(System.currentTimeMillis())

View File

@ -4,6 +4,7 @@ import java.io.{ PrintWriter, StringWriter }
import akka.actor._
import akka.actor.SupervisorStrategy.Resume
import org.bigbluebutton.SystemConfiguration
import org.bigbluebutton.core.apps.groupchats.{ GroupChatApp, GroupChatHdlrs }
import org.bigbluebutton.core.apps.presentationpod._
import org.bigbluebutton.core.apps.users._
@ -54,6 +55,7 @@ class MeetingActor(
val liveMeeting: LiveMeeting
)
extends BaseMeetingActor
with SystemConfiguration
with GuestsApp
with LayoutApp2x
with VoiceApp2x
@ -79,7 +81,7 @@ class MeetingActor(
with SyncGetMeetingInfoRespMsgHdlr
with ClientToServerLatencyTracerMsgHdlr
with ValidateConnAuthTokenSysMsgHdlr
with UserInactivityAuditResponseMsgHdlr {
with UserInactivityAuditResponseMsgHdlr {
override val supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) {
case e: Exception => {
@ -348,7 +350,7 @@ class MeetingActor(
case m: ValidateConnAuthTokenSysMsg => handleValidateConnAuthTokenSysMsg(m)
case m: UserInactivityAuditResponseMsg => handleUserInactivityAuditResponseMsg(m)
case m: UserInactivityAuditResponseMsg => handleUserInactivityAuditResponseMsg(m)
case _ => log.warning("***** Cannot handle " + msg.envelope.name)
}
@ -515,24 +517,27 @@ class MeetingActor(
def processUserInactivityAudit(): Unit = {
val now = TimeUtil.timeNowInMs()
if (now - lastUserInactivitySentOn > 30000) {
val auditTimerMs = TimeUtil.minutesToMillis(userInactivityAuditTimer)
if (now - lastUserInactivitySentOn > auditTimerMs) {
lastUserInactivitySentOn = now
checkInactiveUsers = true
val event = buildUserInactivityAuditMsg(liveMeeting.props.meetingProp.intId)
outGW.send(event)
}
if (checkInactiveUsers && now - lastUserInactivitySentOn > 10000) {
val auditResponseMs = TimeUtil.minutesToMillis(userInactivityAuditResponseDuration)
if (checkInactiveUsers && now - lastUserInactivitySentOn > auditResponseMs) {
checkInactiveUsers = false
checkForInactiveUsers()
}
}
def checkForInactiveUsers(): Unit = {
val now = TimeUtil.timeNowInMs()
val auditResponseMs = TimeUtil.minutesToMillis(userInactivityAuditResponseDuration)
val users = Users2x.findAll(liveMeeting.users2x)
users foreach { u =>
if (now - u.inactivityResponseOn > 2000) {
val respondedOntIme = lastUserInactivitySentOn < u.inactivityResponseOn && (lastUserInactivitySentOn + auditResponseMs) > u.inactivityResponseOn
if (!respondedOntIme) {
UsersApp.ejectUserFromMeeting(outGW, liveMeeting, u.intId, SystemUser.ID, "User inactive for too long.", EjectReasonCode.USER_INACTIVITY)
Sender.sendDisconnectClientSysMsg(liveMeeting.props.meetingProp.intId, u.intId, SystemUser.ID, EjectReasonCode.USER_INACTIVITY, outGW)
}
@ -542,7 +547,7 @@ class MeetingActor(
def buildUserInactivityAuditMsg(meetingId: String): BbbCommonEnvCoreMsg = {
val routing = Routing.addMsgToClientRouting(MessageTypes.BROADCAST_TO_MEETING, meetingId, "system")
val envelope = BbbCoreEnvelope(UserInactivityAuditMsg.NAME, routing)
val body = UserInactivityAuditMsgBody(meetingId)
val body = UserInactivityAuditMsgBody(meetingId, TimeUtil.minutesToSeconds(userInactivityAuditResponseDuration))
val header = BbbClientMsgHeader(UserInactivityAuditMsg.NAME, meetingId, "system")
val event = UserInactivityAuditMsg(header, body)

View File

@ -34,6 +34,7 @@ object AllowedMessageNames {
GetGuestPolicyReqMsg.NAME,
SetGuestPolicyCmdMsg.NAME,
GuestsWaitingApprovedMsg.NAME,
UserInactivityAuditResponseMsg.NAME,
// Webcams
GetWebcamsOnlyForModeratorReqMsg.NAME,

View File

@ -362,8 +362,8 @@ case class GetPresenterGroupRespMsgBody(presenterGroup: Vector[String], requeste
object UserInactivityAuditMsg { val NAME = "UserInactivityAuditMsg" }
case class UserInactivityAuditMsg(header: BbbClientMsgHeader, body: UserInactivityAuditMsgBody) extends StandardMsg
case class UserInactivityAuditMsgBody(meetingId: String)
case class UserInactivityAuditMsgBody(meetingId: String, responseDuration: Long)
object UserInactivityAuditResponseMsg { val NAME = "UserInactivityAuditResponseMsg" }
case class UserInactivityAuditResponseMsg(header: BbbClientMsgHeader, body: UserInactivityAuditResponseMsgBody) extends StandardMsg
case class UserInactivityAuditResponseMsgBody(meetingId: String, userId: String)
case class UserInactivityAuditResponseMsgBody(userId: String)