opentok / opentok-android-sdk-samples

Sample applications illustrating best practices using OpenTok Android SDK.
https://tokbox.com/developer/sdks/android/
MIT License
211 stars 169 forks source link

How to create session programmatically #100

Closed HuuNguyen312 closed 7 years ago

HuuNguyen312 commented 8 years ago

Hi

 public static final String API_KEY = "xxxxxx";
 public static final String API_SECRET = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

How to generate Session ID and TOKEN by programmatically in Android

HuuNguyen312 commented 8 years ago
// Set the following constants to your OpenTok API key and API secret.
// See https://tokbox.com/account/.
OpenTok sdk = new OpenTok(API_KEY, API_SECRET);
SessionProperties sessionProperties = new SessionProperties.Builder()
  .mediaMode(MediaMode.ROUTED)
  .build();
Session session = sdk.createSession(sessionProperties);
String sessionId = session.getSessionId();

not work

robjperez commented 7 years ago

Creating the session from the Android App is not a recommended practice. Doing that, will require to bundle the API_SECRET inside your app and some third party could get it and use it without permission.

The recommended way is to setup a server side where you will get the sessions using the appropriate server sdk. The Android app will communicate with it to fetch the sessionId and the token.

For more details, please take a look to our current tutorial: https://tokbox.com/developer/tutorials/android/

nhoxbypass commented 7 years ago

I know about security reason but i must do a demo project for 5 days, and I'm strong with Java but not familiar with server side, how to create and deploy a new server to a host (which host?).

Any workaround solution for me? Thanks!

marinaserranomontes commented 7 years ago

Hi @nhoxbypass,

Please, take a look at the tutorial: https://tokbox.com/developer/tutorials/android/basic-video-chat/#server

nhoxbypass commented 7 years ago

Thanks @marinaserranomontes so we must use server sdk anyway. Client sdk cannot generate session id.

marinaserranomontes commented 7 years ago

Exactly. You have to use the server for a production application. You should not hardcode the credentials in your production app because the sessionIds cannot be created dynamically and tokens expire.

nhoxbypass commented 7 years ago

Thank you very much, the documents about Server SDK is also too good. Many thanks~