New js DDP client (SimpleDDP)

@kerf Correct.

You can use something like this for storing:

localStorage.setItem('meteor_token',server.token);

and for autologin:

let token = localStorage.getItem('meteor_token');
server.login({resume:token});
3 Likes

Awesome work! Thank You ALL!

1 Like

Great job! Need to try! Thaks everyone!

Any working examle as single file NodeJS script?

I’ve tried to reproduce code samples, even with simpleDDPLogin plugin… But cannot get simpleDDP working :frowning:

After succesful await server.connect(); and server.xxx() call failed with something like that:

(node:12452) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): #<Object>

(node:12452) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

So working example with consts for url, login and password would be nice.

Thank you.

P.S. try…catch shows more details, but the working code is always better.

Hello! What do you mean by ‘single file NodeJS script’?
You need to have a meteor server running first then you can use simpleDDP to subscribe to the publications you have on your server and call methods which you have created on your server.

Ok, I’ll do such script by myself :slight_smile:

BTW, for some configuration of Meteor email shold not set to login succesfully

   let userAuth = await server.login({
      password,
      user: {
        username,
        // email, // Don't pass email for http://xxx.yyy/websocket  !!!
      },
    });
    console.log(`Loged as userId: ${server.userId} token: ${server.token} `);

Hi!
Thanks for the package, I have a problem though.
It works like a charm locally but once I commit it to gitlab and then I use netlify to auto publish with new build it the build breaks on the websocket part (not in the error log but it works when I comment out the code below… I use the login plugin:

const simpleDDP = require(“simpleddp”); // nodejs
const simpleDDPLogin = require(“simpleddp-plugin-login”).simpleDDPLogin;

let opts = {
    endpoint: "wss://mymeteorurl/websocket",       
    SocketConstructor: WebSocket,
    reconnectInterval: 5000
};
const server = new simpleDDP(opts,[simpleDDPLogin]);

Any ideas? :slight_smile:

I think it’s because you don’t have WebSocket in your CI/CD. Try using isomorphic-ws:

npm install isomorphic-ws ws --save

and

const simpleDDP = require(“simpleddp”); // nodejs
const ws = require("isomorphic-ws");
const simpleDDPLogin = require(“simpleddp-plugin-login”).simpleDDPLogin;

let opts = {
    endpoint: "wss://mymeteorurl/websocket",       
    SocketConstructor: ws,
    reconnectInterval: 5000
};
const server = new simpleDDP(opts,[simpleDDPLogin]);

Thanks for reply!

I have isom… I have tried with that as well, same result, the build crashes on netlify…
any requirements on vue version or webpack for this?

Can you show us the error you are getting?

10:31:04 PM: ERROR in static/js/vendor.6d5657dfa11e1be0a9aa.js from UglifyJs

10:31:04 PM: Unexpected token name «key», expected punc «;» [./~/simpleddp/~/clone-deep/index.js:29,0][static/js/vendor.6d5657dfa11e1be0a9aa.js:60703,13]

I think it’s a problem connected with UglifyJs and clone-deep npm package. https://github.com/jonschlinkert/clone-deep/issues/9

You can try to replace clone-deep with https://www.npmjs.com/package/clone inside simpleddp source code (./src/helpers/fullCopy.js), if it works, please give the feedback, I will update the repo.

P.S.
This is the place in clone-deep where UglifyJs breaks:

29. for (let key in val) { /* ./~/simpleddp/~/clone-deep/index.js:29,0 */

So you need ES6 support.

Hi!

I didn’t help but we solved it by adding Uglify to webpack.prod:

const UglifyJsPlugin = require(‘uglifyjs-webpack-plugin’)

new UglifyJsPlugin({
“uglifyOptions”:
{
compress: {
warnings: false
},
sourceMap: true
}
}
)

Not sure if it’s the correct approach and perhaps something specific to our project but auth via ddp works like a charm on netlify now :slight_smile:

1 Like

This is great, I will be trying it out ASAP.

Did you or anyone else ever use this with Electron?

Same problem here await doesn’t work when i starte it locally at node xxx.js

Is there an axample i can work of ? help would be nice thx thomas