Generating a Token

1.5k Views Asked by At

Hi everyone I'm working on an android app to Stream a Live Video I'm using the Vidyo Library and it worked well with the stream. But I need to generate a Token for the stream I couldn't

try{
    Process su = Runtime.getRuntime().exec("generateToken.jar -- 
    key="+Developer_Key+" --appID="+APP_ID+" --userName=G.Salah -- 
    expiresInSecs=75000");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
    StringBuffer output = null;
    BufferedReader reader=new BufferedReader(new 
    InputStreamReader(su.getInputStream()));
    String line="";
    while((line=reader.readLine())!=null){
        output.append(line+"\n");
    }
    String response=output.toString();
    AlertDialog.Builder dialog=new AlertDialog.Builder(this);
    dialog.setMessage(response);
    dialog.show();
    outputStream.writeBytes("exit");
    outputStream.flush();
}
catch (IOException e){
    AlertDialog.Builder dialog=new AlertDialog.Builder(this);
    dialog.setMessage(e+"");
    dialog.show();
}

I've downloaded the generateToken.jar file and put in the libs file in Android studio And tried to execute the Shell Command Line "generateToken.jar --

key="+Developer_Key+" --appID="+APP_ID+" --userName=G.Salah -- 
expiresInSecs=75000"

using Process, but its now working :/

2

There are 2 best solutions below

0
On BEST ANSWER

Ensure that you're passing valid values for developerKey and ApplicationId parameters. Also, make sure that userName doesn't contain special characters. I've just tried to generate token with my account and it worked well. So the .jar is working.

0
On

Vidyo Io Token by Java Application Code:

public class Vidyo {

    private static final String Developer_Key = "??????";
    private static final String APP_ID = "?????.vidyo.io ";

    public static void main(String args[]) {
        try{
            Process su = Runtime.getRuntime().exec("C:\\Users\\Kamal\\Desktop\\Vidyo Io\\"+"generateToken.jar -- key="+Developer_Key+" --appID="+APP_ID+" --userName=Kamal -- expiresInSecs=75000");
            DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
            StringBuffer output = null;
            BufferedReader reader = new BufferedReader(new InputStreamReader(su.getInputStream()));
            String line = "";
            while((line = reader.readLine()) != null){
                output.append(line+"\n");
            }
            String response = output.toString();
            System.out.println(response);
            outputStream.writeBytes("exit");
            outputStream.flush();
        }
        catch (IOException e){
            System.err.println(e);
        }
    }

}

OR Vidyo Io Token by Firebase Cloud Function:

const functions = require('firebase-functions');

// Create and Deploy Your First Cloud Functions
// https://firebase.google.com/docs/functions/write-firebase-functions
// https://vidyo.io/blog/create-group-video-conferencing-application-using-webrtc-node-js-and-vidyo-io/

const jsSHA = require('jssha');
const btoa = require('btoa');

let applicationId = "YOUR_VIDYO_APPLICATION_ID.vidyo.io";
let developerKey = "YOUR_VIDYO_DEVELOPER_KEY";

exports.getVidyoToken = functions.https.onRequest((req, res) => {

    function getRandomInt() {
        return Math.floor(Math.random() * Math.floor(9999));
    }

    function generateToken(expiresInSeconds) {
        var EPOCH_SECONDS = 62167219200;
        var expires = Math.floor(Date.now() / 1000) + expiresInSeconds + EPOCH_SECONDS;
        var shaObj = new jsSHA("SHA-384", "TEXT");
        shaObj.setHMACKey(developerKey, "TEXT");
        jid = "demoUser" + getRandomInt() + '@' + applicationId;
        var body = 'provision' + '\x00' + jid + '\x00' + expires + '\x00';
        shaObj.update(body);
        var mac = shaObj.getHMAC("HEX");
        var serialized = body + '\0' + mac;
        return btoa(serialized);
    }

    let thirtyMinutes = 30 * 60;
    //let response = JSON.stringify({token: generateToken(thirtyMinutes)});
    //res.send(response);

    res.statusCode = 200;
    res.setHeader('Content-Type', 'application/json');
    res.end(JSON.stringify({token: generateToken(thirtyMinutes)}));

}, err => {
    console.error(err.stack);
    res.status(500).send('Unexpected error.');
});