|
| 1 | +# Client Observability Java |
| 2 | + |
| 3 | +This application provides a completed version of the OpenTok [Client Observability tutorial](https://tokbox.com/developer/tutorials/android/) for Android (differing only in some additional validation checks). Upon deploying this sample application, you should be able to have two-way audio and video communication using OpenTok. |
| 4 | + |
| 5 | +Main features: |
| 6 | +* Connect to an OpenTok session |
| 7 | +* Publish an audio-video stream to the session |
| 8 | +* Subscribe to another client's audio-video stream |
| 9 | + |
| 10 | +# Configure the app |
| 11 | +Open the `OpenTokConfig` file and configure the `API_KEY`, `SESSION_ID`, and `TOKEN` variables. You can obtain these values from your [TokBox account](https://tokbox.com/account/#/). |
| 12 | + |
| 13 | +### (Optional) Deploy a back end web service |
| 14 | + |
| 15 | + For a production application, the `SESSION_ID` and `TOKEN` values must be generated by your app server application and passed to the client, because: |
| 16 | + - credentials would expire after a certain amount of time |
| 17 | + - credentials are lined to given session (all users would be connected to the same room) |
| 18 | + |
| 19 | +To quickly deploy a pre-built server click at one of the Heroku buttons below. You'll be sent to Heroku's website and prompted for your OpenTok `API Key` and `API Secret` — you can obtain these values on your project page in your [TokBox account](https://tokbox.com/account/user/signup). If you don't have a Heroku account, you'll need to sign up (it's free). |
| 20 | + |
| 21 | +| PHP server | Node.js server| |
| 22 | +| ------------- | ------------- | |
| 23 | +| <a href="https://heroku.com/deploy?template=https://github.com/opentok/learning-opentok-php" target="_blank"> <img src="https://www.herokucdn.com/deploy/button.png" alt="Deploy"></a> | <a href="https://heroku.com/deploy?template=https://github.com/opentok/learning-opentok-node" target="_blank"> <img src="https://www.herokucdn.com/deploy/button.png" alt="Deploy"></a> | |
| 24 | +| [Repository](https://github.com/opentok/learning-opentok-php) | [Repository](https://github.com/opentok/learning-opentok-node) | |
| 25 | + |
| 26 | +> Note: You can also build your server from scratch using one of the [server SDKs](https://tokbox.com/developer/sdks/server/). |
| 27 | +
|
| 28 | +After deploying the server open the `ServerConfig` file in this project and configure the `CHAT_SERVER_URL` with your domain to fetch credentials from the server: |
| 29 | + |
| 30 | +```java |
| 31 | +public static final String CHAT_SERVER_URL = "https://YOURAPPNAME.herokuapp.com"; |
| 32 | +``` |
| 33 | + |
| 34 | +> Note that this application will ignore credentials in the `OpenTokConfig` file when `CHAT_SERVER_URL` contains a valid URL. |
| 35 | +
|
| 36 | +This is the code responsible for retrieving the credentials from web server: |
| 37 | + |
| 38 | +```java |
| 39 | +private void getSession() { |
| 40 | + Log.i(TAG, "getSession"); |
| 41 | + |
| 42 | + Call<GetSessionResponse> call = apiService.getSession(); |
| 43 | + |
| 44 | + call.enqueue(new Callback<GetSessionResponse>() { |
| 45 | + @Override |
| 46 | + public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) { |
| 47 | + GetSessionResponse body = response.body(); |
| 48 | + initializeSession(body.apiKey, body.sessionId, body.token); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void onFailure(Call<GetSessionResponse> call, Throwable t) { |
| 53 | + throw new RuntimeException(t.getMessage()); |
| 54 | + } |
| 55 | + }); |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +## Further Reading |
| 60 | + |
| 61 | +* Review [other sample projects](../) |
| 62 | +* Read more about [OpenTok Android SDK](https://tokbox.com/developer/sdks/android/) |
0 commit comments