@@ -33,6 +33,9 @@ var ddpclient = new DDPClient({
3333 maintain_collections: true // Set to false to maintain your own collections.
3434});
3535
36+ /*
37+ * Connect to the Meteor Server
38+ */
3639ddpclient .connect (function (error ) {
3740 if (error) {
3841 console .log (' DDP connection error!' );
@@ -41,18 +44,41 @@ ddpclient.connect(function(error) {
4144
4245 console .log (' connected!' );
4346
44- ddpclient .loginWithUsername (" username" , " password" , function (err , result ) {
47+ /*
48+ * Uncomment to log in with username/password
49+ */
50+ // ddpclient.loginWithUsername("username", "password", function (err, result) {
4551 // result contains your auth token
4652
47- ddpclient .call (' test-function' , [' foo' , ' bar' ], function (err , result ) {
48- console .log (' called function, result: ' + result);
49- });
50-
51- ddpclient .subscribe (' posts' , [], function () {
52- console .log (' posts complete:' );
53- console .log (ddpclient .collections .posts );
54- });
55- });
53+ setTimeout (function () {
54+ /*
55+ * Call a Meteor Method
56+ */
57+ ddpclient .call (
58+ ' deletePosts' , // name of Meteor Method being called
59+ [' foo' , ' bar' ], // parameters to send to Meteor Method
60+ function (err , result ) { // callback which returns the method call results
61+ console .log (' called function, result: ' + result);
62+ },
63+ function () { // callback which fires when server has finished
64+ console .log (' updated' ); // sending any updated documents as a result of
65+ console .log (ddpclient .collections .posts ); // calling this method
66+ }
67+ );
68+ }, 3000 );
69+
70+ /*
71+ * Subscribe to a Meteor Xollection
72+ */
73+ ddpclient .subscribe (
74+ ' posts' , // name of Meteor Publish function to subscribe to
75+ [], // any parameters used by the Publish function
76+ function () { // callback when the subscription is complete
77+ console .log (' posts complete:' );
78+ console .log (ddpclient .collections .posts );
79+ }
80+ );
81+ // });
5682});
5783
5884/*
@@ -74,6 +100,7 @@ ddpclient.on('socket-close', function(code, message) {
74100ddpclient .on (' socket-error' , function (error ) {
75101 console .log (" Error: %j" , error);
76102});
103+
77104```
78105
79106Unimplemented Features
0 commit comments