私はyouse MongoDBとAjaxをお勧めします。それはずっと簡単です、あなたはクライアント側(html)にajaxコードを追加し、サーバー側でリクエストを処理するだけです。
簡単な例:
通常、ユーザーがメッセージ、彼らが受けていることを知っているため
サーバー側
app.post('/myUrl', function(req, res){
if(req.body){
//message handlers here
}
Users.find({type: 'admin'}, function(err, users){
var message = req.body.message;
for(var i = 0; i < users.length, i++){
//make sure you have the type as adminPending from the schema in MongoDB
message.save(//save this message to the database); //save this message to the database as 'adminPendingType'
}
})
})
は、管理者に来
html
ファイル
$.ajax({
method: "POST",
url: "http://myUrl.com/myPath",
data: { message: "Hello this is a message" },
contentType: "application/json",
success: function(data){
//handle success
},
error: function(err){
//error handler
}
})
を送信メッセージ、あなたは毎秒AJAXコールをする必要がありますd、これはfacebook/twitterがほとんどのものを扱う方法です。だから、基本的にサーバに何度も何度も何度も何度も尋ねる。
管理HTML
function messageGetter(){
$.ajax({
method: "POST",
url: "http://myUrl.com/didIreceiveAmessage",
data: { message: "Hello this is a message" },
contentType: "application/json",
success: function(data){
//success handler with data object
if(data['exists']== "true"){
//add your data.message to the html page, so it will be seen by the user
}
},
error: function(err){
//error handler
}
})
}
setInterval(messageGetter, 1000); //check it each second
サーバー側
app.post('/myUrl', function(req, res){
if(req.body){
//message handlers here
}
Message.find({type: 'adminPending'}, function(err, messages){
//find the admin info from cookies here
if(messages.length == 0){
console.log("No messages pending");
return false; //exit the request
}else{
var admin = req.session.admin.id; //admin user
//handle stuff with admin
messages['exists'] == true;
res.send(messages);
//change the type of message from adminPending to adminSeen
return false; //exit the message
}
})
})
これは、ノードとAJAXとMongoDBのでそれを行う方法についてだけで素早く簡単な例でした。もちろん、メッセージのタイプを変更して保存する必要があるので、コーディングはもっと長くなります。
回答を参照してください – turmuka