我要在频道的subscribed
方法中广播消息,如下所示:
def subscribed
stream_from 'results_channel'
ActionCable.server.broadcast('results_channel', "Test Confirmation")
end
问题在于广播无法偶尔发生。发生这种情况时,控制台输出如下:
[ActionCable] Broadcasting to results_channel: "Test Confirmation"
ResultsChannel is transmitting the subscription confirmation
ResultsChannel is streaming from results_channel
成功传输后,输出如下:
[ActionCable] Broadcasting to results_channel: "Test Confirmation"
ResultsChannel is streaming from results_channel
ResultsChannel is transmitting the subscription confirmation
ResultsChannel transmitting "Test Confirmation" (via streamed from results_channel)
为了成功广播,控制台输出中会有一些变化。但是,对于缺少的广播,控制台会丢失行ResultsChannel transmitting "Test Confirmation" (via streamed from results_channel)
。
这是意外行为吗?有没有办法确保广播消息是通过订阅发送的(或者我应该在客户端上使用connected
函数)?