在socket.io中,您可以向除发件人之外的所有客户端发送消息,例如:
socket.broadcast.emit('user connected');
Run Code Online (Sandbox Code Playgroud)
但在rails/actioncable中,怎么做?
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 all client except sender?
end
end
Run Code Online (Sandbox Code Playgroud) 我使用jquery来控制chrome中的SVG文件,
$('svg #lotsofimage').append("<image xlink:href='" + conf[thing].base + "' width= '" + conf[thing].width + "px' height= '" + conf[thing].height + "px' x='" + thing_x + "pt' y='" + thing_y + "pt' ></image>");
Run Code Online (Sandbox Code Playgroud)
但我打开开发工具,它显示如下:
<img xlink:href="xxxx" width="xxxx">
<image></image>was instead of <img />
Run Code Online (Sandbox Code Playgroud)
怎么处理?
在 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)