This document descibes how to run the gRPC/WebRTC example. Support for WebRTC is officially only available on linux releases. This sample expects the emulator to be running in a server like environment:
These services should be accessible for the browsers that want to interact with the emulator. For example a publicly visible GCE/AWS server should work fine.
This sample is based on ReactJS and provides the following set of components:
You will likely need to modify App.js
and index.html
to suit your needs.
The JavaScript sample has the following requirements:
ANDROID_SDK_ROOT
is set properly. The easiest way to install the sdk is by installing Android Studio.$ $ANDROID_SDK_ROOT/emulator/emulator -version | head -n 1and make sure that the reported build_id is higher than 5769853
$ANDROID_SDK_ROOT
. For example:$ unzip ~/Downloads/sdk-repo-linux-emulator-5775474.zip -d $ANDROID_SDK_ROOT
Make sure you are able to launch the emulator from the command line with a valid avd. Instructions on how to create a virtual device can be found here.
For example if you created a avd with the name P, you should be able to launch it as follows:
$ $ANDROID_SDK_ROOT/emulator/emulator @P
Make sure that the emulator is working properly, and that can use the desired avd.
WebRTC support will be activated if the emulator is launched with the -grpc <port>
flag. The current demos expect the gRPC endpoint to be available at localhost:5556
. This port only needs to be accessible by the gRPC proxy that is being used. There is no need for this port to be publicly visible.
$ $ANDROID_SDK_ROOT/emulator/emulator @P -grpc 5556
The most important thing to is to figure out if you need a Turn Server. You usually only need this if your server running the emulator is behind a firewall, and not publicly accessible. Most of the time there is no need for a turn server.
If for example you are running the emulator in a private Google GCE project, you will need to make use of a turn server. You can take the following steps to enable turn:
Enable a turn service. There are many services you could use. A quick Google search will provide a series of provides. If you are internal at google you could use the GCE turn api.
Launch the emulator with the -turncfg
flag. This will inform the videobridge to execute the given command for every new incoming connection to obtain the JSON turn configuration that will be used.
This command must do the following:
For example:
emulator -grpc 5556 -turncfg "curl -s -X POST https://networktraversal.googleapis.com/v1alpha/iceconfig?key=MySec"
Once you can run the emulator with your avd of choice it is time to install all the development dependencies.
$ make deps
If all goes well all the go, protobuf and javascript dependencies will be installed.
As a developer you will make use of the gRPC go proxy and use node.js to serve the react app. You can launch the develop environment with:
$ make develop
This should open up a browser, and detect any change made to the webpages and JavaScript sources.
To stop the service:
$ make stop
Note: make stop merely kills node and the grpcwebproxy
A production version based on docker compose can be created as follows:
$ make build-release
This will create two docker containers that work together to make the emulator accessible on the web. The two containers are:
The containers are configured in a compose file that binds to port 80 and 443. The envoy container will offer the self signed certs found in docker/certs. Modify the certs according to your needs.
You can start the service as follows:
$ make run-release
Now point your browser to http://localhost.