0
私はmongoからの_idを持つクライアントの配列を持っていますが、どのようにしてそれらをすべて一度にルータを使用してページにルーティングできますか?Meteor - 接続された複数のクライアントをアレイからリダイレクトしますか?
例:3人のユーザーが「game」という名前のページに3人のユーザーがいる場合、そのユーザーIDを保存するアレイがある場合、IDがアレイに保存されているすべてのユーザーを別のページにルーティングする必要があります。例: "page2")。私はこれをサーバー側の観点から行うべきだと理解していますが、これを理解するのは難しいです。
//client
Template.GameLayout.onRendered(function() {
var ses = Session.get("loggedIn");
Meteor.call('userCounter', ses, function(error, fullArray){
if(error && error.error === "noArray"){
console.log(error);
console.log("I have error");
} else {
if(fullArray){
var usersArray = fullArray[1];
var randomGen = fullArray[0];
console.log(randomGen);
}
}
})
//server
userCounter: function(sessions){
usersArray.push(sessions);
var usersConnected = usersArray.length;
if(!usersConnected){
throw new Meteor.Error("noArray");
console.log("oops heres the problem");
} else {
if(usersConnected > 2){
var randomGen = Math.floor(Math.random() * 9999999) + 1;
var fullArray = [randomGen, usersArray];
console.log(fullArray);
return fullArray;
usersArray =[];
}
}
}
もう少し明確にすると役に立ちます。なぜユーザーをリダイレクトしたいのですか?そして、どのような基準でそれをしたいのですか?リダイレクション(サーバー側またはクライアント側)はどこで開始しますか? –