From e3c786905fb6484a42eb28751766c740f5215351 Mon Sep 17 00:00:00 2001
From: Sergey Morgunov
Date: Thu, 13 Jun 2024 18:39:12 +0300
Subject: [PATCH] Fix `play-scala-streaming-example`
(cherry picked from commit 1b64094d5fb4e6929348cd7d2a02d1fa7ea31747)
# Conflicts:
# play-scala-streaming-example/app/controllers/ScalaCometController.scala
---
.../app/controllers/HomeController.scala | 5 ++---
.../app/controllers/ScalaCometController.scala | 9 +++++----
.../app/controllers/ScalaEventSourceController.scala | 4 ++--
play-scala-streaming-example/app/views/index.scala.html | 2 +-
play-scala-streaming-example/app/views/main.scala.html | 4 ++--
.../app/views/scalacomet.scala.html | 6 ++++--
.../app/views/scalaeventsource.scala.html | 4 +++-
play-scala-streaming-example/build.sbt | 4 ++++
8 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/play-scala-streaming-example/app/controllers/HomeController.scala b/play-scala-streaming-example/app/controllers/HomeController.scala
index 73b2e8251..0618cbe3f 100644
--- a/play-scala-streaming-example/app/controllers/HomeController.scala
+++ b/play-scala-streaming-example/app/controllers/HomeController.scala
@@ -1,12 +1,11 @@
package controllers
import javax.inject.Inject
-
-import play.api.mvc.{AbstractController, ControllerComponents}
+import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents, RequestHeader}
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
- def index() = Action {
+ def index(): Action[AnyContent] = Action { implicit request =>
Ok(views.html.index())
}
diff --git a/play-scala-streaming-example/app/controllers/ScalaCometController.scala b/play-scala-streaming-example/app/controllers/ScalaCometController.scala
index 90e2a1c0b..fb7879c6f 100644
--- a/play-scala-streaming-example/app/controllers/ScalaCometController.scala
+++ b/play-scala-streaming-example/app/controllers/ScalaCometController.scala
@@ -6,16 +6,17 @@ import akka.stream.Materializer
import play.api.http.ContentTypes
import play.api.libs.Comet
import play.api.mvc._
+import views.html.helper.CSPNonce
@Singleton
-class ScalaCometController @Inject() (cc: ControllerComponents, materializer: Materializer) extends AbstractController(cc)
+class ScalaCometController @Inject()(cc: ControllerComponents, materializer: Materializer) extends AbstractController(cc)
with ScalaTicker {
- def index() = Action {
+ def index(): Action[AnyContent] = Action { implicit request =>
Ok(views.html.scalacomet())
}
- def streamClock() = Action {
- Ok.chunked(stringSource via Comet.string("parent.clockChanged")).as(ContentTypes.HTML)
+ def streamClock(): Action[AnyContent] = Action { implicit request =>
+ Ok.chunked(stringSource.via(Comet.string("parent.clockChanged", CSPNonce()))).as(ContentTypes.HTML)
}
}
diff --git a/play-scala-streaming-example/app/controllers/ScalaEventSourceController.scala b/play-scala-streaming-example/app/controllers/ScalaEventSourceController.scala
index 8a5971c24..48337371f 100644
--- a/play-scala-streaming-example/app/controllers/ScalaEventSourceController.scala
+++ b/play-scala-streaming-example/app/controllers/ScalaEventSourceController.scala
@@ -9,11 +9,11 @@ import play.api.mvc._
@Singleton
class ScalaEventSourceController @Inject()(cc: ControllerComponents) extends AbstractController(cc) with ScalaTicker {
- def index() = Action {
+ def index(): Action[AnyContent] = Action { implicit request =>
Ok(views.html.scalaeventsource())
}
- def streamClock() = Action {
+ def streamClock(): Action[AnyContent] = Action { implicit request =>
Ok.chunked(stringSource via EventSource.flow).as(ContentTypes.EVENT_STREAM)
}
diff --git a/play-scala-streaming-example/app/views/index.scala.html b/play-scala-streaming-example/app/views/index.scala.html
index d6203ffa7..da4e9eef8 100644
--- a/play-scala-streaming-example/app/views/index.scala.html
+++ b/play-scala-streaming-example/app/views/index.scala.html
@@ -1,4 +1,4 @@
-@()
+@()(implicit request: RequestHeader)
@main {
diff --git a/play-scala-streaming-example/app/views/main.scala.html b/play-scala-streaming-example/app/views/main.scala.html
index 854198f59..1415b965a 100644
--- a/play-scala-streaming-example/app/views/main.scala.html
+++ b/play-scala-streaming-example/app/views/main.scala.html
@@ -1,4 +1,4 @@
-@(content: Html)
+@(content: Html)(implicit request: RequestHeader)
@@ -7,7 +7,7 @@
EventSource clock
-
+
@content
diff --git a/play-scala-streaming-example/app/views/scalacomet.scala.html b/play-scala-streaming-example/app/views/scalacomet.scala.html
index 6005c4048..05c3ee6a9 100644
--- a/play-scala-streaming-example/app/views/scalacomet.scala.html
+++ b/play-scala-streaming-example/app/views/scalacomet.scala.html
@@ -1,3 +1,5 @@
+@()(implicit request: RequestHeader)
+
@main {
Comet clock
@@ -8,13 +10,13 @@
Clock events are pushed from the Server using a Comet connection.
-
-
+
}
diff --git a/play-scala-streaming-example/app/views/scalaeventsource.scala.html b/play-scala-streaming-example/app/views/scalaeventsource.scala.html
index 80b40162a..0adf9975d 100644
--- a/play-scala-streaming-example/app/views/scalaeventsource.scala.html
+++ b/play-scala-streaming-example/app/views/scalaeventsource.scala.html
@@ -1,3 +1,5 @@
+@()(implicit request: RequestHeader)
+
@main {
Server Sent Event clock
@@ -8,7 +10,7 @@
Clock events are pushed from the Server using a Server Sent Event connection.
-