Meteor Presence を使用すると、オンラインのユーザーの userId を返すことができます。ユーザー オブジェクトを取得する方法を確認したいと思います。
Meteor.publish('userPresence', function() {
return Meteor.presences.find({}, {fields: {state: true, userId: true}});
});
ご覧のとおり、コレクションを公開し、サブスクライブしています。
Meteor.subscribe('userPresence');
すべてのオンライン ユーザーを取得するための各ブロックを含むビューがあります。
<template name="presenceList">
<h1>{{onlineCount}}</h1>
{{#each onlineUsers}}
{{> presenceSingle}}
{{/each}}
</template>
また、これはヘルパーを含むファイルです。
Template.presenceList.helpers({
onlineUsers: function() {
return Meteor.presences.find();
},
onlineCount: function() {
return Meteor.presences.find().count();
}
});
私の最大の苦労は、シングル ユーザー テンプレートでユーザー名を返すことです。
どんな助けでも素晴らしいでしょう、ありがとう。