1

I have a public client side function:

test = function(){
    alert("HELLO")!;
}

What I need is a function that works like this - so on the admin client script, they hit a button which calls a server method:

Meteor.call("callFunctions");

The server side function:

Meteor.methods({
    callFunctions: function() {
         //call clientside function test() for all clients
    }
});

How can I do this without depending on a database?

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
rickyduck
  • 4,030
  • 14
  • 58
  • 93
  • From the docs, "The publish function runs each time a new client subscribes to a document set. The data in a document set can come *from anywhere*, but the common case is to publish a database query.". I didn't test this, but I assume you can just publish some document, have all clients subscribe to it, have your server method modify that document, and attach an event hook to all clients subscribed to fire the `test()` function when the document changes. – Brad M Jan 30 '14 at 15:13
  • What @BradM said is on the right track. You can also just have your publish function send these commands to the client which don't have to correspond to server side documents at all. See different ways to publish: http://stackoverflow.com/a/18880927/586086 – Andrew Mao Jan 30 '14 at 16:11

1 Answers1

0

My client-call package does that. It depends on database internally, but you don't have to worry about that dependence.

To call the methods on all clients you'll need to manually register and loop through their ids.

Set up method:

Meteor.ClientCall.methods({
  'alert': function() {
    ...
  },
});

Call it:

Meteor.ClientCall.apply(clientId, 'alert', []);
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
Hubert OG
  • 19,314
  • 7
  • 45
  • 73
  • so how do I loop through all the client id's? – rickyduck Jan 31 '14 at 10:26
  • Actually, scratch that. If you don't need to call other method on a single client, you could just register all clients with the same `id` and things will work. So, on each client, call `Meteor.ClientCall.setClientId('asdf')`, and then on the server use `Meteor.ClientCall.apply('asdf', 'method', [])`. – Hubert OG Jan 31 '14 at 20:50