forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSocketHandler.scala
43 lines (39 loc) · 1.22 KB
/
SocketHandler.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package lila.relay
import lila.common.ApiVersion
import lila.socket.Socket.{ Uid, SocketVersion }
import lila.socket.{ Handler, JsSocketHandler }
import lila.study.{ Study, StudySocket, SocketHandler => StudyHandler }
import lila.user.User
private[relay] final class SocketHandler(
studyHandler: StudyHandler,
api: RelayApi
) {
private def makeController(
socket: StudySocket,
relayId: Relay.Id,
uid: Uid,
member: StudySocket.Member,
user: Option[User]
): Handler.Controller = ({
case ("relaySync", o) =>
logger.info(s"${user.fold("Anon")(_.username)} toggles #${relayId}")
api.requestPlay(relayId, ~(o \ "d").asOpt[Boolean])
}: Handler.Controller) orElse studyHandler.makeController(
socket = socket,
studyId = Study.Id(relayId.value),
uid = uid,
member = member,
user = user
)
def join(
relayId: Relay.Id,
uid: Uid,
user: Option[User],
version: Option[SocketVersion],
apiVersion: ApiVersion
): Fu[JsSocketHandler] = {
val studyId = Study.Id(relayId.value)
val socket = studyHandler.getSocket(studyId)
studyHandler.join(studyId, uid, user, socket, member => makeController(socket, relayId, uid, member, user), version, apiVersion)
}
}