agora-access-token
Advanced tools
Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "agora-access-token", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/AgoraIO/Tools/tree/master/DynamicKey/AgoraDynamicKey/nodejs", |
@@ -10,3 +10,3 @@ # How to use | ||
```javascript | ||
const {RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole} = require('./index') | ||
const {RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole} = require('agora-access-token') | ||
``` | ||
@@ -13,0 +13,0 @@ |
@@ -5,13 +5,15 @@ //var fs = require('fs'); | ||
var express = require('express'); | ||
var AgoraSignGenerator = require('./lib/AgoraSignGenerator'); | ||
var {RtcTokenBuilder, RtmTokenBuilder, RtcRole, RtmRole} = require('agora-access-token') | ||
var PORT = 8080; | ||
// Fill the vendorkey and sign key given by Agora.io | ||
var VENDOR_KEY = "xxxx"; | ||
var SIGN_KEY = "yyyy"; | ||
// Fill the appID and appCertificate key given by Agora.io | ||
var appID = "<YOUR APP ID>"; | ||
var appCertificate = "<YOUR APP CERTIFICATE>"; | ||
//var private_key = fs.readFileSync(__dirname + '/../../cert/xxx.com.key'); | ||
//var certificate = fs.readFileSync(__dirname + '/../../cert/xxx.com.crt'); | ||
//var credentials = {key: private_key, cert: certificate, passphrase: "password"}; | ||
// token expire time, hardcode to 3600 seconds = 1 hour | ||
var expirationTimeInSeconds = 3600 | ||
var currentTimestamp = Math.floor(Date.now() / 1000) | ||
var privilegeExpiredTs = currentTimestamp + expirationTimeInSeconds | ||
var role = RtcRole.PUBLISHER | ||
@@ -24,4 +26,6 @@ var app = express(); | ||
var generateDynamicKey = function(req, resp) { | ||
var generateRtcToken = function(req, resp) { | ||
var channelName = req.query.channelName; | ||
// use 0 if uid is not specified | ||
var uid = req.query.uid || 0 | ||
if (!channelName) { | ||
@@ -31,6 +35,5 @@ return resp.status(400).json({ 'error': 'channel name is required' }).send(); | ||
var ts = Math.round(new Date().getTime() / 1000); | ||
var rnd = Math.round(Math.random() * 100000000); | ||
var key = AgoraSignGenerator.generateDynamicKey('4c95c85a2c9849e1b4653c47f0ee415c', 'd75e69f2021c49cc9ac2e1894187000f', channelName, ts, rnd); | ||
var key = RtcTokenBuilder.buildTokenWithUid(appID, appCertificate, channelName, uid, role, privilegeExpiredTs); | ||
resp.header("Access-Control-Allow-Origin", "*") | ||
@@ -41,5 +44,19 @@ //resp.header("Access-Control-Allow-Origin", "http://ip:port") | ||
app.get('/dynamic_key', generateDynamicKey); | ||
var generateRtmToken = function(req, resp) { | ||
var account = req.query.account; | ||
if (!account) { | ||
return resp.status(400).json({ 'error': 'account is required' }).send(); | ||
} | ||
var key = RtmTokenBuilder.buildToken(appID, appCertificate, account, RtmRole, privilegeExpiredTs); | ||
resp.header("Access-Control-Allow-Origin", "*") | ||
//resp.header("Access-Control-Allow-Origin", "http://ip:port") | ||
return resp.json({ 'key': key }).send(); | ||
}; | ||
app.get('/rtcToken', generateRtcToken); | ||
app.get('/rtmToken', generateRtmToken); | ||
http.createServer(app).listen(app.get('port'), function() { | ||
@@ -46,0 +63,0 @@ console.log('AgoraSignServer starts at ' + app.get('port')); |
@@ -9,3 +9,4 @@ { | ||
"dependencies": { | ||
"express": "3.4.8" | ||
"agora-access-token": "^2.0.1", | ||
"express": "3.4.8" | ||
}, | ||
@@ -12,0 +13,0 @@ "main": "DemoServer.js", |
@@ -63,4 +63,4 @@ const AccessToken = require('../src/AccessToken').AccessToken | ||
this.key.addPriviledge(Priviledges.kJoinChannel, privilegeExpiredTs) | ||
if (role == Role.PUBLISHER || | ||
role == Role.SUBSCRIBER || | ||
if (role == Role.ATTENDEE || | ||
role == Role.PUBLISHER || | ||
role == Role.ADMIN) { | ||
@@ -76,2 +76,2 @@ this.key.addPriviledge(Priviledges.kPublishAudioStream, privilegeExpiredTs) | ||
module.exports.RtcTokenBuilder = RtcTokenBuilder; | ||
module.exports.Role = Role; | ||
module.exports.Role = Role; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34712
728