我有一个使用private_pub的rails聊天应用程序和一个运行的Faye服务器。在此设置中成功发布/订阅了聊天消息。而且由于private_pub的设置方式,身份验证就在内置。
在另一台服务器上,我正在运行一个试图连接到Faye服务器的离子应用程序(使用angular)。但是,我似乎无法订阅/发布任何内容,即使2是握手(由faye服务器日志确认)。
一些代码:
# Faye server: private_pub.ru
# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"
# Only load rails environment if required
# we are calling sidekiq so it is required
require ::File.expand_path('../config/environment', __FILE__)
Faye::WebSocket.load_adapter('thin')
PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
# run PrivatePub.faye_app
# UPDATED CODE -
# added functionality in gem
app = PrivatePub.faye_app
# subscribe - online
app.bind(:subscribe) do |client_id, channel|
puts "Client subscribe: #{client_id}:#{channel}"
end
app.bind(:handshake) do |client_id|
puts "Client handshake: #{client_id}"
end
run app
移动客户端:
# services.js
.factory('Faye', function() {
client = new Faye.Client('http://localhost:9292/faye')
return client
})
# controllers.js
.controller('ConversationsCtrl', function($scope, Conversations, $location, Faye) {
var subscription = Faye.subscribe('/**');
subscription.then(function(response) {
console.log(response)
})
...
})
如上所述,客户端与faye服务器成功握手,但无法订阅(我无法在任何地方找到错误消息)。我的猜测是private_pub无法正确验证客户端,但我不知道如何解决这个问题。一直在摸我的头,任何帮助/指针将不胜感激! :d