I
I
Ismail2020-04-03 10:27:33
Ruby on Rails
Ismail, 2020-04-03 10:27:33

Is it possible to use websocket in Rails without users?

Good time of the day. I am writing a trello clone using React + Rails.
There is a need to use web sockets for real time updates. Many of the websocket creation examples use users. That is, there is no registration and authorization, there are no users. There are only 3 models - Board, List, Card, as I understand it, use a web socket just for a permanent connection between the front and the server.

And actually the question is:
Can it be used in some way without authorization? . And if possible, how? What is the path for implementation?

(maybe a stupid question, sorry :))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vayladion Gognazdiak, 2020-04-03
@gosugod

Can. Use Broadcast.

class MessagesChannel < ApplicationCable::Channel  
  def subscribed
    stream_from "messages"
  end
end

Further in js is standard
(function() {
  this.App || (this.App = {});

  App.cable = ActionCable.createConsumer('/cable');

}).call(this);

Throw in the channel
ActionCable.server.broadcast('messages', message.to_json)

Reading
App.messages = App.cable.subscriptions.create('MessagesChannel', {  
  received: function(data) {
    var jsonObj = JSON.parse(data);
....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question