Search code examples
javascriptmeteorddp

Connecting to Meteor DDP standalone in browser?


Is it possible to subscribe to data from Meteor via DDP in a browser stand-alone?

I found the Meteor DDP package which states this could be done.

How to use it in a browser stand-alone to receive e.g. collection updates?

Or do you know about other working DDP clients for the browser?


Solution

  • For example there is https://github.com/mondora/ddp.js/, a working isomorphic (browser & Node.js) DDP client library (I'm not an author of this library and there are a few other available with similar functionality).

    You can easily connect to any DDP server and listen to events. There are examples and API documentation in Readme file. Also look at the tests.

    Example usage:

    Server code:

    Meteor.publish("myPublication", (param_0, param_1, param_2) {
        /* ... */
    });
    

    Client code:

    const subscriptionId = ddp.sub("myPublication", [param_0, param_1, param_2]);