environment | status |
---|---|
Android |
VideoChatGuru is an open-source solution written entirely in Kotlin, based on a WebRTC implementation. It’s not bound with any service, and you are free to choose whether you are going to use an established service provider or host your own. VideoChatGuru prioritises peer-to-peer connections, thanks to which we reduce delays to a minimum.
VideoChatGuru wraps the WebRTC API, providing a friendlier access to its features that you are going to need for implementing video chats. We also provide our Chat&Roll example implementation, so that you can see VideoChatGuru in action. Thanks to the fact that we used Firebase for signalling, it should be much easier to learn and understand how webRTC signalling works by observing it unfold live.
-
Create layout for your Video Chat - you will need to provide two SurfaceViewRenderer views for remote and local video.
-
Create instance of
WebRtcClient
all params are optional and default ones should suffice most of use cases. -
Attach views using
webRtcClient.attachRemoteView(view)
andwebRtcClient.attachLocalView(view)
respectiviely there are also methods which allows you to unbind those. -
Initialize peer connection by calling
webRtcClient.initializePeerConnection(...)
method. Here you will need to provide list of Interactive Connectivity Establishment servers(read more below) and implementation for three listeners that are required to make everything work.PeerConnectionListener.onIceCandidate
andPeerConnectionListener.onIceCandidatesRemoved
- those callbacks are called when WebRTC produces or removes ICE candidates, you are responsible to pass those to the other party through any other estabilished communication channel. Other party should handle those respectively by callingaddRemoteIceCandidate
orremoveRemoteIceCandidate
WebRtcOfferingActionListener
- callbacks launched for offering party - one which will initialize call using create offer.LocalSessionDescription
object which is passed inonOfferRemoteDescription
should be passed to the answering party and handled usinghandleRemoteOffer
method.WebRtcAnsweringPartyListener
- callbacks launched for answering party - one which will call handleRemoteOffer method.LocalSessionDescription
object which is passed inonSuccess
should be passed to the offering party and handled usinghandleRemoteAnswer
method.
-
At this point
WebRtcClient
setup is done and you should initialize handshake process on one of the clients usingcreateOffer
method handling all the callbacks as described earlier.
You can also reffer to the sample.
WebRTC is signaling agnostic meaning that it's your responsibility to provide communication channell that will allow to go through handshake phase. You are free to use your own solutions based on for example: FCM, WebSockets, Pooling, Firebase and any other that allows you to exchange messages beetwen clients in real time.
You can reffer to our sample for solution based on Firebase that allowed us to create and implement Chat Roullette logic. Firebase will also allow you to easily observe handshake process in real time.
Chat&Roll sample allows you to have a video chat with random stranger, project showcase use of VideoChatGuru WebRTC wrapper on Android. Signaling is done through Firebase. Your Firebase setup should provide at least one IceServer - for best results you should provide at least one Turn server to be able to make connection when peer to peer connection fails.
You can download Chat&Roll sample app from Google Play: https://play.google.com/store/apps/details?id=co.netguru.android.chatandroll
To run sample project you need to prepare Firebase instance first.
- Go to https://console.firebase.google.com/
- Create new project
- Add Firebase to your android app
- To setup debug version insert package name
co.netguru.android.chatandroll.debug
- To setup release version insert package name
co.netguru.android.chatandroll
- To setup debug version insert package name
- Download google-services.json
- Place it in App folder
You will need your STUN/TURN servers credentials here.
-
Go to Database
-
Add new child name it
ice_servers
-
Add new child to
ice_servers
named0
-
Add child to
0
-
Insert ICE servers credentials
uri : "turn:ipAddress"
oruri : "stun:ipAddress"
in case of stun server
optionally:
username: "your username"
password: "your password"
-
You can add more ICE servers to be used by WebRTC
-
This should be enough happy testing!
STUN server will allow two parties to expose what their public IP addres is. In most cases we are hidden behind routers in local networks with private IP's. It's used only in first phase of connection while estabilishing peer to peer communication. There are many free STUN servers available as they are used only during connection initialization phase.
TURN server is relay server which is used only when peer to peer connection cannot be estabilished, this can be caused for example by NAT restricions. When TURN server has to be used it might cause higher latency, as all the data has to go to the server and then to the other party, especially if the server is located far from both clients. TURN servers are obtainable mostly through paid services as lot of traffic is generated when TURN has to act as relay between clients, or you could host your own using Coturn.
If you want to learn more about how STUN and TURN works go on and watch : https://youtu.be/p2HzZkd2A40?t=1123
You can find many public STUN servers on the web, you might also want to try out:
- http://numb.viagenie.ca/ Numb provides both STUN and TURN servers free of charge. Take in mind that using public servers might not be the best choice for production code.
Many private services provides their STUN servers free of charge. You can also find free TURN servers with limited amount of bandwidth to use up.
There are various options available out there we've tested Coturn and setup is fairly easy, you can follow this guide https://github.com/coturn/coturn/wiki/CoturnConfig .
- Firebase - WebRTC signaling solution based on firebase real time database - https://firebase.google.com/
- STUN/TURN servers
You're more than welcome to contribute or report an issue in case of any problems, questions or improvement proposals.
- Fork it ( https://github.com/netguru/videochatguru-android/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
To use this library in your project, place the following code in your top hierarchy build.gradle file:
allprojects {
repositories {
maven { url 'https://dl.bintray.com/netguru/maven/' }
}
}
Just add the following dependency in your app's build.gradle:
dependencies {
compile 'co.netguru.videochatguru:videochatguru:0.1.2@aar'
}
Copyright © 2017 Netguru.