summaryrefslogtreecommitdiff
path: root/example/websockets/app/src/Websockets.scala
blob: 6cada0f26dd221b69c48a8783717d28b7d09bb7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package app

import concurrent.ExecutionContext.Implicits.global
object Websockets extends cask.MainRoutes{
  @cask.websocket("/connect/:userName")
  def showUserProfile(userName: String): cask.WebsocketResult = {
    if (userName != "haoyi") cask.Response("", statusCode = 403)
    else cask.WsHandler { channel =>
      cask.WsActor {
        case cask.WsActor.Text("") => channel.send(cask.WsActor.Close())
        case cask.WsActor.Text(data) =>
          channel.send(cask.WsActor.Text(userName + " " + data))
      }
    }
  }

  initialize()
}