Skip to content

DDP hooks for Meteor. Currently onConnect and onDisconnect

Notifications You must be signed in to change notification settings

mad-eye/ddpHooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Meteor Ddp Hooks

This small package allows you register callbacks for a ddp client connecting and disconnecting.

Usage

Register a connect callback:

if (Meteor.isServer) {
  DDP.onConnect( function(sessionId) {
    //sessionId is the id of the Meteor Session object (cf livedata package)
    //for this ddp connection.  Access the full session object via
    //Meteor.server.sessions[sessionId]
    console.log("Session connected:", sessionId);
  });
}

Register a disconnect callback (currently just in a publish function):

if (Meteor.isServer) {
  Meteor.publish('stuff', function() {
    self = this;
    //This will trigger when the DDP connection associated with this publish
    //function disconnects.  self refers to the Subscription object for this
    //publish.  You can also pass in a session object, or a sessionId.
    DDP.onDisconnect(self, function(sessionId) {
      console.log("Session disconnected:", sessionId);
    }); 
  });
}

In both cases, the sessionId is the same as Meteor.connection_lastSessionId.

By default, the server is polled every 1000ms for new/closed connections. You can set this via Meteor.settings.sessionInterval.

About

DDP hooks for Meteor. Currently onConnect and onDisconnect

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published