Can I use redstone with shelf webSocket handler

58 views
Skip to first unread message

Holger Koser

unread,
Jul 21, 2014, 3:44:28 PM7/21/14
to redsto...@googlegroups.com
Hi Luiz,

I have tried to use the redstone with the shelf_web_socket 


The first problem I see is that _target is null because the handler is the _finalHandler.
The second problem I have is that _handleMessage forwards the HiJackException. I think it should be ignored as in shelf_io.

I also tried to setup the handler via Interceptors but I get similar problems.

Best regards, Holger

Luiz Mineo

unread,
Jul 21, 2014, 8:31:39 PM7/21/14
to redsto...@googlegroups.com
Hi Holger,

Thanks! I've published a new version (0.5.9) with a fix for this issue. Can you try it again?

Best regards,
Luiz.

Holger Koser

unread,
Jul 22, 2014, 4:16:06 AM7/22/14
to redsto...@googlegroups.com
Hi Luiz,

I can confirm that your fix solves the problem.
It also seems to solve the problem I had with WebSocket using Interceptors. 
What do you think is the best way to handle websocket connections?

Thanks, Holger

Luiz Mineo

unread,
Jul 22, 2014, 8:18:21 AM7/22/14
to redsto...@googlegroups.com
Both seems fine. Although, if you want to restrict the websocket handler to a specific url, without using an interceptor, you can wrap it in another handler. Example:

var websocketHandler = webSocketHandler((webSocket) {
  webSocket.listen((message) {
    print('Server: ' + message);
    webSocket.add('pong');
  });
});
 
void main() {
  app.setupConsoleLog();
  
  app.setShelfHandler((req) {
    if (req.url.path.startsWith("/ws")) {
      return websocketHandler(req);
    }
    return new shelf.Response.notFound("not_found");
  });
  
  app.start();
}  


You can also wrap more than one handler. For example, if you want to use shelf_web_socket and shelf_static:



var websocketHandler = webSocketHandler((webSocket) {
  webSocket.listen((message) {
    print('Server: ' + message);
    webSocket.add('pong');
  });
});

var staticHandler = createStaticHandler("/web");
 
void main() {
  app.setupConsoleLog();
  
  app.setShelfHandler((req) {
    if (req.url.path.startsWith("/ws")) {
      return websocketHandler(req);
    }
    return staticHandler(req);
  });
  
  app.start();

Luiz Mineo

unread,
Aug 27, 2014, 7:18:49 AM8/27/14
to redsto...@googlegroups.com
If you are still interested in using websockets in Redstone, there is now a redstone_web_socket plugin available on pub, that provides a better integration with shelf_web_socket.
Reply all
Reply to author
Forward
0 new messages