S
S
stefan_hansch2015-10-20 15:01:18
Ruby on Rails
stefan_hansch, 2015-10-20 15:01:18

Adding rooms and a private chat room?

Hello.
There is a written chat, I used gem faye-rails to update messages. For authorization of the user, I use devise. Now over to add rooms. It turns out that it is necessary to create separate faye subscriptions for each room? How to implement it correctly? Can anyone show ready-made examples?
So far I have implemented the following way:
messages.js.erb

window.client = new Faye.Client('/faye')

jQuery ->
  $('#new_message').submit ->
    $(this).find("input[type='submit']").val('Sending...').prop('disabled', true)

  try
    client.unsubscribe '/messages'
  catch
    console?.log "Can't unsubscribe."
 
  client.subscribe '/messages', (payload) ->
    $('#messages').find('.media-list').append(payload.message) if payload.message

Answer the question

In order to leave comments, you need to log in

1 answer(s)
_
_ _, 2015-10-20
@AMar4enko

client.subscribe '/room1/*'
When the message arrived, look at what the channel was originally.
For example, '/room1/enter', '/room1/exit', '/room1/message', etc.
In my opinion, the channel comes as the second parameter in the subscriber, although I could be wrong, I haven't worked with Faye for a long time

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question