0

シンプルな複数ユーザー プレイリスト アプリケーションを作成しています。ビデオのストリームを視聴しているクライアントが 1 つあります。別のクライアントでは、そのプレイリストにビデオを追加しようとしています。ビデオはプレイリストに正しく追加されますが、更新が発生すると、ページが再レンダリングされ、視聴中のクライアントでビデオが再起動します。他のユーザーがビデオをプレイリストに追加すると、それを見ているすべての人が引き続き再生されるようにしようとしています。

私が持っているサーバー上:

Meteor.publish('videosQue', function (room_id) {
  return Videos.find({room_id: room_id});
});

クライアントでは、todo の例のように設定します。

var videosHandle = null;
Deps.autorun(function(){
  var room_id = Session.get('room_id');
  if (room_id)
    videosHandle = Meteor.subscribe('videosQue', room_id);
  else
    videosHandle = null;
});

次に、人が部屋にいるときに適用されるコードを次に示します。

Template.EnteredRoom.loading = function () {
  return videosHandle && !videosHandle.ready();
};

Template.EnteredRoom.room = function () {
  return Rooms.findOne(Session.get('room_id'));
};

Template.EnteredRoom.video_objs = function () {
  Session.set('videos', Videos.findOne({room_id: Session.get('room_id')}))
  return Session.get('videos');
};

Template.EnteredRoom.rendered = function () {
  if (Session.get('videos') && Session.get('videos').videoIds.length) {
    var currVid = 0, playlist = Session.get('videos').videoIds;
    renderVid(playlist, currVid);
  };
};

var renderVid = function(playlist, currVid) {
  var video = Popcorn.youtube('#youtube-video', 'http://www.youtube.com/embed/' + playlist[currVid] + '&autoplay=1');

  video.on("ended", function() {
    if (++currVid < playlist.length) 
      renderVid(playlist, currVid);
    else {
      $('#youtube-video').hide();
      $('#video-container').append('<div style="font-size:30px;color:white;">No Videos :( Try adding one!</div>');
    }
  });
}

とにかくこれを成し遂げることはありますか?

助けてくれてありがとう!

アンドリュー

編集:いくつか読んだ後、これを達成するにはどうにかしてisolateを使用する必要があると思います。何かアドバイスはありますか?

4

1 に答える 1

0

{{#constant}} ブロックにリアクティブが不要な部分を入れてみてはいかがでしょうか。

{{#constant}}
    {{#each ...}}
    ....
    {{/each}}
{{/constant}}

モデル関数で { react: false } オプションを使用してコレクションからリアクティブを無効にすることをお勧めします。

    return collection.find({}, {reactive:false}) }

于 2013-08-13T19:46:44.600 に答える