From c02170f377d4eebbd4c74564e223f0e84e02ce91 Mon Sep 17 00:00:00 2001 From: Richard Alam <ritzalam@gmail.com> Date: Thu, 18 Aug 2016 21:34:57 +0000 Subject: [PATCH] - handle timeout when querying screen sharing session. --- .../screenshare/ScreenShareApplication.scala | 101 +++++++++--------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/bbb-screenshare/app/src/main/scala/org/bigbluebutton/app/screenshare/ScreenShareApplication.scala b/bbb-screenshare/app/src/main/scala/org/bigbluebutton/app/screenshare/ScreenShareApplication.scala index fc2a27eb34..895d18399a 100755 --- a/bbb-screenshare/app/src/main/scala/org/bigbluebutton/app/screenshare/ScreenShareApplication.scala +++ b/bbb-screenshare/app/src/main/scala/org/bigbluebutton/app/screenshare/ScreenShareApplication.scala @@ -18,16 +18,16 @@ */ package org.bigbluebutton.app.screenshare -import scala.util.{Success, Failure} +import scala.util.{Failure, Success} import akka.util.Timeout import akka.pattern.ask -import org.bigbluebutton.app.screenshare.events.{IEventsMessageBus} +import org.bigbluebutton.app.screenshare.events.IEventsMessageBus import org.bigbluebutton.app.screenshare.server.sessions.ScreenshareManager import org.bigbluebutton.app.screenshare.server.sessions.messages._ import org.bigbluebutton.app.screenshare.server.util.LogHelper import akka.actor.ActorSystem -import scala.concurrent.Future -import scala.concurrent.Await + +import scala.concurrent.{Await, Future, TimeoutException} import scala.concurrent.duration._ class ScreenShareApplication(val bus: IEventsMessageBus, val jnlpFile: String, @@ -93,54 +93,71 @@ class ScreenShareApplication(val bus: IEventsMessageBus, val jnlpFile: String, logger.debug("Received get screen sharing info on token=" + token + "]") } - val future = screenShareManager ? ScreenShareInfoRequest(meetingId, token) - val reply = Await.result(future, timeout.duration).asInstanceOf[ScreenShareInfoRequestReply] - - val publishUrl = streamBaseUrl + "/" + meetingId - val info = new ScreenShareInfo(publishUrl, reply.streamId) - new ScreenShareInfoResponse(info, null) - } + try { + val future = screenShareManager ? ScreenShareInfoRequest(meetingId, token) + val reply = Await.result(future, timeout.duration).asInstanceOf[ScreenShareInfoRequestReply] - def recordStream(meetingId: String, streamId: String):java.lang.Boolean = { - if (logger.isDebugEnabled()) { - logger.debug("Received record stream request on stream=" + streamId + "]") + val publishUrl = streamBaseUrl + "/" + meetingId + val info = new ScreenShareInfo(publishUrl, reply.streamId) + new ScreenShareInfoResponse(info, null) + } catch { + case e: TimeoutException => + if (logger.isDebugEnabled()) { + logger.debug("FAILED to get screen share info on meetingId=" + meetingId + "]") + } + new ScreenShareInfoResponse(null, initError) } - //var recorded = false - //sendIsStreamRecored(meetingId, streamId).onComplete { - // case Success(record) => recorded = record - // case Failure(ex) => recorded = false - //} + } - // if (logger.isDebugEnabled()) { - // logger.debug("Received record stream response=" + recorded + "] *************************************") - // } - // recorded + def getSharingStatus(meetingId: String, streamId: String): SharingStatus = { - var record = false - val future = screenShareManager ? IsStreamRecorded(meetingId, streamId) + try { + val future = screenShareManager ? GetSharingStatus(meetingId, streamId) + val reply = Await.result(future, timeout.duration).asInstanceOf[GetSharingStatusReply] - val reply = Await.result(future, timeout.duration).asInstanceOf[IsStreamRecordedReply] - record = reply.record - record + reply.streamId match { + case Some(streamId) => new SharingStatus(reply.status, streamId) + case None => new SharingStatus(reply.status, null) + } + } catch { + case e: TimeoutException => + if (logger.isDebugEnabled()) { + logger.debug("FAILED to get sharing status on stream=" + streamId + "]") + } + new SharingStatus("STOP", null) + } } + def recordStream(meetingId: String, streamId: String):java.lang.Boolean = { + if (logger.isDebugEnabled()) { + logger.debug("Received record stream request on stream=" + streamId + "]") + } - private def sendIsStreamRecored(meetingId: String, streamId: String): Future[Boolean] = { + var record = false - //screenShareManager ? IsStreamRecorded(meetingId, streamId) + try { + val future = screenShareManager ? IsStreamRecorded(meetingId, streamId) + val reply = Await.result(future, timeout.duration).asInstanceOf[IsStreamRecordedReply] + record = reply.record + if (logger.isDebugEnabled()) { + logger.debug("Received response SUCCESS request on stream=" + streamId + "]") + } + } catch { + case e: TimeoutException => + if (logger.isDebugEnabled()) { + logger.debug("FAILED to get is stream recorded on stream=" + streamId + "]") + } + record = false + } - (screenShareManager ? IsStreamRecorded(meetingId, streamId)) - .mapTo[IsStreamRecordedReply] - .map(result => result.record) - //.recover { - // case _ => false - //} + record } + def startShareRequest(meetingId: String, userId: String, record: java.lang.Boolean) { if (logger.isDebugEnabled()) { logger.debug("Received start share request on meeting=" + meetingId + "for user=" + userId + "]") @@ -209,19 +226,7 @@ class ScreenShareApplication(val bus: IEventsMessageBus, val jnlpFile: String, screenShareManager ! new UpdateShareStatus(meetingId, streamId, seqNum) } - def getSharingStatus(meetingId: String, streamId: String): SharingStatus = { - - var stopped = false - - val future = screenShareManager ? GetSharingStatus(meetingId, streamId) - val reply = Await.result(future, timeout.duration).asInstanceOf[GetSharingStatusReply] - reply.streamId match { - case Some(streamId) => new SharingStatus(reply.status, streamId) - case None => new SharingStatus(reply.status, null) - } - - } def screenShareClientPongMessage (meetingId: String, userId: String, streamId: String, timestamp: java.lang.Long) { screenShareManager ! new ClientPongMessage(meetingId, userId, streamId, timestamp) -- GitLab