arunoda / meteor-streams

Realtime messaging for Meteor
http://arunoda.github.io/meteor-streams
MIT License
287 stars 97 forks source link

Streams not working until page refreshed #39

Open avishekgurung opened 8 years ago

avishekgurung commented 8 years ago

I am using streams to send notification between two applications. The applications are communicating through clusters via redis. Whenever, I push some notification from one app to another, it does not work. But when I refresh the browsers and try, it works.

Can u please tell me what is the problem. My code goes as follows:

App 1 code function sendMessage(message,date,toUserId,fromUserId,jobId){ ChatStream.emit(toUserId,message,date,toUserId,fromUserId,jobId); }

ChatStream.on(Meteor.userId(),function(message,date,toUserId,fromUserId,jobId){ var formatDate = moment(date).fromNow(); var index = ClientChat.find().count(); var chatObj = { from:fromUserId, message:message, date:formatDate, jobId:jobId, index:index } //ClientChat.insert({from:fromUserId,message:message,date:formatDate,jobId:jobId,index:index}) ClientChat.insert(chatObj); Session.set('receivedPing',chatObj); })

App2 function sendMessage(message,date,toUserId,fromUserId,jobId){ ChatStream.emit(toUserId,message,date,toUserId,fromUserId,jobId); }

ChatStream.on(Meteor.userId(),function(message,date,toUserId,fromUserId,jobId){ ClientChat.insert({from:fromUserId,message:message,date:date,jobId:jobId}) })

Cluster.js in server folder Meteor.startup(function(){ Meteor.Cluster.init(); Meteor.Cluster.sync(ChatStream,LocalNotificationStream); })

lib folder ChatStream = new Meteor.Stream('chatStream');