Websocket-rails not triggering message to channel (standalone, synchronized)

445 Views Asked by At

I'm trying to use websocket-rails (standalone, synchronized w/ redis on local.host:3245) with my Rails Grape API (running on local.host:3001)

Now I try to send messages to channel A from one of my Grape API endpoints using for example:

WebsocketRails[:a_channel].trigger('welcome_message', 'Hello world!')

Then in my rails client (running on local.host:3005) I try to obtain the message and show it in the browser. Using the WebsocketRails js client I am able to connect with the server. Subscribe to the channel and bind to the event suggested in the wiki:

var dispatcher = new WebSocketRails('local.host:3245/websocket');
var channel = dispatcher.subscribe('a_channel');
channel.bind('welcome_message', function(data) {
  console.log('channel event received: ' + data);
});

However nothing shows up in my console.log, but when I look at the websocket_rails.log I see:

[2015-08-18 10:03:23.184] [[32mChannel[0m] [a_channel] {"welcome_message"=>"Hello world!"}

When I look at redis using redis-cli monitor I don't see the websocket_rails keys (at least I assume they should be there...) and also in my

chrome developer environment --> websockets --> headers I see the ping / pong between client and server, but all the variables are empty.

I do not make use of the WebsocketControllers or events.rb routes, should I? based on this wiki page I assumed I didn't have to.. Also I rather not make use of the controllers and just keep everything in my Grape files because of API versioning.

Does anyone have a suggestion / ideas how to fix this problem?

Thanks in advance!

Note:

  • Rails 4.2.3
  • Ruby 2.1.0
  • API server is running on Unicorn
  • rails client is running on Thin
0

There are 0 best solutions below