From ae07ed303a054c3f5679e937a026eb43a029fc1c Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Sun, 30 May 2021 00:37:23 +0900 Subject: [PATCH 1/9] refactor: react warning --- jam-client/src/components/pages/Lobby.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/jam-client/src/components/pages/Lobby.tsx b/jam-client/src/components/pages/Lobby.tsx index 34d819c..b3d3b06 100644 --- a/jam-client/src/components/pages/Lobby.tsx +++ b/jam-client/src/components/pages/Lobby.tsx @@ -151,6 +151,7 @@ export const Lobby: React.FC = ({ userName }) => { if (userName != user.name) { return ( Date: Sun, 30 May 2021 00:38:47 +0900 Subject: [PATCH 2/9] refactor: ts warning --- jam-client/src/components/pages/Lobby.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jam-client/src/components/pages/Lobby.tsx b/jam-client/src/components/pages/Lobby.tsx index b3d3b06..7156e7f 100644 --- a/jam-client/src/components/pages/Lobby.tsx +++ b/jam-client/src/components/pages/Lobby.tsx @@ -1,7 +1,7 @@ import React, { useState, useEffect, useRef } from 'react'; import { Stage } from '@inlet/react-pixi'; import Sockette from 'sockette'; -import { Myself, Participant } from 'components/molecules'; +import { Myself, Participant } from '../molecules'; import { Position } from 'models'; interface Props { From fa22bacebd7d70145fa10b43853d94582c84f1d4 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Sun, 30 May 2021 01:04:33 +0900 Subject: [PATCH 3/9] feat: init openvidu session --- jam-client/src/components/pages/Lobby.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/jam-client/src/components/pages/Lobby.tsx b/jam-client/src/components/pages/Lobby.tsx index 7156e7f..e75239a 100644 --- a/jam-client/src/components/pages/Lobby.tsx +++ b/jam-client/src/components/pages/Lobby.tsx @@ -3,6 +3,7 @@ import { Stage } from '@inlet/react-pixi'; import Sockette from 'sockette'; import { Myself, Participant } from '../molecules'; import { Position } from 'models'; +import { OpenVidu, Session } from 'openvidu-browser'; interface Props { userName: string; @@ -30,6 +31,9 @@ export const Lobby: React.FC = ({ userName }) => { const [users, setUsers] = useState([]); const [message, setMessage] = useState(''); const [isTyping, setIsTyping] = useState(false); + + const ovRef = useRef(); + const sessionRef = useRef(); const wsRef = useRef(); const inputRef = useRef(null); @@ -104,11 +108,15 @@ export const Lobby: React.FC = ({ userName }) => { document.addEventListener('keydown', keyDown); + ovRef.current = new OpenVidu(); + sessionRef.current = ovRef.current.initSession(); + return () => { console.log('Disconnecting..'); - if (wsRef.current) wsRef.current.close(); - document.removeEventListener('keydown', keyDown); + if (sessionRef.current) sessionRef.current.disconnect(); + if (ovRef.current) ovRef.current = undefined; + if (wsRef.current) wsRef.current.close(); }; }, []); From d2e0a5b8481c4d44a99bcbb2023a5b5dd5463f33 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Sun, 30 May 2021 13:37:39 +0900 Subject: [PATCH 4/9] feat: add zio --- build.sbt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build.sbt b/build.sbt index 75f4250..cc54122 100644 --- a/build.sbt +++ b/build.sbt @@ -16,6 +16,9 @@ lazy val commonSettings = Seq( "-Xlint", "-Xfatal-warnings" ), + libraryDependencies ++= Seq( + "dev.zio" %% "zio" % "1.0.8" + ), // scalafix addCompilerPlugin(scalafixSemanticdb), semanticdbEnabled := true, From 95564d9d1afc63f196c2e7a9b59f16a6d4ec29d0 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Tue, 1 Jun 2021 21:22:49 +0900 Subject: [PATCH 5/9] chore: setup domain layer --- build.sbt | 17 ++++++++++++++++- .../main/scala/jam}/domain/models/Room.scala | 2 +- .../main/scala/jam/domain/models/Session.scala | 3 +++ .../main/scala/jam/domain/models/Token.scala | 3 +++ .../main/scala/jam}/domain/models/User.scala | 2 +- .../scala/jam}/domain/models/UserCommand.scala | 2 +- jam-server/app/actors/RoomRequestActor.scala | 2 +- jam-server/app/actors/RoomResponseActor.scala | 3 ++- .../app/controllers/WebSocketsController.scala | 3 +-- jam-server/app/formatters/PlayJsonFormats.scala | 2 +- jam-server/app/infrastructure/RoomChannel.scala | 2 +- .../infrastructure/RoomRepositoryOnMemory.scala | 3 +-- jam-server/app/services/RoomRepository.scala | 2 +- jam-server/app/services/RoomService.scala | 3 +-- 14 files changed, 34 insertions(+), 15 deletions(-) rename {jam-server/app => jam-domain/src/main/scala/jam}/domain/models/Room.scala (79%) create mode 100644 jam-domain/src/main/scala/jam/domain/models/Session.scala create mode 100644 jam-domain/src/main/scala/jam/domain/models/Token.scala rename {jam-server/app => jam-domain/src/main/scala/jam}/domain/models/User.scala (89%) rename {jam-server/app => jam-domain/src/main/scala/jam}/domain/models/UserCommand.scala (93%) diff --git a/build.sbt b/build.sbt index cc54122..ad12530 100644 --- a/build.sbt +++ b/build.sbt @@ -42,6 +42,13 @@ lazy val playCommonSettings = Seq( } ) +lazy val domain = (project in file("jam-domain")) + .settings(commonSettings) + +lazy val application = (project in file("jam-application")) + .settings(commonSettings) + .dependsOn(domain) + lazy val server = (project in file("jam-server")) .enablePlugins(PlayScala) .settings(commonSettings) @@ -66,6 +73,9 @@ lazy val server = (project in file("jam-server")) .settings( devSettings := Map("play.server.http.port" -> "9000").toSeq ) + .dependsOn(domain) + .dependsOn(application) + .dependsOn(infrastructure) lazy val infrastructure = (project in file("jam-infrastructure")) .settings(commonSettings) @@ -76,13 +86,18 @@ lazy val infrastructure = (project in file("jam-infrastructure")) "io.openvidu" % "openvidu-java-client" % "2.17.0" ) ) + .dependsOn(domain) + .dependsOn(application) lazy val root = (project in file(".")) .settings(commonSettings) .settings( Compile / run := (server / Compile / run).evaluated ) - .aggregate(server, infrastructure) + .aggregate(domain) + .aggregate(application) + .aggregate(infrastructure) + .aggregate(server) addCommandAlias("fixAll", "scalafixAll; scalafmtAll; scalafmtSbt") addCommandAlias("checkAll", "scalafixAll --check; scalafmtCheckAll; scalafmtSbtCheck") diff --git a/jam-server/app/domain/models/Room.scala b/jam-domain/src/main/scala/jam/domain/models/Room.scala similarity index 79% rename from jam-server/app/domain/models/Room.scala rename to jam-domain/src/main/scala/jam/domain/models/Room.scala index 93f329e..a612d15 100644 --- a/jam-server/app/domain/models/Room.scala +++ b/jam-domain/src/main/scala/jam/domain/models/Room.scala @@ -1,4 +1,4 @@ -package domain.models +package jam.domain.models case class Room(name: RoomName, users: Set[User]) diff --git a/jam-domain/src/main/scala/jam/domain/models/Session.scala b/jam-domain/src/main/scala/jam/domain/models/Session.scala new file mode 100644 index 0000000..75871e7 --- /dev/null +++ b/jam-domain/src/main/scala/jam/domain/models/Session.scala @@ -0,0 +1,3 @@ +package jam.domain.models + +case class Session(id: String) extends AnyVal diff --git a/jam-domain/src/main/scala/jam/domain/models/Token.scala b/jam-domain/src/main/scala/jam/domain/models/Token.scala new file mode 100644 index 0000000..d27f959 --- /dev/null +++ b/jam-domain/src/main/scala/jam/domain/models/Token.scala @@ -0,0 +1,3 @@ +package jam.domain.models + +case class Token() diff --git a/jam-server/app/domain/models/User.scala b/jam-domain/src/main/scala/jam/domain/models/User.scala similarity index 89% rename from jam-server/app/domain/models/User.scala rename to jam-domain/src/main/scala/jam/domain/models/User.scala index d59395f..c5d5f76 100644 --- a/jam-server/app/domain/models/User.scala +++ b/jam-domain/src/main/scala/jam/domain/models/User.scala @@ -1,4 +1,4 @@ -package domain.models +package jam.domain.models case class User(name: UserName, position: Position) diff --git a/jam-server/app/domain/models/UserCommand.scala b/jam-domain/src/main/scala/jam/domain/models/UserCommand.scala similarity index 93% rename from jam-server/app/domain/models/UserCommand.scala rename to jam-domain/src/main/scala/jam/domain/models/UserCommand.scala index e9d8388..0cf923f 100644 --- a/jam-server/app/domain/models/UserCommand.scala +++ b/jam-domain/src/main/scala/jam/domain/models/UserCommand.scala @@ -1,4 +1,4 @@ -package domain.models +package jam.domain.models sealed trait UserCommand diff --git a/jam-server/app/actors/RoomRequestActor.scala b/jam-server/app/actors/RoomRequestActor.scala index 93ee529..da9563a 100644 --- a/jam-server/app/actors/RoomRequestActor.scala +++ b/jam-server/app/actors/RoomRequestActor.scala @@ -1,8 +1,8 @@ package actors import akka.actor.{Actor, ActorRef, Props} -import domain.models.{Position, Room, RoomName, User, UserCommand, UserName} import infrastructure.RedisClient +import jam.domain.models.{Position, Room, RoomName, User, UserCommand, UserName} import play.api.libs.json.{JsValue, Json} class RoomRequestActor(out: ActorRef, redis: RedisClient, roomName: RoomName, userName: UserName) diff --git a/jam-server/app/actors/RoomResponseActor.scala b/jam-server/app/actors/RoomResponseActor.scala index 0067af7..6fc0b08 100644 --- a/jam-server/app/actors/RoomResponseActor.scala +++ b/jam-server/app/actors/RoomResponseActor.scala @@ -1,8 +1,9 @@ package actors import akka.actor.{Actor, ActorRef, PoisonPill, Props} -import domain.models.{User, UserName} +import domain.models.UserName import infrastructure.RedisClient +import jam.domain.models.{User, UserName} import play.api.libs.json.Json class RoomResponseActor(out: ActorRef, redisClient: RedisClient, myself: UserName) extends Actor { diff --git a/jam-server/app/controllers/WebSocketsController.scala b/jam-server/app/controllers/WebSocketsController.scala index f382ae3..5082aa4 100644 --- a/jam-server/app/controllers/WebSocketsController.scala +++ b/jam-server/app/controllers/WebSocketsController.scala @@ -1,12 +1,11 @@ package controllers import javax.inject._ - import actors.{RoomRequestActor, RoomResponseActor} import akka.actor.ActorSystem import akka.stream.scaladsl._ -import domain.models.{RoomName, UserCommand, UserName} import infrastructure.RedisClient +import jam.domain.models.{RoomName, UserCommand, UserName} import play.api.libs.json.JsValue import play.api.libs.streams.ActorFlow import play.api.mvc._ diff --git a/jam-server/app/formatters/PlayJsonFormats.scala b/jam-server/app/formatters/PlayJsonFormats.scala index 0df9788..0f6d6d3 100644 --- a/jam-server/app/formatters/PlayJsonFormats.scala +++ b/jam-server/app/formatters/PlayJsonFormats.scala @@ -1,6 +1,6 @@ package formatters -import domain.models.{Position, User, UserCommand, UserName} +import jam.domain.models.{Position, User, UserCommand, UserName} import play.api.libs.functional.syntax._ import play.api.libs.json._ diff --git a/jam-server/app/infrastructure/RoomChannel.scala b/jam-server/app/infrastructure/RoomChannel.scala index f55c8f2..24b74b5 100644 --- a/jam-server/app/infrastructure/RoomChannel.scala +++ b/jam-server/app/infrastructure/RoomChannel.scala @@ -2,7 +2,7 @@ package infrastructure import akka.NotUsed import akka.stream.scaladsl.{Sink, Source} -import domain.models.UserCommand +import jam.domain.models.UserCommand case class RoomChannel( sink: Sink[UserCommand, NotUsed], diff --git a/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala b/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala index 83e0bdd..778e4a8 100644 --- a/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala +++ b/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala @@ -2,11 +2,10 @@ package infrastructure import java.util.concurrent.atomic.AtomicReference import javax.inject.{Inject, Singleton} - import akka.actor.ActorSystem import akka.stream.scaladsl.{BroadcastHub, Flow, Keep, MergeHub, Sink} import akka.stream.{KillSwitches, Materializer, UniqueKillSwitch} -import domain.models.{Room, RoomName, UserCommand, UserName} +import jam.domain.models.{Room, RoomName, UserCommand, UserName} import services.{RoomInfo, RoomRepository} import scala.collection.mutable diff --git a/jam-server/app/services/RoomRepository.scala b/jam-server/app/services/RoomRepository.scala index 52b3cbe..7aeda1a 100644 --- a/jam-server/app/services/RoomRepository.scala +++ b/jam-server/app/services/RoomRepository.scala @@ -2,7 +2,7 @@ package services import akka.stream.UniqueKillSwitch import akka.stream.scaladsl.Flow -import domain.models.{Room, RoomName, UserCommand, UserName} +import jam.domain.models.{Room, RoomName, UserCommand, UserName} case class RoomInfo(room: Room, bus: Flow[UserCommand, UserCommand, UniqueKillSwitch]) diff --git a/jam-server/app/services/RoomService.scala b/jam-server/app/services/RoomService.scala index 4c80068..0ebd92b 100644 --- a/jam-server/app/services/RoomService.scala +++ b/jam-server/app/services/RoomService.scala @@ -1,8 +1,7 @@ package services import javax.inject.{Inject, Singleton} - -import domain.models.{RoomName, UserName} +import jam.domain.models.{RoomName, UserName} @Singleton class RoomService @Inject() (roomRepository: RoomRepository) { From 9502dd0f7ec575b860719bc98dd05754e32c3787 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Wed, 2 Jun 2021 00:14:34 +0900 Subject: [PATCH 6/9] fix: compile error --- jam-server/app/actors/RoomResponseActor.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jam-server/app/actors/RoomResponseActor.scala b/jam-server/app/actors/RoomResponseActor.scala index 05eebe7..3b705ec 100644 --- a/jam-server/app/actors/RoomResponseActor.scala +++ b/jam-server/app/actors/RoomResponseActor.scala @@ -1,14 +1,13 @@ package actors import akka.actor.{Actor, ActorRef, PoisonPill, Props} -import domain.models.UserName import infrastructure.RedisClient import jam.domain.models.{User, UserName} import play.api.libs.json.Json class RoomResponseActor(out: ActorRef, redisClient: RedisClient, myself: UserName) extends Actor { import formatters.PlayJsonFormats._ - import domain.models.UserCommand._ + import jam.domain.models.UserCommand._ private val logger = play.api.Logger(getClass) From 10c24d6ec8146f13fc95f68101d786c78b8c49b0 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Wed, 2 Jun 2021 01:18:38 +0900 Subject: [PATCH 7/9] chore: update sbt to version 1.5.3 --- project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/build.properties b/project/build.properties index 41aaafe..3114321 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.5.2 \ No newline at end of file +sbt.version=1.5.3 \ No newline at end of file From ef11a52013f8c86198757b7817bcc3340be89c05 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Sun, 13 Jun 2021 22:22:02 +0900 Subject: [PATCH 8/9] chore: install eff --- build.sbt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/build.sbt b/build.sbt index 7ff80f2..ae0a27c 100644 --- a/build.sbt +++ b/build.sbt @@ -17,8 +17,10 @@ lazy val commonSettings = Seq( "-Xfatal-warnings" ), libraryDependencies ++= Seq( - "dev.zio" %% "zio" % "1.0.8" + "org.atnos" %% "eff" % "5.18.0", + "io.circe" %% "circe-generic" % "0.14.1" ), + addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.0" cross CrossVersion.full), // scalafix addCompilerPlugin(scalafixSemanticdb), semanticdbEnabled := true, @@ -80,11 +82,14 @@ lazy val server = (project in file("jam-server")) lazy val infrastructure = (project in file("jam-infrastructure")) .settings(commonSettings) .settings( - libraryDependencies ++= Seq( - "com.google.code.gson" % "gson" % "2.8.7", - "org.slf4j" % "slf4j-api" % "1.7.30", - "io.openvidu" % "openvidu-java-client" % "2.17.0" - ) + libraryDependencies ++= { + val sttpVersion = "3.3.5" + Seq( + "com.softwaremill.sttp.client3" %% "core" % sttpVersion, + "com.softwaremill.sttp.client3" %% "async-http-client-backend-zio" % sttpVersion, + "com.softwaremill.sttp.client3" %% "circe" % sttpVersion + ) + } ) .dependsOn(domain) .dependsOn(application) From 830ff01d19bd04844d9158052aa3cfc75d4ecec8 Mon Sep 17 00:00:00 2001 From: Shoma Nishitateno Date: Thu, 29 Jul 2021 18:54:51 +0900 Subject: [PATCH 9/9] wip: sttp http interpreter --- .../application/effects/http/Credential.scala | 4 +++ .../application/effects/http/HttpEffect.scala | 21 +++++------ .../application/effects/http/HttpParam.scala | 3 ++ .../application/services/WebRtcService.scala | 17 +++++++++ .../http/SttpHttpInterpreter.scala | 9 +++-- .../openvidu/CirceJsonFormats.scala | 13 +++++++ .../openvidu/WebRtcServiceOnOpenVidu.scala | 36 +++++++++++++++++++ jam-server/app/actors/RoomRequestActor.scala | 3 +- jam-server/app/actors/RoomResponseActor.scala | 3 +- .../controllers/WebSocketsController.scala | 4 ++- .../app/formatters/PlayJsonFormats.scala | 3 +- .../app/infrastructure/RoomChannel.scala | 1 + .../RoomRepositoryOnMemory.scala | 4 ++- jam-server/app/services/RoomRepository.scala | 1 + jam-server/app/services/RoomService.scala | 1 + 15 files changed, 102 insertions(+), 21 deletions(-) create mode 100644 jam-application/src/main/scala/jam/application/effects/http/Credential.scala rename jam-infrastructure/src/main/scala/jam/infrastructure/http/HttpDSL.scala => jam-application/src/main/scala/jam/application/effects/http/HttpEffect.scala (51%) create mode 100644 jam-application/src/main/scala/jam/application/effects/http/HttpParam.scala create mode 100644 jam-application/src/main/scala/jam/application/services/WebRtcService.scala create mode 100644 jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/CirceJsonFormats.scala create mode 100644 jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/WebRtcServiceOnOpenVidu.scala diff --git a/jam-application/src/main/scala/jam/application/effects/http/Credential.scala b/jam-application/src/main/scala/jam/application/effects/http/Credential.scala new file mode 100644 index 0000000..69fc1dd --- /dev/null +++ b/jam-application/src/main/scala/jam/application/effects/http/Credential.scala @@ -0,0 +1,4 @@ +package jam.application.effects.http + +sealed trait Credential +case class BasicCredential(username: String, password: String) extends Credential diff --git a/jam-infrastructure/src/main/scala/jam/infrastructure/http/HttpDSL.scala b/jam-application/src/main/scala/jam/application/effects/http/HttpEffect.scala similarity index 51% rename from jam-infrastructure/src/main/scala/jam/infrastructure/http/HttpDSL.scala rename to jam-application/src/main/scala/jam/application/effects/http/HttpEffect.scala index 2835071..ac73cfe 100644 --- a/jam-infrastructure/src/main/scala/jam/infrastructure/http/HttpDSL.scala +++ b/jam-application/src/main/scala/jam/application/effects/http/HttpEffect.scala @@ -1,31 +1,26 @@ -package jam.infrastructure.http +package jam.application.effects.http import io.circe._ import org.atnos.eff._ -case class HttpParam(url: String, credential: Credential) - -sealed trait Credential -case class BasicCredential(username: String, password: String) extends Credential - -sealed trait HttpDSL[+A] -case class Get[A](param: HttpParam, decoder: Decoder[A]) extends HttpDSL[A] +sealed trait HttpEffect[+A] +case class Get[A](param: HttpParam, decoder: Decoder[A]) extends HttpEffect[A] case class Post[A1, A2]( param: HttpParam, data: A1, encoder: Encoder[A1], decoder: Decoder[A2] -) extends HttpDSL[A2] +) extends HttpEffect[A2] -object HttpDSL { - type _http[R] = HttpDSL |= R +object HttpEffect { + type _http[R] = HttpEffect |= R def get[A, R: _http](param: HttpParam)(implicit decoder: Decoder[A]): Eff[R, A] = - Eff.send[HttpDSL, R, A](Get(param, decoder)) + Eff.send[HttpEffect, R, A](Get(param, decoder)) def post[A1, A2, R: _http](param: HttpParam, data: A1)(implicit encoder: Encoder[A1], decoder: Decoder[A2] ): Eff[R, A2] = - Eff.send[HttpDSL, R, A2](Post(param, data, encoder, decoder)) + Eff.send[HttpEffect, R, A2](Post(param, data, encoder, decoder)) } diff --git a/jam-application/src/main/scala/jam/application/effects/http/HttpParam.scala b/jam-application/src/main/scala/jam/application/effects/http/HttpParam.scala new file mode 100644 index 0000000..8a75831 --- /dev/null +++ b/jam-application/src/main/scala/jam/application/effects/http/HttpParam.scala @@ -0,0 +1,3 @@ +package jam.application.effects.http + +case class HttpParam(url: String, credential: Credential) diff --git a/jam-application/src/main/scala/jam/application/services/WebRtcService.scala b/jam-application/src/main/scala/jam/application/services/WebRtcService.scala new file mode 100644 index 0000000..cbea987 --- /dev/null +++ b/jam-application/src/main/scala/jam/application/services/WebRtcService.scala @@ -0,0 +1,17 @@ +package jam.application.services + +import jam.domain.models.{Session, Token} + +trait WebRtcService { + def createSession(id: String): Session + def getToken(session: Session): Token +} + +object WebRtcService { + +// def createSession(id: String): ZIO[WebRtcService, Nothing, Session] = +// ZIO.accessM(env => IO.effectTotal(env.createSession(id))) +// +// def getToken(session: Session): ZIO[WebRtcService, Nothing, Token] = +// ZIO.accessM(env => IO.effectTotal(env.getToken(session))) +} diff --git a/jam-infrastructure/src/main/scala/jam/infrastructure/http/SttpHttpInterpreter.scala b/jam-infrastructure/src/main/scala/jam/infrastructure/http/SttpHttpInterpreter.scala index 393619a..290a80e 100644 --- a/jam-infrastructure/src/main/scala/jam/infrastructure/http/SttpHttpInterpreter.scala +++ b/jam-infrastructure/src/main/scala/jam/infrastructure/http/SttpHttpInterpreter.scala @@ -7,16 +7,19 @@ import org.atnos.eff.all.fromEither import sttp.client3.circe._ import sttp.client3.{ResponseException, _} +import jam.application.effects.http._ + object SttpHttpInterpreter { + type _either[R] = Either[ResponseException[String, Error], *] |= R def run[R, U, A]( effects: Eff[R, A] - )(implicit m: Member.Aux[HttpDSL, R, U], either: _either[U]): Eff[U, A] = - translate(effects)(new Translate[HttpDSL, U] { + )(implicit m: Member.Aux[HttpEffect, R, U], either: _either[U]): Eff[U, A] = + translate(effects)(new Translate[HttpEffect, U] { private val backend = HttpURLConnectionBackend() - override def apply[X](kv: HttpDSL[X]): Eff[U, X] = { + override def apply[X](kv: HttpEffect[X]): Eff[U, X] = { val result = kv match { case Get(param, decoder) => get(param)(decoder).send(backend).body diff --git a/jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/CirceJsonFormats.scala b/jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/CirceJsonFormats.scala new file mode 100644 index 0000000..b007131 --- /dev/null +++ b/jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/CirceJsonFormats.scala @@ -0,0 +1,13 @@ +package jam.infrastructure.openvidu + +//import io.circe._ +// +//import java.time.{Instant, ZonedDateTime} +//import scala.util.Try + +object CirceJsonFormats { +// implicit val decodeZonedDateTim: Decoder[ZonedDateTime] = Decoder.decodeZonedDateTime.emapTry { +// str => +// Try(Instant.parse(str)) +// } +} diff --git a/jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/WebRtcServiceOnOpenVidu.scala b/jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/WebRtcServiceOnOpenVidu.scala new file mode 100644 index 0000000..2cc3065 --- /dev/null +++ b/jam-infrastructure/src/main/scala/jam/infrastructure/openvidu/WebRtcServiceOnOpenVidu.scala @@ -0,0 +1,36 @@ +package jam.infrastructure.openvidu + +//import jam.application.services.WebRtcService +//import jam.domain.models.{Session, Token} +//import sttp.client3._ +//import sttp.client3.circe._ +//import io.circe.generic.auto._ +//import sttp.client3.asynchttpclient.zio._ + +import java.time.ZonedDateTime + +object WebRtcServiceOnOpenVidu { +// import CirceJsonFormats._ + +// private val resource = s"$baseUrl/api/sessions" + +// def live(baseUrl: String, username: String, password: String): WebRtcService = +// new WebRtcService { +// private val request = basicRequest.auth.basic(username, password) +// +// override def createSession(id: String): Session = { +// val req = request +// .post(uri"$resource") +// .body(InitializeSession(id)) +// .response(asJson[InitializedSession]) +// +// send(req) +// } +// +// override def getToken(session: Session): Token = +// ??? +// } +} + +private[openvidu] case class InitializeSession(customSessionId: String) +private[openvidu] case class InitializedSession(id: String, createdAt: ZonedDateTime) diff --git a/jam-server/app/actors/RoomRequestActor.scala b/jam-server/app/actors/RoomRequestActor.scala index c4173a8..79cebeb 100644 --- a/jam-server/app/actors/RoomRequestActor.scala +++ b/jam-server/app/actors/RoomRequestActor.scala @@ -2,9 +2,10 @@ package actors import akka.actor.{Actor, ActorRef, Props} import infrastructure.RedisClient -import jam.domain.models.{Position, Room, RoomName, User, UserCommand, UserName} import play.api.libs.json.{JsValue, Json} +import jam.domain.models.{Position, Room, RoomName, User, UserCommand, UserName} + class RoomRequestActor(out: ActorRef, redis: RedisClient, roomName: RoomName, userName: UserName) extends Actor { import formatters.PlayJsonFormats._ diff --git a/jam-server/app/actors/RoomResponseActor.scala b/jam-server/app/actors/RoomResponseActor.scala index 3b705ec..5ea693d 100644 --- a/jam-server/app/actors/RoomResponseActor.scala +++ b/jam-server/app/actors/RoomResponseActor.scala @@ -2,9 +2,10 @@ package actors import akka.actor.{Actor, ActorRef, PoisonPill, Props} import infrastructure.RedisClient -import jam.domain.models.{User, UserName} import play.api.libs.json.Json +import jam.domain.models.{User, UserName} + class RoomResponseActor(out: ActorRef, redisClient: RedisClient, myself: UserName) extends Actor { import formatters.PlayJsonFormats._ import jam.domain.models.UserCommand._ diff --git a/jam-server/app/controllers/WebSocketsController.scala b/jam-server/app/controllers/WebSocketsController.scala index 5082aa4..6fa8701 100644 --- a/jam-server/app/controllers/WebSocketsController.scala +++ b/jam-server/app/controllers/WebSocketsController.scala @@ -1,16 +1,18 @@ package controllers import javax.inject._ + import actors.{RoomRequestActor, RoomResponseActor} import akka.actor.ActorSystem import akka.stream.scaladsl._ import infrastructure.RedisClient -import jam.domain.models.{RoomName, UserCommand, UserName} import play.api.libs.json.JsValue import play.api.libs.streams.ActorFlow import play.api.mvc._ import services.RoomService +import jam.domain.models.{RoomName, UserCommand, UserName} + @Singleton class WebSocketsController @Inject() ( val controllerComponents: ControllerComponents, diff --git a/jam-server/app/formatters/PlayJsonFormats.scala b/jam-server/app/formatters/PlayJsonFormats.scala index 0f6d6d3..6285939 100644 --- a/jam-server/app/formatters/PlayJsonFormats.scala +++ b/jam-server/app/formatters/PlayJsonFormats.scala @@ -1,9 +1,10 @@ package formatters -import jam.domain.models.{Position, User, UserCommand, UserName} import play.api.libs.functional.syntax._ import play.api.libs.json._ +import jam.domain.models.{Position, User, UserCommand, UserName} + object PlayJsonFormats { import UserCommand._ diff --git a/jam-server/app/infrastructure/RoomChannel.scala b/jam-server/app/infrastructure/RoomChannel.scala index 24b74b5..073cf52 100644 --- a/jam-server/app/infrastructure/RoomChannel.scala +++ b/jam-server/app/infrastructure/RoomChannel.scala @@ -2,6 +2,7 @@ package infrastructure import akka.NotUsed import akka.stream.scaladsl.{Sink, Source} + import jam.domain.models.UserCommand case class RoomChannel( diff --git a/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala b/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala index 778e4a8..2f21d26 100644 --- a/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala +++ b/jam-server/app/infrastructure/RoomRepositoryOnMemory.scala @@ -2,12 +2,14 @@ package infrastructure import java.util.concurrent.atomic.AtomicReference import javax.inject.{Inject, Singleton} + import akka.actor.ActorSystem import akka.stream.scaladsl.{BroadcastHub, Flow, Keep, MergeHub, Sink} import akka.stream.{KillSwitches, Materializer, UniqueKillSwitch} -import jam.domain.models.{Room, RoomName, UserCommand, UserName} import services.{RoomInfo, RoomRepository} +import jam.domain.models.{Room, RoomName, UserCommand, UserName} + import scala.collection.mutable import scala.concurrent.duration._ diff --git a/jam-server/app/services/RoomRepository.scala b/jam-server/app/services/RoomRepository.scala index 7aeda1a..4dd6fde 100644 --- a/jam-server/app/services/RoomRepository.scala +++ b/jam-server/app/services/RoomRepository.scala @@ -2,6 +2,7 @@ package services import akka.stream.UniqueKillSwitch import akka.stream.scaladsl.Flow + import jam.domain.models.{Room, RoomName, UserCommand, UserName} case class RoomInfo(room: Room, bus: Flow[UserCommand, UserCommand, UniqueKillSwitch]) diff --git a/jam-server/app/services/RoomService.scala b/jam-server/app/services/RoomService.scala index 0ebd92b..8607715 100644 --- a/jam-server/app/services/RoomService.scala +++ b/jam-server/app/services/RoomService.scala @@ -1,6 +1,7 @@ package services import javax.inject.{Inject, Singleton} + import jam.domain.models.{RoomName, UserName} @Singleton