Any way for the server end to send a signal to the client code?


#1

I have a package that’s 100% client-only, and I need that to be invoked when something on the server side happens. In other words:

Meteor.onConnection(function (conn) {
  // do something on client-side
});

How would I go about doing this?


#2

create simple collection and communicate by sending documents there
and cursor.observe or cursor.observeChanges


#3

So I’ll just wind up having a collection in my database called “connections” or something like that? I thought of that, but wanted to keep this a database-free solution.


#4

Can you give an example of what might happen on the server? It’s easier to come up with a solution with a concrete question.


#5

Check this out for inspiration: https://github.com/anticoders/meteor-methods/


#6

Nothing, basically. I just want the server side to watch for a connection from a user via Meteor.onConnection, and then have the client do something like pop up a box, or populate a Session variable.


#7

You could do something like this.

Template.foo.onCreated(function(){
    var self = this;
    self.autorun(function(){
       if(Meteor.status().connected){
         // do stuff
       }
    })
})

Since Meteor.status() is a reactive data-source it will trigger an autorun whenever it changes.

The documentation on Meteor.status() can be found here.