Meteor-EventDDP
Meteor-EventDDP copied to clipboard
mathEmit to specific users
Hi,
I just want to emit a server event and the only user (client) that should get it is the current user, who is executing that meteor method where the event is sent.
Can somebody explain how to emit event to specific user. I'm just doing as in readme:
in the client:
ddpEvents.setClient({
// Setting userId here throws an error
// userId: '',
// This is an example of metadata
appId: '2222',
foo: 'bar'
});
then in the server: (in a meteor method)
ddpEvents.matchEmit('push', {
$and: [
userId: [this.userId],
appId: '2222',
foo: 'bar'
]
}, 'Hello');
But the event does not get to the client. How to match a specific user when using matchEmit? Maybe something that I'm doing wrong with ddpEvents syntax?
Excellent, super useful package. Many thanks and bye ...
Any luck on this? Trying to do the same thing to emit to a specific logged in user using their Meteor ID. I have emitted an event on the client and the server sees the user ID so I am not sure why the match isn't working to emit it back from the server to a single client Id.
I had this issue, and upon looking at the source of the package, I don't think it can be done securely.
As a workaround, I created another collection called "messages". Add documents to it whenever you need to, making sure to add a userId field. Then publish, making sure userIds match. Then in the client, I subscribe to it, and watch for changes like this:
Meteor.subscribe("messages");
Messages.find().observe({
added:function(doc){
console.log(doc) //do whatever you want with the doc here.
}
})