Reputation: 164
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);
}
}
Upvotes: 1
Views: 9245
Reputation: 687
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
Upvotes: 2