Skip to content

Commit

Permalink
add new token generator syntax for JS
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Aug 29, 2024
1 parent 369275f commit f43008d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docusaurus/video/docusaurus/docs/api/_common_/rtmp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const resp = await call.get();
// userId of existing user
const userId = 'jane';
await client.upsertUsers([{ id: userId }]);
const token = client.createToken(userId);
const token = client.generateUserToken({ user_id: userId });
const rtmpURL = resp.call.ingress.rtmp.address;
const streamKey = token;

Expand Down
47 changes: 34 additions & 13 deletions docusaurus/video/docusaurus/docs/api/basics/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,6 @@ await client.upsertUsers({
[newUser.id]: newUser,
},
});

// exp is optional (by default the token is valid for an hour)
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;

client.createToken(userId, exp);
```

</TabItem>
Expand Down Expand Up @@ -277,9 +272,9 @@ You can optionally provide an expiration time. By default, tokens are valid for

```js
const userId = 'john';
// exp is optional (by default the token is valid for an hour)
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
client.createToken(userId, exp);
// validity is optional (by default the token is valid for an hour)
const validity = 60 * 60;
client.generateUserToken({ user_id: userId, validity_in_seconds: validity });
```

</TabItem>
Expand Down Expand Up @@ -325,6 +320,16 @@ SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET}
echo "${HEADER}.${PAYLOAD}.${SIGNATURE}"
```

</TabItem>
<TabItem value="js-deprecated" label="[email protected] (deprecated)">

```js
const userId = 'john';
// exp is optional (by default the token is valid for an hour)
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
client.createToken(userId, exp);
```

</TabItem>
</Tabs>

Expand All @@ -340,16 +345,16 @@ Call tokens contain a list of call IDs. When a user utilizes a call token, they
<TabItem value="js" label="JavaScript">

```js
const userId = 'john';
// exp is optional (by default the token is valid for an hour)
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
const user_id = 'john';
// validity is optional (by default the token is valid for an hour)
const validity_in_seconds = 60 * 60;

const call_cids = ['default:call1', 'livestream:call2'];

client.createCallToken(userId, call_cids, exp);
client.generateCallToken({ user_id, call_cids, validity_in_seconds });

// Optionally provide a role for the call(s)
client.createCallToken({ user_id: userId, role: 'admin' }, call_cids);
client.generateCallToken({ user_id, call_cids, role: 'admin' });
```

</TabItem>
Expand Down Expand Up @@ -386,5 +391,21 @@ SIGNATURE=$(echo -n ${HEADER}.${PAYLOAD} | openssl dgst -sha256 -hmac ${SECRET}
echo "${HEADER}.${PAYLOAD}.${SIGNATURE}"
```

</TabItem>
<TabItem value="js-deprecated" label="[email protected] (deprecated)">

```js
const userId = 'john';
// exp is optional (by default the token is valid for an hour)
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;

const call_cids = ['default:call1', 'livestream:call2'];

client.createCallToken(userId, call_cids, exp);

// Optionally provide a role for the call(s)
client.createCallToken({ user_id: userId, role: 'admin' }, call_cids);
```

</TabItem>
</Tabs>
6 changes: 3 additions & 3 deletions docusaurus/video/docusaurus/docs/api/basics/get_started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ const newUser: UserRequest = {
};
await client.upsertUsers([newUser]);

// exp is optional (by default the token is valid for an hour)
const exp = Math.round(new Date().getTime() / 1000) + 60 * 60;
// validity is optional (by default the token is valid for an hour)
const vailidity = 60 * 60;

client.createToken(userId, exp);
client.generateUserToken({ user_id: userId, validity_in_seconds: validity });
```

</TabItem>
Expand Down

0 comments on commit f43008d

Please sign in to comment.