Code Monkey home page Code Monkey logo

android-ddp-wss's Introduction

Android-DDP-WSS

A fork of https://github.com/delight-im/Android-DDP to provide WSS support for meteor.

This project includes code from https://github.com/palmerc/SecureWebSockets.

Usage

The Android-DDP's interface mailny leaved unchanged in exception of just one new constructor to set custom web socket options:

public Meteor(final Context context, final String serverUri, String protocolVersion, 
    WebSocketOptions webSocketOptions) {

To migrate your app to WSS you just need to:

  1. replace Android-DDP.jar with Android-DDP-WSS.jar in your app;

  2. add dependencies into your app/build.gradle:

    dependencies { // ..... compile 'org.codehaus.jackson:jackson-core-asl:1.9.13' compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'

  3. change ws:// to wss:// in server URL.

Plain WS is supported by this library as well, of course.

Run meteor with WSS

One of methods to start Meteor with WSS is to run it under reverse HTTPS proxy.

Example of nginx configuration to establish reverse proxy to Meteor:

http {
  server {
  
    listen 8443;
    server_name localhost;
    
    ssl on;
    ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
    ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;
    
    location / {
    
      # websockets
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;
      
      proxy_pass http://localhost:3000/;
      proxy_redirect off;
    }
  }
}

How to use custom CA in your app:

  1. Export CA from server openssl x509 -outform der -in /etc/ssl/certs/ssl-cert-snakeoil.pem -out ca.crt

  2. Place generated ca.crt into app/src/main/res/raw/ca.crt

  3. Create Meteor instance with custom options:

     String serverUrl = "wss://server:8443/websocket";
     
     WebSocketOptions options = null;
     try {
         InputStream streamCA = context.getResources().openRawResource(R.raw.ca);
         SocketFactory socketFactory = CertificateHelper.getSocketFactoryWithCustomCA(streamCA);
         options = new WebSocketOptions();
         options.setSSLCertificateSocketFactory(socketFactory);
     } catch (Exception e) {
         e.printStackTrace();
     }
    
     mMeteor = new Meteor(context, serverUrl, null, options);
    

Build library from source code

Clone the repo:

git clone https://github.com/loentar/Android-DDP-WSS.git
cd Android-DDP-WSS

Build the project using gradle wrapper:

Under Linux:

./gradlew build

Under Windows:

gradlew.bat build

jar library will be placed into lib/build/intermediates/bundles/release/classes.jar.

aar library will be placed into lib/build/outputs/aar/lib-release.aar.

android-ddp-wss's People

Contributors

loentar avatar michaelstephendavies avatar

Watchers

 avatar  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.