GithubHelp home page GithubHelp logo

ddp's Introduction

DDP

This is a DPP protocol implementation for Flutter/Dart.

Getting Started

Install

Add the package to your project using these instructions.
For help getting started with Flutter, view our online documentation.
For help on editing package code, view the documentation.

Connection

import 'package:ddp/ddp.dart';

DdpClient client = DdpClient("meteor", "ws://localhost:3000/websocket", "meteor");
client.connect();

client.addStatusListener((status) {
  if (status == ConnectStatus.connected) {
    print('I am connected!');
  }
});

Subscribe

void myListener(String collectionName, String message, String docId, Map map) {
  // Do something great
}

client.addStatusListener((status) {
  if (status == ConnectStatus.connected) {
    client.subscribe("subscribe_name", (done) {
      Collection collection = done.owner.collectionByName("collection_name");
      collection.addUpdateListener(myListener);
    }, []);
  }
});

Call method

List tasks = [];

client.addStatusListener((status) async {
  if (status == ConnectStatus.connected) {
    var data = await client.call('getTasks', []);
    data.reply.forEach((map) => tasks.add(map));
  }
});

License

Copyright (c) 2018 haoguo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

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.

ddp's People

Contributors

haoguo avatar lohanbodevan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ddp's Issues

how to implement or integrate ?

flutter and dart is comlpletely new for developers so can you show us with some examples how to connect to meteor server . how to subscribe to to publication and how to call meteor methods

Cannot connect to server on Flutter web

ddpClient.connect() cannot be run on the web.

...
  onPressed: () {
      DdpClient client =
          DdpClient(xxx, xxx, xxx);
      client.connect(); // Died on this line
  },

This code works fine on mobile (IOS and Android), it does not work for web.
Here is the error message:

══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
js_primitives.dart:30 The following UnsupportedError was thrown while handling a gesture:
js_primitives.dart:30 Unsupported operation: Platform._version
js_primitives.dart:30 
js_primitives.dart:30 When the exception was thrown, this was the stack:
js_primitives.dart:30 package:dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 194:49  throw_
js_primitives.dart:30 package:dart-sdk/lib/_internal/js_dev_runtime/patch/io_patch.dart 284:5               _version
js_primitives.dart:30 package:dart-sdk/lib/io/platform_impl.dart 121:32                                     get version
js_primitives.dart:30 package:dart-sdk/lib/io/platform.dart 74:37                                           get _version
js_primitives.dart:30 package:dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart 75:6     get
js_primitives.dart:30 package:dart-sdk/lib/io/platform.dart 231:32                                          get version
js_primitives.dart:30 package:dart-sdk/lib/_http/http_impl.dart 3234:26                                     _getHttpVersion
js_primitives.dart:30 package:dart-sdk/lib/_http/http_impl.dart 2071:22                                     new
js_primitives.dart:30 package:dart-sdk/lib/_http/http.dart 1473:18                                          new
js_primitives.dart:30 package:dart-sdk/lib/_http/websocket_impl.dart 993:45                                 get _httpClient
js_primitives.dart:30 package:dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/utils.dart 75:6     get
js_primitives.dart:30 package:dart-sdk/lib/_http/websocket_impl.dart 1046:8                                 connect
js_primitives.dart:30 package:dart-sdk/lib/_http/websocket.dart 380:22                                      connect
js_primitives.dart:30 package:ddp/ddp_client.dart 137:8                                                     connect
...

status listener not working correctly when server goes away?

hi there,
i am playing with ddp connector, and i am wondering, how to listen to an event, when the server shuts down. ConnectStatus.disconnected is not triggered in this case.

client = DdpClient("meteor", "ws://localhost:3000/websocket", "meteor");
    client.connect();
    client.addStatusListener((status) {
      if (status == ConnectStatus.connected) {
        print("connected");
      }
      if (status == ConnectStatus.connecting) {
        print("connecting");
      }
      if (status == ConnectStatus.disconnected) {
        print("disconnected");
      }
      if (status == ConnectStatus.dialing) {
        print("dialing");
      }
    });

Update the dependencies

With the latest version of Flutter, the following dependencies have been updated:

tuple: ^2.0.0
quiver: ^2.0.0

Lack of support for filtering collection results

The package lacks support for filtering out results of a collection based on a condition.

As of now, we can query the collection using two methods:

  1. Collection.findAll()
  2. Collection.findOnce()

There doesn't exist a method Collection.find(<condition>) which helps in filtering out results earlier before fetching all the results and then manually filtering out.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.