在socket.io中,您可以向发件人回复邮件,如:
socket.on('records', function(sheet_id){
records = Record.all
//send message to sender
socket.emit('records', records);
});
但是在rails中:
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
答案 0 :(得分:4)
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