生成令牌

时间:2018-05-05 15:59:12

标签: android token generate vidyo

大家好,我正在使用Android应用来播放实时视频 我使用的是Vidyo图书馆,它在流媒体上运行良好。 但是我需要为我无法生成的流生成令牌。

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();
}

我已下载generateToken.jar文件并将其放入Android studio中的libs文件中 并尝试执行Shell命令行" generateToken.jar -

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

使用Process,但现在正在使用:/

2 个答案:

答案 0 :(得分:0)

确保您传递的是developerKey和ApplicationId参数的有效值。另外,请确保userName不包含特殊字符。 我刚刚尝试使用我的帐户生成令牌,但效果很好。所以.jar正在运作。

答案 1 :(得分:0)

Vidyo Io令牌(通过Java应用程序代码):

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);
        }
    }

}
通过Firebase Cloud功能的

OR Vidyo Io令牌:

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.');
});