ActionCable does not subscribe to javascript

I play with ActionCable, the most basic setup.

I have this on the client side:

App.chat = App.cable.subscriptions.create "ChatChannel",
  subscribed: ->
    console.log 'subscribed'
  test: ->
    @perform("test")

On server

class ChatChannel < AC..::Channel
  def subscribed
    Rails.logger.info "This is never printed in the logs"
  end
  def test
    Rails.logger.info "This is never printed in the logs"
  end
end

In the JS console, I see:

[ActionCable] Opening WebSocket, current state is null, subprotocols: actioncable-v1-json,actioncable-unsupported 1494360634092
[ActionCable] ConnectionMonitor started. pollInterval = 3000 ms 1494360634096
[ActionCable] WebSocket onopen event, using 'actioncable-v1-json' subprotocol 1494360634733
[ActionCable] ConnectionMonitor recorded connect 1494360634734

In the server log I see:

Started GET "/cable" for 127.0.0.1 at 2017-05-09 15:10:34 -0500
Started GET "/cable/" [WebSocket] for 127.0.0.1 at 09/05/2017 03:10 PM
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
Registered connection (Z2lkOi8vcHJvcGhvL1VzZXIvMg)

If I send a broadcast message from the server, it was never received on the client. If I try to perform an action from the client, it will return false and nothing will appear on the console.

The Network tab shows:

Request URL:ws://0.0.0.0:3000/cable
Request Method:GET
Status Code:101 Switching Protocols (with a green status icon)

I do not use redis starting the server with rails server

gem 'rails', '~> 5.0.2'
gem 'puma', '~> 3.0'
+4
source share
1 answer

try it.

App.chat = App.cable.subscriptions.create "ChatChannel",
  # subscribed: ->
  #   console.log 'subscribed'
  # test: ->
  #   @perform("test")

  connected: ->
    @perform("test")
0
source

Source: https://habr.com/ru/post/1676780/


All Articles