serverless-webrtc-android

More: Author   ReportBugs   
Tags:

A demo of using WebRTC with no signaling server. But for Android written in Kotlin.

Compatibile and inspired by this project written for JavaScript by Chris Ball:

What is WebRTC?

It's technology for real time peer to peer comunication. Especially useful for transfering audio and video - teleconference apps, but can be used for ordinary data as in this example. WebRTC is supported in recent Chrome browser, Node.js and also on Android/iOS.

How it works?

WebRTC requires two data payloads to be transfered between parties, it's called SDP (sesssion description protocol). One is called offer and the second is answer.

You can either create offer and send it to other party or wait for offer to be delivered to you. Usually SDP handshakes are done by special signalling server, but in this case we are not using any, so you'll need to pass SDPs manually by e.g. e-mail.

If it's running IPv4, it's very unlikely that both parties will have public IP address or it will be in the same network. SDP requires you'll need to pass external IP address there, this is done automatically by process called ICE gathering. It uses two types of external servers - STUN and TURN. We are using only STUN here, but it should work with TURN as well (and even better). It can even punch through some NAT mechanisms.

It uses libjingle library, it's a native library for WebRTC that comes with Chromium. There is also JNI wrapper for use in Java. You can compile it by yourself but it's extremely tricky. You can use already build dependency in your build.gradle. This helped me a lot:

Usage

Known issues

  • There is no renegotiation of connection, it doesn't make much sense without signalling server.
  • If you paste offer in the app, answer is created but after while it goes with 'icegathering failed'. You must be fast to pass the answer to the other side. I'm not sure what causes this.

License

You can do whatever you want with this code.

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools