2017-05-09 8 views
4

私は非常に基本的な設定であるActionCableで遊んでいます。ActionCableはJavaScriptで購読していません

私は、クライアント側でこれをしました:

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

JSコンソールでサーバー

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 

に私が見ることができる:なるほど、サーバーログで

[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 

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) 

ブロードキャストメッセージをサーバーから送信すると、クライアント上で受信されません。クライアントからアクションを実行しようとすると、falseを返し、コンソールに何も表示されません。

ネットワーク]タブを示しています

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

私はrails server

gem 'rails', '~> 5.0.2' 
gem 'puma', '~> 3.0' 
+1

私は 'pace.js'をJavaScriptの読み込みアニメーションスクリプトに含めると考えています。それが問題を引き起こしているようです。 –

+1

Pace.jsを使用している場合は、 'trackWebSockets'オプションを' false'に設定しています。詳細はhttps://github.com/HubSpot/pace/issues/411 –

答えて

0

でサーバーを起動する、のRedisを使用していないが、それを試してみてください。

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

    connected: -> 
    @perform("test") 
関連する問題