remove site socket... and the entire site module
parent
6f7ee124fe
commit
9b484fe56c
|
@ -36,16 +36,6 @@ object Main extends LilaController {
|
|||
}
|
||||
}
|
||||
|
||||
def websocket(apiVersion: Int) = SocketOption { implicit ctx =>
|
||||
getSocketSri("sri") ?? { sri =>
|
||||
Env.site.socketHandler.human(sri, ctx.userId, apiVersion, get("flag")) map some
|
||||
}
|
||||
}
|
||||
|
||||
def apiWebsocket = WebSocket.tryAccept { req =>
|
||||
Env.site.socketHandler.api(lila.api.Mobile.Api.currentVersion) map Right.apply
|
||||
}
|
||||
|
||||
def captchaCheck(id: String) = Open { implicit ctx =>
|
||||
Env.hub.captcher ? ValidCaptcha(id, ~get("solution")) map {
|
||||
case valid: Boolean => Ok(if (valid) 1 else 0)
|
||||
|
|
|
@ -47,7 +47,7 @@ lazy val modules = Seq(
|
|||
common, db, rating, user, security, hub, socket,
|
||||
message, notifyModule, i18n, game, bookmark, search,
|
||||
gameSearch, timeline, forum, forumSearch, team, teamSearch,
|
||||
analyse, mod, site, round, pool, lobby, setup,
|
||||
analyse, mod, round, pool, lobby, setup,
|
||||
importer, tournament, simul, relation, report, pref,
|
||||
evaluation, chat, puzzle, tv, coordinate, blog,
|
||||
history, video, shutup, push,
|
||||
|
@ -377,10 +377,6 @@ lazy val notifyModule = module("notify", Seq(common, db, game, user, hub, relati
|
|||
libraryDependencies ++= provided(play.api, reactivemongo.driver)
|
||||
)
|
||||
|
||||
lazy val site = module("site", Seq(common, socket)).settings(
|
||||
libraryDependencies ++= provided(play.api, lettuce)
|
||||
)
|
||||
|
||||
lazy val tree = module("tree", Seq(common)).settings(
|
||||
libraryDependencies ++= provided(play.api)
|
||||
)
|
||||
|
|
|
@ -68,10 +68,6 @@ GET /player/autocomplete controllers.User.autocomplete
|
|||
|
||||
GET /dasher controllers.Dasher.get
|
||||
|
||||
# mobile app sends no site socket version: default to v3
|
||||
GET /socket controllers.Main.websocket(apiVersion: Int = 3)
|
||||
GET /socket/v:apiVersion controllers.Main.websocket(apiVersion: Int)
|
||||
|
||||
# Blog
|
||||
GET /blog controllers.Blog.index(page: Int ?= 1, ref: Option[String] ?= None)
|
||||
GET /blog/discuss/:id controllers.Blog.discuss(id: String)
|
||||
|
@ -486,7 +482,6 @@ GET /api/tournament/:id/games controllers.Api.tournamentGames(id: Strin
|
|||
GET /api/tournament/:id/results controllers.Api.tournamentResults(id: String)
|
||||
POST /api/tournament controllers.Tournament.apiCreate
|
||||
GET /api/status controllers.Api.status
|
||||
GET /api/socket controllers.Main.apiWebsocket
|
||||
GET /api/users/status controllers.Api.usersStatus
|
||||
GET /api/users/titled controllers.Api.titledUsers
|
||||
GET /api/crosstable/:u1/:u2 controllers.Api.crosstable(u1: String, u2: String)
|
||||
|
|
|
@ -34,8 +34,7 @@ final class Env(
|
|||
isPlaying: lila.user.User.ID => Boolean,
|
||||
pools: List[lila.pool.PoolConfig],
|
||||
challengeJsonView: lila.challenge.JsonView,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
siteRemoteSocket: lila.site.SiteRemoteSocket,
|
||||
remoteSocketApi: lila.socket.RemoteSocket
|
||||
val isProd: Boolean
|
||||
) {
|
||||
|
||||
|
@ -184,7 +183,6 @@ object Env {
|
|||
pools = lila.pool.Env.current.api.configs,
|
||||
challengeJsonView = lila.challenge.Env.current.jsonView,
|
||||
remoteSocketApi = lila.socket.Env.current.remoteSocket,
|
||||
siteRemoteSocket = lila.site.Env.current.remoteSocket,
|
||||
isProd = lila.common.PlayApp.isProd
|
||||
)
|
||||
}
|
||||
|
|
|
@ -318,7 +318,6 @@ object mon {
|
|||
val ejectAll = inc(s"socket.eject.all")
|
||||
object count {
|
||||
val all = rec("socket.count")
|
||||
val site = rec("socket.count.site")
|
||||
}
|
||||
val deadMsg = inc("socket.dead.msg")
|
||||
def queueSize(name: String) = rec(s"socket.queue_size.$name")
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
package lila.site
|
||||
|
||||
import akka.actor.ActorSystem
|
||||
import com.typesafe.config.Config
|
||||
import play.api.libs.concurrent.Akka.system
|
||||
|
||||
import lila.socket.actorApi.SendToFlag
|
||||
|
||||
final class Env(
|
||||
config: Config,
|
||||
remoteSocketApi: lila.socket.RemoteSocket,
|
||||
population: lila.socket.SocketPopulation,
|
||||
hub: lila.hub.Env,
|
||||
system: ActorSystem
|
||||
) {
|
||||
|
||||
private val SocketSriTtl = config duration "socket.sri.ttl"
|
||||
|
||||
private val socket = new Socket(system, SocketSriTtl)
|
||||
|
||||
val remoteSocket = new SiteRemoteSocket(
|
||||
remoteSocketApi = remoteSocketApi
|
||||
)
|
||||
|
||||
lazy val socketHandler = new SocketHandler(socket, hub)
|
||||
}
|
||||
|
||||
object Env {
|
||||
|
||||
lazy val current = "site" boot new Env(
|
||||
config = lila.common.PlayApp loadConfig "site",
|
||||
remoteSocketApi = lila.socket.Env.current.remoteSocket,
|
||||
population = lila.socket.Env.current.population,
|
||||
hub = lila.hub.Env.current,
|
||||
system = lila.common.PlayApp.system
|
||||
)
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
package lila.site
|
||||
|
||||
import play.api.libs.json._
|
||||
|
||||
import lila.socket.RemoteSocket._
|
||||
|
||||
final class SiteRemoteSocket(
|
||||
remoteSocketApi: lila.socket.RemoteSocket
|
||||
) {
|
||||
|
||||
remoteSocketApi.subscribe("site-in", Protocol.In.baseReader)(remoteSocketApi.baseHandler)
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
package lila.site
|
||||
|
||||
import scala.concurrent.duration.Duration
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import play.api.libs.iteratee._
|
||||
import play.api.libs.json.JsValue
|
||||
|
||||
import actorApi._
|
||||
import lila.socket._
|
||||
import lila.socket.actorApi.SendToFlag
|
||||
|
||||
private[site] final class Socket(
|
||||
system: akka.actor.ActorSystem,
|
||||
sriTtl: Duration
|
||||
) extends SocketTrouper[Member](system, sriTtl) with LoneSocket {
|
||||
|
||||
def monitoringName = "site"
|
||||
def broomFrequency = 4159 millis
|
||||
|
||||
system.lilaBus.subscribe(this, 'sendToFlag)
|
||||
|
||||
private val flags = new lila.socket.MemberGroup[Member](_.flag)
|
||||
|
||||
def receiveSpecific = {
|
||||
|
||||
case Join(sri, userId, flag, promise) =>
|
||||
val (enumerator, channel) = Concurrent.broadcast[JsValue]
|
||||
val member = Member(channel, userId, flag)
|
||||
addMember(sri, member)
|
||||
flags.add(sri, member)
|
||||
promise success Connected(enumerator, member)
|
||||
|
||||
case SendToFlag(flag, msg) =>
|
||||
flags get flag foreach {
|
||||
_.foreachValue(_ push msg)
|
||||
}
|
||||
}
|
||||
|
||||
// don't eject non-pinging API socket clients
|
||||
override def broom: Unit = {
|
||||
members foreach {
|
||||
case (sri, member) => if (!aliveSris.get(sri) && !member.isApi) ejectSriString(sri)
|
||||
}
|
||||
lila.mon.socket.count.site(members.size)
|
||||
}
|
||||
|
||||
override protected def afterQuit(sri: Socket.Sri, member: Member) = {
|
||||
flags.remove(sri, member)
|
||||
}
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package lila.site
|
||||
|
||||
import play.api.libs.json.JsNumber
|
||||
import ornicar.scalalib.Random
|
||||
|
||||
import actorApi._
|
||||
import lila.socket._
|
||||
import lila.socket.actorApi.StartWatching
|
||||
import lila.common.ApiVersion
|
||||
|
||||
private[site] final class SocketHandler(
|
||||
socket: Socket,
|
||||
hub: lila.hub.Env
|
||||
) {
|
||||
|
||||
def human(
|
||||
sri: Socket.Sri,
|
||||
userId: Option[String],
|
||||
apiVersion: ApiVersion,
|
||||
flag: Option[String]
|
||||
): Fu[JsSocketHandler] =
|
||||
socket.ask[Connected](Join(sri, userId, flag, _)) map {
|
||||
case Connected(enum, member) => Handler.iteratee(
|
||||
hub,
|
||||
controller = PartialFunction.empty,
|
||||
member,
|
||||
socket,
|
||||
sri,
|
||||
apiVersion
|
||||
) -> enum
|
||||
}
|
||||
|
||||
def api(apiVersion: ApiVersion): Fu[JsSocketHandler] = {
|
||||
|
||||
val sri = Socket.Sri(Random secureString 8)
|
||||
val userId = none[String]
|
||||
val flag = "api".some
|
||||
|
||||
def controller(member: SocketMember): Handler.Controller = {
|
||||
case ("startWatching", o) => o str "d" foreach { ids =>
|
||||
hub.bus.publish(StartWatching(sri, member, ids.split(' ').toSet), 'socketMoveBroadcast)
|
||||
}
|
||||
case _ => // not available on API socket
|
||||
}
|
||||
|
||||
socket.ask[Connected](Join(sri, userId, flag, _)) map {
|
||||
case Connected(enum, member) => Handler.iteratee(
|
||||
hub,
|
||||
controller(member),
|
||||
member,
|
||||
socket,
|
||||
sri,
|
||||
apiVersion
|
||||
) -> enum
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package lila.site
|
||||
package actorApi
|
||||
|
||||
import scala.concurrent.Promise
|
||||
|
||||
import lila.socket.DirectSocketMember
|
||||
import lila.socket.Socket.Sri
|
||||
|
||||
case class Member(
|
||||
channel: JsChannel,
|
||||
userId: Option[String],
|
||||
flag: Option[String]
|
||||
) extends DirectSocketMember {
|
||||
|
||||
def isApi = flag has "api"
|
||||
}
|
||||
|
||||
private[site] case class Join(sri: Sri, userId: Option[String], flag: Option[String], promise: Promise[Connected])
|
||||
private[site] case class Connected(enumerator: JsEnumerator, member: Member)
|
|
@ -1,5 +0,0 @@
|
|||
package lila
|
||||
|
||||
import lila.socket.WithSocket
|
||||
|
||||
package object site extends PackageObject with WithSocket
|
|
@ -29,6 +29,7 @@ final class Env(
|
|||
bus = system.lilaBus,
|
||||
lifecycle = lifecycle
|
||||
)
|
||||
remoteSocket.subscribe("site-in", RemoteSocket.Protocol.In.baseReader)(remoteSocket.baseHandler)
|
||||
|
||||
system.scheduler.schedule(5 seconds, 1 seconds) { population ! PopulationTell }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue