-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new token generator syntax for JS
- Loading branch information
Showing
3 changed files
with
38 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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> | ||
|
@@ -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> | ||
|
||
|
@@ -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> | ||
|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters