graphql: Refactor externalVideo data

This commit is contained in:
Gustavo Trott 2023-09-06 17:19:10 -03:00
parent a310c9a32b
commit 2a38c935d3
5 changed files with 68 additions and 59 deletions

View File

@ -20,7 +20,7 @@ trait StopExternalVideoPubMsgHdlr extends RightsManagementTrait {
} else {
ExternalVideoModel.clear(liveMeeting.externalVideoModel)
ExternalVideoDAO.updateStopped(liveMeeting.props.meetingProp.intId)
ExternalVideoDAO.updateStoppedSharing(liveMeeting.props.meetingProp.intId)
//broadcastEvent
val msgEvent = MsgBuilder.buildStopExternalVideoEvtMsg(liveMeeting.props.meetingProp.intId, msg.header.userId)

View File

@ -5,33 +5,31 @@ import slick.jdbc.PostgresProfile.api._
import slick.lifted.ProvenShape
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
import scala.util.{ Failure, Success }
case class ExternalVideoDbModel(
externalVideoId: String,
meetingId: String,
externalVideoUrl: String,
startedAt: java.sql.Timestamp = new java.sql.Timestamp(System.currentTimeMillis()),
stoppedAt: Option[java.sql.Timestamp],
lastEventAt: Option[java.sql.Timestamp],
lastEventDesc: String,
playerRate: Double,
playerTime: Double,
playerState: Int
externalVideoId: String,
meetingId: String,
externalVideoUrl: String,
startedSharingAt: java.sql.Timestamp,
stoppedSharingAt: Option[java.sql.Timestamp],
updatedAt: java.sql.Timestamp,
playerPlaybackRate: Double,
playerCurrentTime: Double,
playerPlaying: Boolean
)
class ExternalVideoDbTableDef(tag: Tag) extends Table[ExternalVideoDbModel](tag, "external_video") {
val externalVideoId = column[String]("externalVideoId", O.PrimaryKey)
val meetingId = column[String]("meetingId")
val externalVideoUrl = column[String]("externalVideoUrl")
val startedAt = column[java.sql.Timestamp]("startedAt")
val stoppedAt = column[Option[java.sql.Timestamp]]("stoppedAt")
val lastEventAt = column[Option[java.sql.Timestamp]]("lastEventAt")
val lastEventDesc = column[String]("lastEventDesc")
val playerRate = column[Double]("playerRate")
val playerTime = column[Double]("playerTime")
val playerState = column[Int]("playerState")
override def * : ProvenShape[ExternalVideoDbModel] = (externalVideoId, meetingId, externalVideoUrl, startedAt, stoppedAt, lastEventAt, lastEventDesc, playerRate, playerTime, playerState) <> (ExternalVideoDbModel.tupled, ExternalVideoDbModel.unapply)
val startedSharingAt = column[java.sql.Timestamp]("startedSharingAt")
val stoppedSharingAt = column[Option[java.sql.Timestamp]]("stoppedSharingAt")
val updatedAt = column[java.sql.Timestamp]("updatedAt")
val playerPlaybackRate = column[Double]("playerPlaybackRate")
val playerCurrentTime = column[Double]("playerCurrentTime")
val playerPlaying = column[Boolean]("playerPlaying")
override def * : ProvenShape[ExternalVideoDbModel] = (externalVideoId, meetingId, externalVideoUrl, startedSharingAt, stoppedSharingAt, updatedAt, playerPlaybackRate, playerCurrentTime, playerPlaying) <> (ExternalVideoDbModel.tupled, ExternalVideoDbModel.unapply)
}
object ExternalVideoDAO {
@ -42,18 +40,17 @@ object ExternalVideoDAO {
externalVideoId = System.currentTimeMillis() + "-" + RandomStringGenerator.randomAlphanumericString(8),
meetingId = meetingId,
externalVideoUrl = externalVideoUrl,
startedAt = new java.sql.Timestamp(System.currentTimeMillis()),
stoppedAt = None,
lastEventAt = None,
lastEventDesc = "",
playerRate = 0,
playerTime = 0,
playerState = 0,
startedSharingAt = new java.sql.Timestamp(System.currentTimeMillis()),
stoppedSharingAt = None,
updatedAt = new java.sql.Timestamp(System.currentTimeMillis()),
playerPlaybackRate = 1,
playerCurrentTime = 0,
playerPlaying = true
)
)
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) inserted in ExternalVideo table!")
case Failure(e) => DatabaseConnection.logger.error(s"Error inserting ExternalVideo: $e")
case Failure(e) => DatabaseConnection.logger.error(s"Error inserting ExternalVideo: $e")
}
}
@ -61,26 +58,38 @@ object ExternalVideoDAO {
DatabaseConnection.db.run(
TableQuery[ExternalVideoDbTableDef]
.filter(_.meetingId === meetingId)
.filter(_.stoppedAt.isEmpty)
.map(ev => (ev.lastEventDesc, ev.playerRate, ev.playerTime, ev.playerState, ev.lastEventAt))
.update((status, rate, time, state, Some(new java.sql.Timestamp(System.currentTimeMillis()))))
.filter(_.stoppedSharingAt.isEmpty)
.map(ev => (ev.playerPlaybackRate, ev.playerCurrentTime, ev.playerPlaying, ev.updatedAt))
.update((
rate,
time,
status match {
case "play" => true
case "stop" => false
case _ => state match {
case 1 => true
case 0 => false
}
},
new java.sql.Timestamp(System.currentTimeMillis())
))
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated on ExternalVideo table!")
case Failure(e) => DatabaseConnection.logger.debug(s"Error updating ExternalVideo: $e")
}
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated on ExternalVideo table!")
case Failure(e) => DatabaseConnection.logger.debug(s"Error updating ExternalVideo: $e")
}
}
def updateStopped(meetingId: String) = {
def updateStoppedSharing(meetingId: String) = {
DatabaseConnection.db.run(
TableQuery[ExternalVideoDbTableDef]
.filter(_.meetingId === meetingId)
.filter(_.stoppedAt.isEmpty)
.map(ev => ev.stoppedAt)
.update(Some(new java.sql.Timestamp(System.currentTimeMillis())))
.filter(_.stoppedSharingAt.isEmpty)
.map(ev => (ev.stoppedSharingAt, ev.playerPlaying))
.update(Some(new java.sql.Timestamp(System.currentTimeMillis())), false)
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated stoppedAt on ExternalVideo table!")
case Failure(e) => DatabaseConnection.logger.debug(s"Error updating stoppedAt on ExternalVideo: $e")
}
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated stoppedSharingAt on ExternalVideo table!")
case Failure(e) => DatabaseConnection.logger.debug(s"Error updating stoppedSharingAt on ExternalVideo: $e")
}
}
}

View File

@ -1171,19 +1171,18 @@ create table "external_video"(
"externalVideoId" varchar(100) primary key,
"meetingId" varchar(100) REFERENCES "meeting"("meetingId") ON DELETE CASCADE,
"externalVideoUrl" varchar(500),
"startedAt" timestamp with time zone,
"stoppedAt" timestamp with time zone,
"lastEventAt" timestamp with time zone,
"lastEventDesc" varchar(50),
"playerRate" numeric,
"playerTime" numeric,
"playerState" integer
"startedSharingAt" timestamp with time zone,
"stoppedSharingAt" timestamp with time zone,
"updatedAt" timestamp with time zone,
"playerPlaybackRate" numeric,
"playerCurrentTime" numeric,
"playerPlaying" boolean
);
create index "external_video_meetingId_current" on "external_video"("meetingId") WHERE "stoppedAt" IS NULL;
create index "external_video_meetingId_current" on "external_video"("meetingId") WHERE "stoppedSharingAt" IS NULL;
CREATE VIEW "v_external_video" AS
SELECT * FROM "external_video"
WHERE "stoppedAt" IS NULL;
WHERE "stoppedSharingAt" IS NULL;
--------------------------------
----Screenshare

View File

@ -12,13 +12,12 @@ select_permissions:
columns:
- externalVideoId
- externalVideoUrl
- lastEventAt
- lastEventDesc
- playerRate
- playerState
- playerTime
- startedAt
- stoppedAt
- playerPlaybackRate
- playerPlaying
- playerCurrentTime
- startedSharingAt
- stoppedSharingAt
- updatedAt
filter:
meetingId:
_eq: X-Hasura-MeetingId

View File

@ -296,9 +296,10 @@ class VideoPlayer extends Component {
const { playing } = this.state;
const curTime = this.getCurrentTime();
const rate = this.getCurrentPlaybackRate();
if (isPresenter && !playing) {
this.sendSyncMessage('play', { time: curTime });
this.sendSyncMessage('play', { rate, time: curTime });
}
this.setState({ playing: true });
@ -314,9 +315,10 @@ class VideoPlayer extends Component {
const { playing } = this.state;
const curTime = this.getCurrentTime();
const rate = this.getCurrentPlaybackRate();
if (isPresenter && playing) {
this.sendSyncMessage('stop', { time: curTime });
this.sendSyncMessage('stop', { rate, time: curTime });
}
this.setState({ playing: false });