Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用faye ruby服务器向订阅响应添加自定义字段_Ruby_Chat_Publish Subscribe_Faye_Bayeux - Fatal编程技术网

使用faye ruby服务器向订阅响应添加自定义字段

使用faye ruby服务器向订阅响应添加自定义字段,ruby,chat,publish-subscribe,faye,bayeux,Ruby,Chat,Publish Subscribe,Faye,Bayeux,我正在尝试使用faye(包括在发行版中的聊天示例)编写一个概念验证聊天应用程序 在我的概念证明中,我想在客户端订阅某个频道时发送聊天频道的完整历史记录。我目前的想法是使用订阅响应消息中的自定义字段来实现这一点 检查后,似乎允许在订阅响应消息中使用“ext”字段 但我无法使用服务器扩展将任何内容添加到此ext字段 class ServerLog def incoming(message, callback) puts " msg: #{message}" unless mess

我正在尝试使用faye(包括在发行版中的聊天示例)编写一个概念验证聊天应用程序

在我的概念证明中,我想在客户端订阅某个频道时发送聊天频道的完整历史记录。我目前的想法是使用订阅响应消息中的自定义字段来实现这一点

检查后,似乎允许在订阅响应消息中使用“ext”字段

但我无法使用服务器扩展将任何内容添加到此ext字段

class ServerLog
  def incoming(message, callback)
    puts " msg: #{message}"
    unless message['channel'] == '/meta/subscribe'
      return callback.call(message)
    end

    # the following line changes absolutely nothing
    message['ext'] = 'foo'

    callback.call(message)
  end
end

App.add_extension(ServerLog.new)

虽然ext字段的设置不会使服务器崩溃,但它对订阅响应消息绝对没有影响。我甚至使用Wireshark进行了检查(只是为了确保js客户端不会忽略某些字段)。

我的错误是使用了“传入”方法,而不是“传出”

class ServerLog
  def outgoing(message, callback)
    puts " out: #{message}#"
    unless message['channel'] == '/meta/subscribe'
      return callback.call(message)
    end

    if message['subscription'] == '/chat/specialchannel'
      message['ext'] ||= {}
      message['ext']['specialattribute'] = 'special value'
    end

    callback.call(message)

  end
end

App.add_extension(ServerLog.new)
此示例将把
specialattribute
添加到订阅响应消息的
ext
字段中(如果频道是
/chat/specialchannel