rxjs-ddp-client
This is a simple WebSocket library for real time app like Chats, Notification, etc based on DDP protocol powered by RXjs
- use Meteor-DDP protocol (without the need of Meteor Client) to connect to any Server supporting DDP protocol.
- use RxJs to handle the collection items in Streams
- customizable Cache options to persist and load data from cache
Thi library works well together with:
Difference with Oortcloud/node-ddp-client
- Code rewrite using ES6 and Typescript (add typings and interfaces)
- Using customizable storage system (minimongo-db or minimongo-cache dependencies are NOT required)
- Access to collection's data by simple subscribe to Observable and use RxJs operators (map, zip, filter, etc) for querying
Install
npm install rxjs-ddp-client
Usage Example
- First you need to create a custom DDPClient class that will extend from the base class DDPClient (for a complete example see the file MyDDPClient.ts).
- In this custom DDPClient class you need to implement all your DDP app logic (Login, Collections names, DDP server url, etc)
// example/MyDDPClient.ts//... // Define your collections names // Class methods implementations connect login // Events called by DDPClient onConnected onDisconnected onSocketErrorerror // ...}
- rxjs-ddp-client comes with the data cache out of the box. To keep things flexible, you can use any cache system by implementing a class like MyDDPCacheEngine that has the methods required by DDPCacheEngine interface. For example if you chose to use LocalStorage as cache engine you need a class like this:
// example/MyDDPCacheEngine.ts
- Ultimately you can initialize your custom DDP client in your app main entry point
VanillaJS
// app.ts;; ; // OPTION 1: Wrapper of LocalForage or any storage using Observable (methods must match to DDPCacheEngine interface)// const _storageService = new MyLocalForageWrapper(); // OPTION 2: if you use Angular 2 you could consider using the StorageService of ng2-platform ([see ng2-platform repo](https://github.com/thomasgazzoni/ng2-platform))// const _storageService = this._storageService; // Need to declare StorageService in the constructor // OPTION 3: use the browser localStorage (using the example file my-ddp-cache-engine.ts above); myDDPClient.setCacheEngine_storageService;myDDPClient.connect;
Angular 2+
// app.component.ts;;;
Thanks
- Thanks to oortcloud for the node-ddp-client which formed the inspiration for this code.
- Thanks to yjmade for the Django/PostgreSQL implementation of the Meteor server.
License
MIT