Answer the question
In order to leave comments, you need to log in
How to chat on web sockets?
Hello! I'm trying to make a chat on RoR using websocket.
I have never worked with web sockets and have gone into a stupor.
Installed the tubesock gem to open a web socket connection. The connection opens, and if you send something, then the answer comes, here is the code:
def socket
hijack do |tubesock|
tubesock.onopen do
tubesock.send_data "Hello, friend"
end
tubesock.onmessage do |data|
# как тут определить какой юзер и кому отправляет, чтобы создать запись в БД, и после этого отослать получателю сообщение
tubesock.send_data "You said: #{data}"
end
end
end
Answer the question
In order to leave comments, you need to log in
Why not try Rail ActionCable? It should work not only under Rails 5, but also under Rails 4 and there are quite a few examples on it - https://github.com/rails/rails/tree/master/actioncable
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question