May 2015
Intermediate to advanced
274 pages
5h 11m
English
Actions in GlobalSettings for WebSockets? What if we want to refuse a WebSocket connection when certain headers are missing? Something similar to the following code snippet didn't work as expected:override def onRouteRequest(request: RequestHeader): Option[Handler] = {
if(request.path.startsWith("/ws")){
Option(controllers.Default.error)
} else
super.onRouteRequest(request)
}Interrupting WebSocket from the global object does not work as it does for Actions. However, there are other means of doing so: by using the tryAccept and tryAcceptWithActor methods. A WebSocket definition can be replaced by the following code:
def wsWithHeader = WebSocket.tryAccept[String] { rh => Future.successful(rh.headers.get("token") ...Read now
Unlock full access