Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This can be achieved if you write your own router to do it - the above is not possible with Plays router because you're saying you want to router <code>/</code> to two different end points, the default Play router doesn't look at anything but the request method and URI. So, if you override <code>Global.onRouteRequest</code> to look something like this:</p> <pre><code>override def onRouteRequest(req: RequestHeader): Option[Handler] = { if (req.method == "GET" &amp;&amp; req.path == "/" &amp;&amp; req.headers.get("Upgrade").exists(_.equalsIgnoreCase("websocket))) { Some(controllers.Application.ws()) } else { super.onRouteRequest(req) } } </code></pre> <p>Then, remove the WebSocket route from your routes file.</p> <p>If you want to do this for Java, it will look something like this:</p> <pre><code>public Handler onRouteRequest(play.api.mvc.RequestHeader req) { if (req.method().equals("GET") &amp;&amp; req.path().equals("/") &amp;&amp; req.headers().get("Upgrade").isDefined() &amp;&amp; req.headers().get("Upgrade").get().equalsIgnoreCase("websocket")) { return play.core.j.JavaWebSocket.ofJson(new scala.Function0&lt;WebSocket&lt;JsonNode&gt;&gt;() { public WebSocket&lt;JsonNode&gt; apply() { return controllers.Application.ws(); } }); } else { return super.onRouteRequest(req); } } </code></pre> <p>Not sure if I've got the syntax/types 100% correct there, but hopefully you can work it out. Also, note I've assumed JSON websockets here, if you're using strings or byte arrays, then use <code>JavaWebSocket.ofString/ofBytes</code>. And finally, note that this is an internal API and could break at any time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload