Gregivy / simpleddp

An easy to use DDP client library
MIT License
165 stars 19 forks source link

is polling (DISABLE_WEBSOCKETS) supported? #15

Closed adamgins closed 4 years ago

adamgins commented 5 years ago

Hi,

struggling with React Native and connecting to a specific Meteor server and enabling DDP/Websockets.

Wondering If Websockets are supported wondering and if the fall back to polling is supported?

If there's a better place to post questions, please let me know where?

I have tried to connect the the server but don't seem to be getting any good error message back to help me debug this. The best I got was 400/bad request when using React Native Meteor... so trying to come up with a workaround for that.

Any help appreciated

thanks

Gregivy commented 5 years ago

Hello, SimpleDDP does not provide WebSockets or any other interface. It accepts a SocketConstructor parameter which is any valid W3C API Web Sockets interface (https://developer.mozilla.org/en-US/docs/Web/API/WebSocket). In the example bellow we use ws package for node.js.

let opts = {
    endpoint: "ws://someserver.com/websocket",
    SocketConstructor: ws,
    reconnectInterval: 5000
};
const server = new simpleDDP(opts);

In case of node.js you can use SimpleDDP + ws(https://github.com/websockets/ws). For browsers use WebSocket object or if you need to support older browsers try this pollyfill https://github.com/gimite/web-socket-js.

For React Native you should use default WebSocket object (https://facebook.github.io/react-native/docs/network). React Native supports web sockets out of the box and you don't need any polling. So in your case:

let opts = {
    endpoint: "ws://someserver.com/websocket",
    SocketConstructor: WebSocket,
    reconnectInterval: 5000
};
const server = new simpleDDP(opts);