我使用節點js和王菲簡單地傳遞一些信息給客戶,如何創建訂閱,通過bayeux.getClient()發佈的消息視圖的路徑。發佈(
我創建節點服務器
var http = require('http'),
faye = require('faye'),
url = require('url'),
qs = require('querystring');
var POST;
var bayeux = new faye.NodeAdapter({mount: '/faye', timeout: 45});
function publish(request,response)
{
var body = '';
request.on('data', function (data) {
body += data;
});
request.on('end', function() {
POST = qs.parse(body);
if(POST.secrete_key=="@#$werw*#@erwe*&^&*rw234234") // validate request using secret key
{
if(POST.root=="global"||POST.root=="web"){
bayeux.getClient().publish(POST.channelWeb,{text: POST.textWeb});
}
if(POST.root=="global"||POST.root=="mobile"){
bayeux.getClient().publish(POST.channelMobile,{text: POST.textMobile});
}
//eval(POST.auth_type+"_"+POST.update_type+"()");
}//end validate request
else
{
response.writeHead(404);
response.end('404 File not found');
}
});
response.end();
}
// Handle non-Bayeux requests
var server = http.createServer(function (request,response)
{
var pathRegex = new RegExp('^/publish/?$');
var pathname = url.parse(request.url).pathname;
if (pathRegex.test(pathname)) {
publish(request, response);
} else {
render404(request, response);
}
});
bayeux.attach(server);
server.listen(8000);
我使用bayeux.getClient().publish(
發佈消息到一個特定的客戶端。
我創建了一個訂閱JS
var client = new Faye.Client(n.node_url+':8000/faye/');
client.subscribe(n.channel, function(message) {
obj.processNotification(obj,message.text,n.user_id,n.user_type,n.channel);
});
的問題是,IHAVE不知道如何在
bayeux.getClient().publish(channel, message);
創建通道
以及如何訂閱,請幫忙。在此先感謝................