生成令牌
Generating a Token
大家好,我正在开发一个 android 应用程序来流式传输实时视频
我正在使用 Vidyo Library,它在流中运行良好。
但是我需要为我无法生成的流生成令牌
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 文件并将 libs 文件放入 Android studio
并尝试执行 Shell 命令行 "generateToken.jar --
key="+Developer_Key+" --appID="+APP_ID+" --userName=G.Salah --
expiresInSecs=75000"
正在使用进程,但它现在正在运行:/
确保您为 developerKey 和 ApplicationId 参数传递有效值。另外,请确保 userName 不包含特殊字符。
我刚刚尝试用我的帐户生成令牌并且效果很好。所以 .jar 正在工作。
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 云功能的 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 + '[=11=]' + 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.');
});
大家好,我正在开发一个 android 应用程序来流式传输实时视频 我正在使用 Vidyo Library,它在流中运行良好。 但是我需要为我无法生成的流生成令牌
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 文件并将 libs 文件放入 Android studio 并尝试执行 Shell 命令行 "generateToken.jar --
key="+Developer_Key+" --appID="+APP_ID+" --userName=G.Salah --
expiresInSecs=75000"
正在使用进程,但它现在正在运行:/
确保您为 developerKey 和 ApplicationId 参数传递有效值。另外,请确保 userName 不包含特殊字符。 我刚刚尝试用我的帐户生成令牌并且效果很好。所以 .jar 正在工作。
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 云功能的 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 + '[=11=]' + 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.');
});