如何在rails上的ruby中调试Pubnub?

时间:2016-08-24 09:33:25

标签: ruby-on-rails pubnub

如何在rails上的ruby中调试Pubnub?

案例 - 当结果出现时,调试器不会在回调时停止。除了调试器之外,有没有办法调试这个?

初始化代码:

$pubnub ||= Pubnub.new(
  subscribe_key: Setting.subscribe_key,
  publish_key: Setting.publish_key,
  logger: Logger.new("#{Rails.root}/log/pubnub_logger.log")
)
#Add a global listener
$pubnub.add_listener(name: 'broadcast_listener', callback: Pubnub::PubnubService.new.callbacks)

订阅并发布:

def subscribe(channel)
    # @my_callback = lambda { |envelope| puts("----------------->"+ envelope.msg) }
    $pubnub.subscribe(channel: channel)            
  end

  def publish(channel, message = {})
    # @my_callback = lambda { |envelope| puts("-------->From chat:: "+envelope.msg) }
    # pubnub.publish(:channel  => channel, :message  => msg, :callback => @my_callback )            
    puts "--------------Message---#{message}-------------------"
    $pubnub.publish(http_sync: true, channel: channel, message: message) do |envelope|
      puts envelope.status
    end
  end   

这是我的回调:

def callbacks 
    callbacks = Pubnub::SubscribeCallback.new(message: ->(envelope) { 
            # puts "#{envelope.result[:data]}" 
            subscription_callback(envelope.result) 
        }, 
        presence: ->(envelope) { 
            # puts #{envelope.result[:data][:message]}" 
            presence_callback(envelope.result) 
        }, 
        status: ->(envelope) {
            # show status
        } 
    ) 
end


def subscription_callback(result) 
    puts "----------------#{result}--------------" 
    binding.pry 
    parse_channel_name = result[:data][:subscribed_channel].split("_") 
    channel_name, broadcast_id = parse_channel_name[0], parse_channel_name[1] 
end

0 个答案:

没有答案