Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d31b2f6
Showing
9 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
logs/ | ||
target/ | ||
RUNNING_PID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package lichess.ws | ||
|
||
import akka.actor._ | ||
import play.api.libs.json._ | ||
|
||
final class SiteClientActor(out: ActorRef) extends Actor { | ||
|
||
def receive = { | ||
case Ping => send(Pong) | ||
case msg: JsValue => send(JsString("Got: " + msg)) | ||
} | ||
|
||
val Ping = JsNull | ||
val Pong = JsNumber(0) | ||
|
||
def send(msg: JsValue) = out ! msg | ||
} | ||
|
||
object SiteClientActor { | ||
|
||
def props(out: ActorRef) = Props(new SiteClientActor(out)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package controllers | ||
|
||
import javax.inject._ | ||
|
||
import akka.actor._ | ||
import akka.event.Logging | ||
import akka.stream.Materializer | ||
import play.api.libs.streams.ActorFlow | ||
import play.api.Logger | ||
import play.api.mvc._ | ||
import play.api.libs.json._ | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
import lichess.ws._ | ||
|
||
@Singleton | ||
class SocketController @Inject() (val controllerComponents: ControllerComponents)(implicit | ||
actorSystem: ActorSystem, | ||
mat: Materializer, | ||
executionContext: ExecutionContext | ||
) extends BaseController { | ||
|
||
private type WSMessage = JsValue | ||
private val logger = Logger(getClass) | ||
|
||
def site(): WebSocket = | ||
WebSocket.accept[WSMessage, WSMessage] { req => | ||
ActorFlow actorRef { out => SiteClientActor.props(out) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name := "lila-ws" | ||
|
||
version := "1.0-SNAPSHOT" | ||
|
||
lazy val root = (project in file(".")).enablePlugins(PlayScala).disablePlugins(PlayFilters) | ||
|
||
/* val akkaVersion = "2.6.0-M2" */ | ||
|
||
scalaVersion := "2.13.0" | ||
|
||
libraryDependencies += guice | ||
|
||
scalacOptions ++= Seq( | ||
"-feature", | ||
"-deprecation", | ||
"-Xfatal-warnings" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Uncomment this for the most verbose Akka debugging: | ||
akka { | ||
loggers = ["akka.event.slf4j.Slf4jLogger"] | ||
loglevel = "DEBUG" | ||
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter" | ||
|
||
actor { | ||
debug { | ||
#receive = on | ||
#autoreceive = on | ||
#lifecycle = on | ||
} | ||
} | ||
} | ||
|
||
|
||
play.filters.headers.contentSecurityPolicy = null | ||
|
||
# https://www.playframework.com/documentation/latest/AllowedHostsFilter | ||
# Allow requests to localhost:9000. | ||
play.filters.hosts { | ||
allowed = ["localhost:9000"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<configuration> | ||
|
||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel"/> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>logs/application.log</file> | ||
<encoder> | ||
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%coloredLevel %logger{15} - [%marker] %message%n%xException{10}</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<logger name="play" level="INFO"/> | ||
|
||
<!-- actors logging --> | ||
<logger name="akka" level="DEBUG"/> | ||
|
||
<logger name="actors" level="DEBUG"/> | ||
|
||
<!-- controllers --> | ||
<logger name="controllers" level="DEBUG"/> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
<appender-ref ref="FILE"/> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Routes | ||
# This file defines all application routes (Higher priority routes first) | ||
# ~~~~ | ||
|
||
GET /socket/v4 controllers.SocketController.site |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.2.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Use the Play sbt plugin for Play projects | ||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.3") |