How to connect Meteor to external websocket api using DDP?

Hi there,

I am new to meteor, I wanted to connect my meteor app with 2 external websockets APIs using DDP protocol.
Is this possible with meteor? and what’s the best way to approach this?


Do these APIs already exist, or do you mean you’re going to make them? If so, here’s the DDP spec.
To connect to a DDP API, use DDP.connect()

1 Like

Yes, they APIs already exist and I just want to be able to interact with them through my meteor app. Thanks for sending the links through, I’ll check them out. Is there any good DDP example/boilerplate I can look at to help me understand how it all fits together? Thanks for your help

Here’s a quick example :slightly_smiling_face:

If the API was created like this:

var stuff = new Mongo.Collection('stuff')
Meteor.publish('allStuff', function(){
  return stuff.find()

To subscribe to a collection from it:

var connection = DDP.connect('')
var stuff = new Mongo.collection('stuff', {connection:connection}) //note: the name string must be the same as the server collection
connection.subscribe('allStuff', ()=>{
  //the ready callback

You can try it against too!
Just open your meteor app in the browser and run this in the console:

var connection = DDP.connect('')
var partners = new Mongo.Collection('partners', {connection:connection})

For some reason the ready callback of the subscription seemed to be firing before it was actually ready, so “partners” was still empty :thinking: Not sure why. That’s why I used setTimeout instead.