While writing a WebSocket proxy in Play 2.6 (based on Websocket Proxy using Play 2.6 and akka streams), I am facing a problem handling streamed text.
Concerned code:
def proxySocket: WebSocket = WebSocket.accept[String, String] { _ =>
Flow[String].map(s => TextMessage(s))
.via(websocketFlow)
.map(_.asTextMessage.getStrictText)
}
This is working for proxying to a local websocket server. But while proxying to a remote server, it leads to the following error:
java.lang.IllegalStateException: Cannot get strict text for streamed message.
We can get stream message via _.asTextMessage.getStreamedText
, but I am not able to figure out how to convert it into String
.