Ich spiele mit ActionCable, die sehr einfache Einrichtung.ActionCable nicht ausgeführt abonniert in Javascript
Ich habe dies auf Client-Seite:
App.chat = App.cable.subscriptions.create "ChatChannel",
subscribed: ->
console.log 'subscribed'
test: ->
@perform("test")
Auf 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
Auf der JS-Konsole kann ich sehen:
[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
Auf dem Server-Log sehe ich:
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)
Wenn ich eine Broadcast-Nachricht vom Server sende, wird sie nie auf dem Client empfangen. Wenn ich versuche, eine Aktion vom Client auszuführen, wird false zurückgegeben, und auf der Konsole wird nichts angezeigt.
Die Netzwerk-Registerkarte zeigt:
Request URL:ws://0.0.0.0:3000/cable
Request Method:GET
Status Code:101 Switching Protocols (with a green status icon)
Ich bin nicht redis verwenden, Server mit rails server
gem 'rails', '~> 5.0.2'
gem 'puma', '~> 3.0'
Nur gedacht, dass ich "pace.js" ein Javascript laden Animationsskript enthalten. Scheint, als ob das das Problem verursacht –
Wenn Sie Pace.js verwenden, wird die Option 'trackWebSockets' durch 'warkaround' auf' false' gesetzt, weitere Informationen finden Sie hier: https://github.com/HubSpot/pace/issues/411 –