Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onConnected hook #17

Open
broth-eu opened this issue Jan 3, 2014 · 1 comment
Open

onConnected hook #17

broth-eu opened this issue Jan 3, 2014 · 1 comment

Comments

@broth-eu
Copy link

broth-eu commented Jan 3, 2014

It would be nice if I can register on a stream to get notified after a client has established a connection to the server.

In my current project I need this to initialize a context object for each client on the server. Hence, I have to check in every listening (server) method if such a context is already available. In case not, a new context object is created.

@spastai
Copy link

spastai commented Apr 3, 2014

Meteor.onConnection(function(connection) {}) could be used here as meteor-streams are using Meteor 'connection'.
However here you will face the problem this Meteor.onConnection happens earlier than client streams starts listen for the events (in other words does https://github.com/arunoda/meteor-streams/blob/master/lib/client.js#L33), so you need to modify https://github.com/arunoda/meteor-streams/blob/master/lib/server.js#L38 adding hook at the end of the publish method, something like
self.onConnected && self.onConnected(subscriptionId);
Then your code could look like:

Meteor.onConnection(function(connection) {
    stream.onConnected = function(id) {
        stream.emit('connect', connection.id);
    }
});

and client

stream.on('connect', function (id) {
))

could do your client initialization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants