def socket WebSocket using String implicit request import play api lib

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def socket = WebSocket.using[String] { implicit request =>
import play.api.libs.concurrent.Execution.Implicits._
Await.result(SecureSocial.currentUser, 1.second) match {
case None =>
val in = Iteratee.foreach[String](println).map(_ => println("Disconnected"))
val out = Enumerator("Pshel von!")
(in, out)
case Some(userId) =>
val in = Iteratee.foreach[String](println).map(_ => println("Disconnected")
val out = Enumerator(s"Hello, $userId!")
(in, out)
}
}