我正在使用rocketchat的流星播放包,我已经像这样发起了Streamer变量:
const Streamer = new Meteor.Streamer('chat', {retransmitToSelf: true});
export default Streamer;
所以我在客户端上有这个代码:
import Streamer from '/imports/stream.js'
Template.chat.events({
'submit form': function(event){
event.preventDefault();
var message = event.target.message.value;
event.target.message.value = "";
Streamer.emit('chat', message);
}
})
//If I add this following code outside the Template.chat.events, it will listen wherever I am on the site, I only want it to actively listen when he is visiting the chat.
Streamer.on('chat', function(message) {
console.log(message);
})
那么我如何在Template.chat.events中收听Streamer.on事件?
答案 0 :(得分:0)
我通过将块放在template.chat.onCreated()中解决了这个问题。 然后我将Streamer.stop('chat')放在template.chat.onDestroyed()中。