Meteor DDP & Minimongo implementation in C++.
With this library you can:
- communicate with Meteor applications over Websockets
- subscribe to real-time feeds, track changes and observe specific queries
- call server-side methods, query and modify collections
- keep your data mirrored and simulate server operations (latency compensation)
Install Meteor++:
git clone --recursive git://github.com/almightycouch/meteorpp.git
cd meteorpp/build/
cmake ..
make
Run the examples:
ddp-monitor test
Intregrate the library to your project and enjoy the power of Meteor with the speed of C++.
One of the seven principles of Meteor is "simplicity equals productivity".
No esoteric concepts, clear documentation, well-established coding conventions, a set of simple tools designed to integrate seamlessly together.
Meteor++ was built from ground up with the very same philosophy, keep things simple. Both APIs share many similar patterns. If you are familiar to Meteor, you will feel right at home.
The library is written in modern C++. It depends on following third-party libraries:
- the delicious nlohmann JSON library
- Boost libraries, essentially Boost.Asio and Boost.Signals2
- EJDB patch, a MongoDB engine written in C
- Zaphoyd's websocket implementation, WebSocket++
Most of these libraries are header-only and do not require any specific installation. However, you must install boost_random
, boost_system
and ejdb
to successfully build Meteor++.
In order to support features such as latency compensation and atomic operations, some files in the EJDB library must be patched. You can get the patch to apply here. ↩
Note that a fork of EJDB containing the required changes is available as a submodule.
Though it's 2015 already, the support for C++11 is still a bit sparse.
Do not forget to set the necessary switches to enable C++11 (e.g., -std=c++11
for GCC and Clang).
Installing Boost is straight forward on most systems.
OSX:
brew install boost
Linux:
sudo apt-get install libboost-dev libboost-program-options-dev libboost-random-dev libboost-system-dev
If you require more specific informations about the installation process, please read this Getting Started on Unix Variants guide.
Installing EJDB is pretty easy as well as we provide the patched library as submodule.
cd ejdb/
mkdir build/
cd build/
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../dist ../
make && make install
cd ../../
Once the dependencies installed, you can build meteorpp as follow:
cd meteorpp/build/
cmake ..
make
Here are some examples to give you an idea how to use the library.
#include <boost/asio.hpp>
#include <meteorpp/ddp.hpp>
#include <meteorpp/ddp_collection.hpp>
#include <meteorpp/live_query.hpp>
void print_live_query(std::shared_ptr<meteorpp::live_query> const& live_query)
{
std::cout << live_query->data().dump(4) << std::endl;
}
int main(int argc, char** argv)
{
boost::asio::io_service io;
std::shared_ptr<meteorpp::ddp_collection> coll;
std::shared_ptr<meteorpp::live_query> live_query;
auto ddp = std::make_shared<meteorpp::ddp>(io);
ddp->connect("ws://localhost:3000/websocket", [&](std::string const& id) {
coll = std::make_shared<meteorpp::ddp_collection>(ddp, "test");
coll->on_ready([&]() {
live_query = coll->track({{ "foo", "bar" }});
live_query->on_changed(std::bind(print_live_query, live_query));
print_live_query(live_query);
});
});
io.run();
return 0;
}
Copyright (c) 2015 Mario Flach under the MIT License (MIT)
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.