xla*_*aok 2 ruby-on-rails actioncable
在 socket.io 中,您可以回复消息给发件人,例如:
socket.on('records', function(sheet_id){
records = Record.all
//send message to sender
socket.emit('records', records);
});
Run Code Online (Sandbox Code Playgroud)
但在导轨中:
class BoardChannel < ApplicationCable::Channel
def subscribed
stream_from "board:#{params[:board]}"
end
def speak
# client will call @perform('speak')
result = do_something()
# how to send 'result' to sender?
end
end
Run Code Online (Sandbox Code Playgroud)
小智 6
使用ActionCable::Connection::Base#transmit方法
class BoardChannel < ApplicationCable::Channel
def subscribed
stream_from "board:#{params[:board]}"
end
def speak
result = do_something()
transmit(result) # send message to current connection (sender)
end
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
914 次 |
| 最近记录: |