Giter Site home page Giter Site logo

martindale / android-ddp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from delight-im/android-ddp

0.0 3.0 0.0 4.35 MB

Meteor's Distributed Data Protocol (DDP) for clients on Android

License: Apache License 2.0

Java 93.85% CSS 0.79% HTML 0.28% JavaScript 5.07%

android-ddp's Introduction

Android-DDP

This library implements the Distributed Data Protocol (DDP) from Meteor for clients on Android.

Connect your native Android apps, written in Java, to apps built with the Meteor framework and build real-time features.

Installation

  • Add this library to your project

    • Include one of the JARs in your libs folder
    • or
    • Copy the Java package to your project's source folder
    • or
    • Create a new library project from this repository and reference it in your project
  • Add the Internet permission to your app's AndroidManifest.xml:

    <uses-permission android:name="android.permission.INTERNET" />

Usage

  • Creating a new instance of the DDP client

    public class MyActivity extends Activity implements MeteorCallback {
    
        private Meteor mMeteor;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
     	   
     	   // ...
     	   
     	   mMeteor = new Meteor(this, "ws://example.meteor.com/websocket");
     	   mMeteor.setCallback(this);
        }
        
        public void onConnect(boolean signedInAutomatically) { }
        
        public void onDisconnect(int code, String reason) { }
        
        public void onDataAdded(String collectionName, String documentID, String newValuesJson) { }
        
        public void onDataChanged(String collectionName, String documentID, String updatedValuesJson, String removedValuesJson) { }
        
        public void onDataRemoved(String collectionName, String documentID) { }
        
        public void onException(Exception e) { }
    
    }
    
  • Inserting data into a collection

    Map<String, Object> values = new HashMap<String, Object>();
    values.put("_id", "my-id");
    values.put("some-key", "some-value");
    
    mMeteor.insert("my-collection", values);
    
  • Updating data in a collection

    Map<String, Object> query = new HashMap<String, Object>();
    query.put("_id", "my-id");
    
    Map<String, Object> values = new HashMap<String, Object>();
    values.put("some-key", "some-value");
    
    mMeteor.update("my-collection", query, values);
    
  • Deleting data from a collection

    mMeteor.remove("my-collection", "my-id");

  • Subscribing to data from the server

    String subscriptionId = mMeteor.subscribe("my-subscription");

  • Unsubscribing from a previously established subscription

    mMeteor.unsubscribe(subscriptionId);

  • Calling a custom method defined on the server

    mMeteor.call("myMethod");

  • Disconnect from the server

    mMeteor.disconnect()

  • Creating a new account (requires accounts-password package)

    mMeteor.registerAndLogin("john", "[email protected]", "password", new ResultListener() { });

  • Signing in with an existing username (requires accounts-password package)

    mMeteor.loginWithUsername("john", "password", new ResultListener() { });

  • Signing in with an existing email address (requires accounts-password package)

    mMeteor.loginWithEmail("[email protected]", "password", new ResultListener() { });

  • Check if the client is currently logged in

    mMeteor.isLoggedIn()

  • Get the client's user ID (if currently logged in)

    mMeteor.getUserId()

  • Logging out

    mMeteor.logout();

  • Checking whether the client is connected

    mMeteor.isConnected()

  • Manually attempt to re-connect (if necessary)

    mMeteor.reconnect()

Contributing

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed.

Dependencies

Further reading

Disclaimer

This project is neither affiliated with nor endorsed by Meteor or Firebase.

License

Copyright 2014 www.delight.im <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

android-ddp's People

Contributors

ocram avatar

Watchers

 avatar  avatar  avatar

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.