0

Well, i'm trying to create a chat app with rails and websocket but don't work good.

This is my events.rb:

WebsocketRails::EventMap.describe do
  namespace :chat do
    subscribe :new_message, :to => ChatController, :with_method => :incoming_message
  end
end

This is my JS:

$(document).ready(function() {

  var dispatcher = new WebSocketRails(window.location.host + "/websocket");
  dispatcher.bind('chat.new_message', bind_new_message);

  $('#send_message').on('click', function(event) {
    var message = {
      text: $('#new_message').val()
    }
    dispatcher.trigger('chat.new_message', message);
  });

});

function bind_new_message(message) {
  $('#chat_history').append('<div class="message"><span class="user">' + message.user + ':</span> ' + message.text + '</div>');
}

And this is my chatcontroller.rb:

class ChatController < WebsocketRails::BaseController

    def incoming_message
        logger.info "====>>>>    Llega al Controlador    --->>>    #{message.inspect}"
        new_comment = {:user => current_user.screen_name, :text => message[:text]}
        broadcast_message :new_message, new_comment, namespace: 'chat'
        # send_message :new_message, new_comment, namespace: 'chat'
    end

end

And the problem is that this don't work, for example, in websocket gem doc puts that when Broadcast Events to all Clients you can use method broadcast_message but don't work, however, if i change this method for send_message it works (but only broadcast to user that trigger the event)

This is my test app

fcastillo
  • 938
  • 1
  • 11
  • 24
  • I couldn't help noticing the the `websocket-rails`'s last commit was a year ago... I would look into [Faye](https://github.com/faye/faye-websocket-ruby) or [The Plezi Framework](https://github.com/boazsegev/plezi) unless I already had a Rails app that needed a patch with the feature. – Myst Jul 01 '15 at 02:13
  • Yes, i'll try other options like [Faye](https://github.com/faye/faye-websocket-ruby) or [The Plezi Framework](https://github.com/boazsegev/plezi). Thank you so much! – fcastillo Jul 01 '15 at 06:07

1 Answers1

0

This answer is posted to reflect the resolution proposed in the comments and in order to properly mark the question as one that is not in need of future attention.

As pointed out here, websocket-rails isn't an active project and it's last commit was a long time ago.

Alternatives such as Faye and Plezi were offered.

Community
  • 1
  • 1
Myst
  • 18,516
  • 2
  • 45
  • 67