Store slide position data in postgres

This commit is contained in:
Paul Trudel 2023-07-27 19:10:51 +00:00
parent e61edbdfcc
commit 8373eefdc3
9 changed files with 91 additions and 13 deletions

View File

@ -0,0 +1,20 @@
package org.bigbluebutton.core.apps.presentationpod
import org.bigbluebutton.common2.msgs._
import org.bigbluebutton.core.apps.RightsManagementTrait
import org.bigbluebutton.core.bus.MessageBus
import org.bigbluebutton.core.db.PresPageDAO
import org.bigbluebutton.core.domain.MeetingState2x
import org.bigbluebutton.core.running.LiveMeeting
trait AddSlidePositionsPubMsgHdlr extends RightsManagementTrait {
this: PresentationPodHdlrs =>
def handle(msg: AddSlidePositionsPubMsg, state: MeetingState2x,
liveMeeting: LiveMeeting, bus: MessageBus) = {
PresPageDAO.updateSlidePosition(msg.body.presentationId, msg.body.width, msg.body.height,
msg.body.viewBoxWidth, msg.body.viewBoxHeight)
state
}
}

View File

@ -21,6 +21,7 @@ class PresentationPodHdlrs(implicit val context: ActorContext)
with PresentationUploadTokenReqMsgHdlr
with MakePresentationDownloadReqMsgHdlr
with ResizeAndMovePagePubMsgHdlr
with AddSlidePositionsPubMsgHdlr
with SyncGetPresentationPodsMsgHdlr
with RemovePresentationPodPubMsgHdlr
with PresentationPageConvertedSysMsgHdlr

View File

@ -12,6 +12,7 @@ case class PresPageDbModel(
pageId: String,
presentationId: String,
podId: String,
slideId: String,
num: Int,
urls: String,
slideRevealed: Boolean,
@ -21,13 +22,16 @@ case class PresPageDbModel(
widthRatio: Double,
heightRatio: Double,
width: Double,
height: Double
height: Double,
viewBoxWidth: Double,
viewBoxHeight: Double
)
class PresPageDbTableDef(tag: Tag) extends Table[PresPageDbModel](tag, None, "pres_page") {
val pageId = column[String]("pageId", O.PrimaryKey)
val presentationId = column[String]("presentationId")
val podId = column[String]("podId")
val slideId = column[String]("slideId")
val num = column[Int]("num")
val urls = column[String]("urls")
val slideRevealed = column[Boolean]("slideRevealed")
@ -38,8 +42,10 @@ class PresPageDbTableDef(tag: Tag) extends Table[PresPageDbModel](tag, None, "pr
val heightRatio = column[Double]("heightRatio")
val width = column[Double]("width")
val height = column[Double]("height")
val viewBoxWidth = column[Double]("viewBoxWidth")
val viewBoxHeight = column[Double]("viewBoxHeight")
// val presentation = foreignKey("presentation_fk", presentationId, Presentations)(_.presentationId, onDelete = ForeignKeyAction.Cascade)
def * = (pageId, presentationId, podId, num, urls, slideRevealed, current, xOffset, yOffset, widthRatio, heightRatio, width, height) <> (PresPageDbModel.tupled, PresPageDbModel.unapply)
def * = (pageId, presentationId, podId, slideId, num, urls, slideRevealed, current, xOffset, yOffset, widthRatio, heightRatio, width, height, viewBoxWidth, viewBoxHeight) <> (PresPageDbModel.tupled, PresPageDbModel.unapply)
}
object PresPageDAO {
@ -64,10 +70,24 @@ object PresPageDAO {
"num" = ${presentation.num},
"widthRatio" = ${presentation.widthRatio},
"heightRatio" = ${presentation.heightRatio}
WHERE "presentationId" = ${presentationId}"""
WHERE "presentationId" = $presentationId"""
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated size on PresPage table")
case Failure(e) => DatabaseConnection.logger.debug(s"Error updating size on PresPage: $e")
}
}
def updateSlidePosition(presentationId: String, width: Double, height: Double, viewBoxWidth: Double, viewBoxHeight: Double) = {
DatabaseConnection.db.run(
sqlu"""UPDATE pres_page SET
"width" = $width,
"height" = $height,
"viewBoxWidth" = $viewBoxWidth,
"viewBoxHeight" = $viewBoxHeight
WHERE "presentationId" = $presentationId"""
).onComplete {
case Success(rowsAffected) => DatabaseConnection.logger.debug(s"$rowsAffected row(s) updated slide position on PresPage table")
case Failure(e) => DatabaseConnection.logger.debug(s"Error updating slide position on PresPage: $e")
}
}
}

View File

@ -51,6 +51,7 @@ object PresPresentationDAO {
pageId = page._2.id,
presentationId = presentation.id,
podId = podId,
slideId = "",
num = page._2.num,
urls = page._2.urls.toJson.asJsObject.compactPrint,
slideRevealed = page._2.current,
@ -60,7 +61,9 @@ object PresPresentationDAO {
widthRatio = page._2.widthRatio,
heightRatio = page._2.heightRatio,
width = 1,
height = 1
height = 1,
viewBoxWidth = 1,
viewBoxHeight = 1
)
)
}

View File

@ -292,6 +292,8 @@ class ReceivedJsonMsgHandlerActor(
routeGenericMsg[SetCurrentPagePubMsg](envelope, jsonNode)
case ResizeAndMovePagePubMsg.NAME =>
routeGenericMsg[ResizeAndMovePagePubMsg](envelope, jsonNode)
case AddSlidePositionsPubMsg.NAME =>
routeGenericMsg[AddSlidePositionsPubMsg](envelope, jsonNode)
case RemovePresentationPubMsg.NAME =>
routeGenericMsg[RemovePresentationPubMsg](envelope, jsonNode)
case SetPresentationDownloadablePubMsg.NAME =>

View File

@ -536,6 +536,7 @@ class MeetingActor(
case m: PresentationPageCountErrorSysPubMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)
case m: PresentationUploadTokenReqMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)
case m: ResizeAndMovePagePubMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)
case m: AddSlidePositionsPubMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)
case m: PresentationPageConvertedSysMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)
case m: PresentationPageConversionStartedSysMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)
case m: PresentationConversionEndedSysMsg => state = presentationPodsApp.handle(m, state, liveMeeting, msgBus)

View File

@ -40,6 +40,11 @@ case class ResizeAndMovePagePubMsg(header: BbbClientMsgHeader, body: ResizeAndMo
case class ResizeAndMovePagePubMsgBody(podId: String, presentationId: String, pageId: String, xOffset: Double,
yOffset: Double, widthRatio: Double, heightRatio: Double, slideNumber: Int)
object AddSlidePositionsPubMsg { val NAME = "AddSlidePositionsPubMsg" }
case class AddSlidePositionsPubMsg(header: BbbClientMsgHeader, body: AddSlidePositionsPubMsgBody) extends StandardMsg
case class AddSlidePositionsPubMsgBody(podId: String, presentationId: String, slideId: String, width: Double,
height: Double, viewBoxWidth: Double, viewBoxHeight: Double)
object SetCurrentPresentationPubMsg { val NAME = "SetCurrentPresentationPubMsg" }
case class SetCurrentPresentationPubMsg(header: BbbClientMsgHeader, body: SetCurrentPresentationPubMsgBody) extends StandardMsg
case class SetCurrentPresentationPubMsgBody(podId: String, presentationId: String)

View File

@ -842,6 +842,7 @@ CREATE TABLE "pres_page" (
"pageId" varchar(100) PRIMARY KEY,
"presentationId" varchar(100) REFERENCES "pres_presentation"("presentationId") ON DELETE CASCADE,
"podId" varchar(100),
"slideId" varchar(100),
"num" integer,
"urls" TEXT,
"slideRevealed" boolean default false,
@ -851,7 +852,9 @@ CREATE TABLE "pres_page" (
"widthRatio" NUMERIC,
"heightRatio" NUMERIC,
"width" NUMERIC,
"height" NUMERIC
"height" NUMERIC,
"viewBoxWidth" NUMERIC,
"viewBoxHeight" NUMERIC
);
CREATE INDEX "idx_pres_page_presentationId" ON "pres_page"("presentationId");
CREATE INDEX "idx_pres_page_presentationId_curr" ON "pres_page"("presentationId") where "current" is true;

View File

@ -1,4 +1,6 @@
import { SlidePositions } from '/imports/api/slides';
import { Meteor } from 'meteor/meteor';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import flat from 'flat';
@ -10,6 +12,10 @@ export default async function addSlidePositions(
slideId,
slidePosition,
) {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'AddSlidePositionsPubMsg';
check(meetingId, String);
check(podId, String);
check(presentationId, String);
@ -32,14 +38,14 @@ export default async function addSlidePositions(
};
const modifier = {
$set: Object.assign(
{ meetingId },
{ podId },
{ presentationId },
{ id: slideId },
flat(slidePosition),
{ safe: true },
),
$set: {
meetingId,
podId,
presentationId,
id: slideId,
...flat(slidePosition),
safe: true,
},
};
try {
@ -50,6 +56,23 @@ export default async function addSlidePositions(
} else {
Logger.info(`Upserted slide position id=${slideId} pod=${podId} presentation=${presentationId}`);
}
const {
width, height, viewBoxWidth, viewBoxHeight,
} = slidePosition;
const payload = {
podId,
presentationId,
slideId,
width,
height,
viewBoxWidth,
viewBoxHeight,
};
Logger.info('Sending slide position data to backen');
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, '', payload);
} catch (err) {
Logger.error(`Adding slide position to collection: ${err}`);
}