Use your socket of choice (native or SockJS) websockets to connect to Meteor publish functions and methods inside of a non-Meteor javascript app. It's also useful as a general means of managing your socket connections following the DDP Protocol.
Use as a component:
component install bmcmahen/ddp-browser-client
Or use the standalone build located in the standalone
folder, with the constructor available under the global ddp
.
Pass in a socket (native, SockJS) to the DDP constructor.
Return an id of the subscription. Pass this to the unsubscribe method to unsubscribe.
Document added to a collection
Document removed from a collection
Document changed in a collection
var DDP = require('bmcmahen-ddp-browser-client');
var sock = new SockJS('http://localhost:3000/sockjs');
var socket = new DDP(sock).connect(function(){
console.log('connected');
socket.on('added', function(data){
var collectionName = data.collection;
var documentId = data.id;
var fields = data.fields;
// We can then create new models and populate
// our local collections.
var model = new Model(fields);
var myCollection.add(model);
});
});