This application, built on top of Basic Video Chat, showcases how to set the preferred torch/flashlight mode and zoom factor for the camera. Note that this is a preference and may not take effect if the active camera does not support the functionality (for example, the front camera typically does not support torch).
The default value for torch is false. Passing true or false indicates whether the publisher should enable or disable the camera's torch when available.
The zoom factor values range from 0.5 to the maximum zoom factor. Values between 0.5 and 1.0 will represent ultra-wide-angle (zoom out) and values between 1.0 and the maximum zoom factor will represent zooming in. The actual zoom factor applied will be automatically clamped to the range supported by the active camera's configuration, meaning if the camera does not support ultra-wide-angle, zoom factors set below 1.0 will not take effect and no zoom will be applied. For values over the maximum zoom factor supported by the camera, the zoom factor will be set with the max value. The value of 1.0 represents no zoom (the default view).
publisher = Publisher.Builder(this@MainActivity).build()
publisher?.setCameraTorch(true)
publisher?.setCameraZoomFactor(5.0f)
Open the OpenTokConfig
file and configure the API_KEY
, SESSION_ID
, and TOKEN
variables. You can obtain these values from your TokBox account.
For a production application, the SESSION_ID
and TOKEN
values must be generated by your app server application and passed to the client, because:
- credentials would expire after a certain amount of time
- credentials are lined to given session (all users would be connected to the same room)
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. If you don't have a Heroku account, you'll need to sign up (it's free).
PHP server | Node.js server |
---|---|
|
|
Repository | Repository |
Note: You can also build your server from scratch using one of the server SDKs.
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:
public static final String CHAT_SERVER_URL = "https://YOURAPPNAME.herokuapp.com";
Note that this application will ignore credentials in the
OpenTokConfig
file whenCHAT_SERVER_URL
contains a valid URL.
This is the code responsible for retrieving the credentials from web server:
private void getSession() {
Log.i(TAG, "getSession");
Call<GetSessionResponse> call = apiService.getSession();
call.enqueue(new Callback<GetSessionResponse>() {
@Override
public void onResponse(Call<GetSessionResponse> call, Response<GetSessionResponse> response) {
GetSessionResponse body = response.body();
initializeSession(body.apiKey, body.sessionId, body.token);
}
@Override
public void onFailure(Call<GetSessionResponse> call, Throwable t) {
throw new RuntimeException(t.getMessage());
}
});
}
- Review other sample projects
- Read more about OpenTok Android SDK