i am using node js and faye to simply pass some messages to clients ,
i create a node server
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);
i use bayeux.getClient().publish(
to publish a message to a specific client .
i have created a subscription 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);
});
the problem is , ihave no idea of how to create the channel
in
bayeux.getClient().publish(channel, message);
and how subscribe it , please help . thanks in advance ................
Basically on server side you can create a logic for creating distinct channels and save it in your DB for your clients to subscribe on it and use the same for communication.
For example There could be two users, A and B. The time users A and B onboard on your server, that time you can make two channels for each, based on the combination of their user id's and name and some dynamic number. This gives all the users their default channels to listen and subscribe. These channels can be used for sending messages from server to the clients, which can act as notifications to the client.
Now for communication purpose, there can be a channel such as OpenTalks on which all the users are subscribed, which can be used for chatting.
You can refine the making of channels more for one to one conversation.
Or you can use