IOS 上的 Safari 中 Action Cable 不工作
Action Cable not working in Safari on IOS
我想在 rails 6.0.2.
中交换有关动作电缆的信息
在我的桌面上这也很好用。
但不幸的是,在我的 IPhone 和 IPad (IOS 13.4) 上的 Safari 中,未建立与 websocket 的连接。 'connected' 和 'received' 函数都没有被调用。我在 IPhone(通过电缆连接)上的 Safari 开发者工具控制台中没有任何错误或信息。
我这里有所有相关文件,它们大部分是由 rails 标准生成的。
app/javascript/channels/test_channel.js
import consumer from "./consumer"
consumer.subscriptions.create("TestChannel", {
connected() {
console.log("connected")
},
disconnected() {
console.log("disconnected")
},
received(data) {
console.log("received")
}
});
app/javascript/channels/consumer.js
import { createConsumer } from "@rails/actioncable"
export default createConsumer()
app/javascript/channels/index.js
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
app/javascript/channels/index.js
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
app/javascript/packs/application.js
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
package.json
{
"name": "...",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "4.2.2",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.10.3"
}
}
app/channels/test_channel.rb
class TestChannel < ApplicationCable::Channel
def subscribed
stream_from "some_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
ngnix Config(在本地开发中也不起作用)
....
location /cable {
passenger_app_group_name test_app_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
}
好吧,那是我的错误。在我的 Safari 中,启用了实验性功能 'NSURLSession WebSocket'。在我禁用该选项后,它起作用了。该选项位于:
启动设置 > 向下滚动找到 Safari,然后点击它。 > 向下滚动以单击高级选项。然后你会看到实验功能 > 点击它
我想在 rails 6.0.2.
中交换有关动作电缆的信息在我的桌面上这也很好用。
但不幸的是,在我的 IPhone 和 IPad (IOS 13.4) 上的 Safari 中,未建立与 websocket 的连接。 'connected' 和 'received' 函数都没有被调用。我在 IPhone(通过电缆连接)上的 Safari 开发者工具控制台中没有任何错误或信息。
我这里有所有相关文件,它们大部分是由 rails 标准生成的。
app/javascript/channels/test_channel.js
import consumer from "./consumer"
consumer.subscriptions.create("TestChannel", {
connected() {
console.log("connected")
},
disconnected() {
console.log("disconnected")
},
received(data) {
console.log("received")
}
});
app/javascript/channels/consumer.js
import { createConsumer } from "@rails/actioncable"
export default createConsumer()
app/javascript/channels/index.js
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
app/javascript/channels/index.js
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
app/javascript/packs/application.js
require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
package.json
{
"name": "...",
"private": true,
"dependencies": {
"@rails/actioncable": "^6.0.0",
"@rails/activestorage": "^6.0.0",
"@rails/ujs": "^6.0.0",
"@rails/webpacker": "4.2.2",
"turbolinks": "^5.2.0"
},
"version": "0.1.0",
"devDependencies": {
"webpack-dev-server": "^3.10.3"
}
}
app/channels/test_channel.rb
class TestChannel < ApplicationCable::Channel
def subscribed
stream_from "some_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
end
ngnix Config(在本地开发中也不起作用)
....
location /cable {
passenger_app_group_name test_app_action_cable;
passenger_force_max_concurrent_requests_per_process 0;
}
好吧,那是我的错误。在我的 Safari 中,启用了实验性功能 'NSURLSession WebSocket'。在我禁用该选项后,它起作用了。该选项位于:
启动设置 > 向下滚动找到 Safari,然后点击它。 > 向下滚动以单击高级选项。然后你会看到实验功能 > 点击它