簡體   English   中英

流星發送給活躍用戶

[英]Meteor send to active users

我從編寫一個meteorjs網頁開始。 我從排行榜示例開始。 這很好。 我添加了一些新功能。 我添加了一個jQuery通知腳本。 (Noty http://ned.im/noty/

當我給一個人五分時,請使用此代碼激活Noty插件

var n = noty({text: txt,timeout: 2000});
......
Template.leaderboard.events({
    'click input.inc': function () {
      Players.update(Session.get("selected_player"), {$inc: {score: 5}});
      notje("Er heeft iemand een score gegeven");
      Method.call("callHouse");
    },

該通知只會顯示在我的瀏覽器上,而不會顯示給其他用戶。 如何向所有活動用戶使用通知。 用戶->服務器->所有用戶

希望您能幫我解決這個問題

您將必須創建一個通知集合(客戶端和服務器):

notifications = new Meteor.Collection("notifications");

然后在其中插入您的消息並使用觀察手柄顯示它。 確保添加特定於用戶的內容,以便可以使用較小的用戶子集。 並確定何時使用它,並將它們標記為就緒,以便不再發布它們,並且用戶不會繼續接收它們。

然后,您可以在客戶端執行以下操作:

Meteor.startup(function() {
    notifications.find().observe({
        added: function(doc) {
            //Message can be contained in doc.txt

            //Not sure if this bit is right, but basically trigger the notification:
            n = noty({text: doc.txt,timeout: 2000});
        }
    });
});

希望這會給您一些大概的想法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM