0

大家好,我正在开发一个用于流式传输实时视频的 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"

使用进程,但它现在正在工作:/

4

2 回答 2

1

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

于 2018-05-31T14:13:37.400 回答
0

Java 应用程序代码的 Vidyo Io 令牌:

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 云功能的 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.');
});
于 2019-11-16T00:13:54.670 回答