1

I have an already working Java method that I want to get the result of the method in a react-native component. I don't really know anything about java, but I know this code works. Is there anyway I could run this java method in any javascript file.

// Java File

import com.twilio.jwt.accesstoken.AccessToken;
import com.twilio.jwt.accesstoken.VideoGrant;

  public class Main {

// Substitute your Twilio AccountSid and ApiKey details
    public static final String ACCOUNT_SID = "ACCOUNT_SID";
    public static final String API_KEY_SID = "API_KEY_SID";
    public static final String API_KEY_SECRET = "API_KEY_SECRET";

    public static void main(String[] args) throws Exception {
    // Create a VideoGrant
        final VideoGrant grant = new VideoGrant();
        grant.setRoom("cool room");

    // Create an Access Token
        final AccessToken token = new AccessToken.Builder(ACCOUNT_SID, API_KEY_SID, API_KEY_SECRET)
        .identity("example-user") // Set the Identity of this token
        .grant(grant) // Grant access to Video
        .build();

    // Serialize the token as a JWT
    final String jwt = token.toJWT();
    System.out.println(jwt);
  }
}

1 Answer 1

2

I'm assuming that piece of code you've shown is actually Android specific. In that case you will need to send the result of your Java method back to the Javascript side by using a Native Module. The official docs provide a decent example: https://facebook.github.io/react-native/docs/native-modules-android

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.