Skip to content

Commit

Permalink
Merge pull request #85 from marcioaffonso/VIDECO-8004
Browse files Browse the repository at this point in the history
[VIDECO-8004] - Update Insights-API samples with applicationIds
  • Loading branch information
marcioaffonso authored Feb 15, 2023
2 parents 7f1b164 + fd64d45 commit 9d3b760
Show file tree
Hide file tree
Showing 17 changed files with 320 additions and 231 deletions.
9 changes: 7 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# OpenTok config env variables
REACT_APP_INSIGHTS_URL = https://insights.opentok.com
REACT_APP_API_KEY = YOUR_API_KEY
REACT_APP_INSIGHTS_URL = https://tools.vonage.com/video/insights-api
REACT_APP_API_KEY = YOUR_API_KEY_OR_APPLICATION_ID

# For TokBox users, only
API_SECRET = YOUR_API_SECRET

# For Nexmo users, only
PRIVATE_KEY_PATH = ./private.key

# App config env variables
SERVER_PORT = 4000
REACT_APP_SERVER_URL = http://localhost:4000
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
.env.production.local

npm-debug.log*
private.key
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Environment Variable Names and Description:

- `REACT_APP_INSIGHTS_URL` (Required): The URL for the OpenTok Insights API server.
- `REACT_APP_API_KEY` (Required): Your OpenTok API Key.
- `API_SECRET` (Required): Your OpenTok API Secret.
- `API_SECRET` (Required when using an OpenTok project): The OpenTok API secret (For OpenTok projects, only).
- `PRIVATE_KEY_PATH` (Required when using a Vonage application): The file path to the private key (for your Vonage application, only).
- `SERVER_PORT` (Required): The port number for your server to run on.
- `REACT_APP_SERVER_URL` (Required): The URL for your server app.
- `APP_CLIENT_URL` (Required): The URL for your client app.
Expand All @@ -50,7 +51,7 @@ This ensures that only those are accessible by the client, protecting your API s

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
projectData(
start: ${moment().subtract(10, 'days')},
interval: DAILY
Expand All @@ -76,7 +77,7 @@ This ensures that only those are accessible by the client, protecting your API s

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
projectData(
start: ${moment().subtract(10, 'days')},
groupBy: SDK_TYPE,
Expand All @@ -102,7 +103,7 @@ Here is the generic query to Insights API to get specified tier related insights

```
{
project(projectId: ${apiKey}) {
project(projectId: "${YOUR_API_KEY}") {
projectData(
start: ${moment(startDate)},
end: ${moment(endDate)},
Expand Down Expand Up @@ -156,7 +157,7 @@ and populate the stacked area chart.

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
projectData(
start: ${moment().subtract(10, 'days')},
groupBy: BROWSER_NAME,
Expand Down Expand Up @@ -189,7 +190,7 @@ and populate the stacked area chart.

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
projectData(
start: ${moment().subtract(10, 'days')},
groupBy: COUNTRY,
Expand Down Expand Up @@ -218,7 +219,7 @@ and populate the stacked area chart.

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
sessionData {
sessionSummaries(start: ${moment().subtract(10, 'days')}) {
totalCount
Expand All @@ -235,7 +236,7 @@ and populate the stacked area chart.

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
sessionData {
sessions(sessionIds: ["${YOUR_SESSION_ID}"]) {
resources {
Expand Down Expand Up @@ -275,7 +276,7 @@ and populate the stacked area chart.

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
sessionData {
sessionSummaries(
start: ${moment().subtract(10, 'days')}
Expand All @@ -302,7 +303,7 @@ input `endCursor` parameter to obtain the next page of data. For more informatio

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
sessionData {
sessions(sessionIds: ["${YOUR_SESSION_ID}"]) {
resources {
Expand All @@ -323,7 +324,7 @@ input `endCursor` parameter to obtain the next page of data. For more informatio

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
sessionData {
sessions(sessionIds: ["${YOUR_SESSION_ID}"]) {
resources {
Expand All @@ -349,7 +350,7 @@ input `endCursor` parameter to obtain the next page of data. For more informatio

```
{
project(projectId: ${YOUR_API_KEY}) {
project(projectId: "${YOUR_API_KEY}") {
projectData(
start: ${moment(startDate)},
end: ${moment(endDate)},
Expand Down
44 changes: 44 additions & 0 deletions helpers/token-generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const jwt = require('jsonwebtoken');
const { v1 } = require('uuid');

const EXPIRATION_SECS = (60 * 60); // 1 hour

const getCurrentTime = () => Math.floor(new Date() / 1000);

/**
* Generates a new token for TokBox users
* @param apiKey - TokBox API Key
* @param apiSecret - TokBox API Secret
*/
const createTokenTokBox = (apiKey, apiSecret) => {
const currentTime = getCurrentTime();
return jwt.sign({
iss: apiKey,
ist: 'project',
iat: currentTime,
exp: currentTime + EXPIRATION_SECS
}, apiSecret);
};

/**
* Generates a new token for Nexmo users
* @param applicationId - Nexmo Application ID
* @param privateKey - Buffer containing the private key
*/
const createTokenNexmo = (applicationId, privateKey) => {
if (!(privateKey instanceof Buffer)) {
throw new Error("You must set up your private key file.");
}
const currentTime = getCurrentTime();
return jwt.sign({
iat: currentTime,
jti: v1(),
exp: currentTime + EXPIRATION_SECS,
application_id: applicationId
}, privateKey, { algorithm: "RS256" });
};

module.exports = {
createTokenTokBox,
createTokenNexmo,
};
Loading

0 comments on commit 9d3b760

Please sign in to comment.