play-socket.io
play-socket.io copied to clipboard
Possible for namespace methods to return Futures of flows?
Hi,
I find myself sometimes asking another Actor to produce a Flow for me. For instance, this is used heavily in this example: https://github.com/playframework/play-scala-websocket-example (native websockets). In this case, the method requires you to return a Future[Flow]:
/**
* Creates an action that will either accept the websocket, using the given flow to handle the in and out stream, or
* return a result to reject the Websocket.
*/
def acceptOrResult[In, Out](f: RequestHeader => Future[Either[Result, Flow[In, Out, _]]])(implicit transformer: MessageFlowTransformer[In, Out]): WebSocket = {
WebSocket { request =>
f(request).map(_.right.map(transformer.transform))
}
}
Is it possible to use a similar pattern in this library or is it not relevant?
My other question is that is it possible to do some clean up actions? Something like onDisconnect?
Thanks for this library!