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