问题描述
我正在尝试将动作电缆添加到我在前端使用 angular 8 的 rails 应用程序。 在路由文件中安装路径并设置配置文件后,我尝试调用 ws://localhost:3000/cable:
routes.rb
mount ActionCable.server => '/cable'
config/environments/development.rb
config.action_cable.url = "ws://localhost:3000/cable"
config.action_cable.allowed_request_origins = [/http:\/\/*/,/https:\/\/*/,/file:\/\/*/,'file://']
控制台进入一个无限循环,它成功连接,然后一旦开始流式传输,它就会失去连接。这是进入循环的预期行为吗?怎么了?
控制台输出
Started GET "/cable" for ::1 at 2020-12-24 21:58:28 +0800
Started GET "/cable/" [WebSocket] for ::1 at 2020-12-24 21:58:29 +0800
Successfully upgraded to WebSocket (REQUEST_METHOD: GET,HTTP_CONNECTION: Upgrade,HTTP_UPGRADE: websocket)
Registered connection (#<User:0x00000000075d9678>)
reached here
NotificationChannel is transmitting the subscription confirmation
NotificationChannel is streaming from notifications_channel
Finished "/cable/" [WebSocket] for ::1 at 2020-12-24 21:58:38 +0800
NotificationChannel stopped streaming from notifications_channel
Started GET "/cable" for ::1 at 2020-12-24 21:58:39 +0800
Started GET "/cable/" [WebSocket] for ::1 at 2020-12-24 21:58:40 +0800
Successfully upgraded to WebSocket (REQUEST_METHOD: GET,HTTP_UPGRADE: websocket)
Registered connection (#<User:0x000000000772db78>)
reached here
NotificationChannel is transmitting the subscription confirmation
NotificationChannel is streaming from notifications_channel
Finished "/cable/" [WebSocket] for ::1 at 2020-12-24 21:58:49 +0800
NotificationChannel stopped streaming from notifications_channel
Started GET "/cable" for ::1 at 2020-12-24 21:58:50 +0800
Started GET "/cable/" [WebSocket] for ::1 at 2020-12-24 21:58:51 +0800
Successfully upgraded to WebSocket (REQUEST_METHOD: GET,HTTP_UPGRADE: websocket)
Registered connection (#<User:0x0000000007843008>)
我的 NotificationsChannel 文件。
class NotificationChannel < ApplicationCable::Channel
def subscribed
puts 'reached here'
stream_from 'notifications_channel'
end
def received(data)
end
def unsubscribed
end
end
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)