Skip to content

Commit 4ae6bd9

Browse files
feat(video): Support for configurable room name (#309)
1 parent 79f3f1b commit 4ae6bd9

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

video/.env

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ API_KEY=
1010
# required: true
1111
API_SECRET=
1212

13+
# description: Choose a room name for your video call
14+
# format: text
15+
# required: true
16+
ROOM_NAME=
17+
1318
# description: Choose a passcode for your app. Users have to use this passcode to enter the video call
1419
# format: text
1520
# required: true

video/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ This project requires some environment variables to be set. To keep your tokens
1010

1111
In your `.env` file, set the following values:
1212

13-
| Variable | Description | Required |
14-
| :----------- | :-------------------------------------------------------------------------------- | :------- |
15-
| `ACCOUNT_SID`| Find in the [console](https://www.twilio.com/console) | Yes |
16-
| `API_KEY` | Twilio API Key. Create one here (https://www.twilio.com/console/runtime/api-keys) | Yes |
17-
| `API_SECRET` | Twilio API Secret corresponding to your API Key | Yes |
18-
| `PASSCODE` | A passcode to gate your video call | Yes |
13+
| Variable | Description | Required |
14+
| :------------ | :-------------------------------------------------------------------------------- | :------- |
15+
| `ACCOUNT_SID` | Find in the [console](https://www.twilio.com/console) | Yes |
16+
| `API_KEY` | Twilio API Key. Create one here (https://www.twilio.com/console/runtime/api-keys) | Yes |
17+
| `API_SECRET` | Twilio API Secret corresponding to your API Key | Yes |
18+
| `ROOM_NAME` | A room name to identify your video call | Yes |
19+
| `PASSCODE` | A passcode to gate your video call | Yes |
1920

2021
### Function Parameters
2122

video/assets/conference.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ const participantDisconnected = (participant) => {
3939
};
4040

4141
(() => {
42-
const ROOM_NAME = 'demo';
4342
const { Video } = Twilio;
4443
let videoRoom;
4544
let localStream;
@@ -77,10 +76,10 @@ const participantDisconnected = (participant) => {
7776
}
7877
})
7978
.then((body) => {
80-
const { token } = body;
79+
const { token, room } = body;
8180
console.log(token);
8281
// connect to room
83-
return Video.connect(token, { name: ROOM_NAME });
82+
return Video.connect(token, { name: room });
8483
})
8584
.then((room) => {
8685
console.log(`Connected to Room ${room.name}`);

video/functions/video-token.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
exports.handler = function (context, event, callback) {
22
const VALID_PASSCODE = context.PASSCODE;
3+
const { ROOM_NAME } = context;
34
const TWILIO_ACCOUNT_SID = context.ACCOUNT_SID;
45
const TWILIO_API_KEY = context.API_KEY;
56
const TWILIO_API_SECRET = context.API_SECRET;
@@ -14,7 +15,6 @@ exports.handler = function (context, event, callback) {
1415
return callback(null, response);
1516
}
1617

17-
const ROOM_NAME = 'demo'; // fixed room name
1818
const { AccessToken } = Twilio.jwt;
1919
const { VideoGrant } = AccessToken;
2020
/*
@@ -34,5 +34,6 @@ exports.handler = function (context, event, callback) {
3434
accessToken.identity = ACCESS_TOKEN_IDENTITY;
3535
return callback(null, {
3636
token: accessToken.toJwt(), // Serialize the token to a JWT string
37+
room: ROOM_NAME,
3738
});
3839
};

video/tests/video-token.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const baseContext = {
66
ACCOUNT_SID: 'ACxxx',
77
API_KEY: 'api-key',
88
API_SECRET: 'api-secret',
9+
ROOM_NAME: 'test',
910
};
1011

1112
describe('video-token/token', () => {
@@ -20,12 +21,13 @@ describe('video-token/token', () => {
2021
const callback = (_err, result) => {
2122
expect(result).toBeDefined();
2223
expect(typeof result.token).toBe('string');
24+
expect(result.room).toEqual(baseContext.ROOM_NAME);
2325
jwt.verify(result.token, baseContext.API_SECRET, (err, decoded) => {
2426
expect(err).toBeNull();
2527
expect(decoded.iss).toBe(baseContext.API_KEY);
2628
expect(decoded.sub).toBe(baseContext.ACCOUNT_SID);
2729
expect(decoded.grants.video).toEqual({
28-
room: 'demo',
30+
room: baseContext.ROOM_NAME,
2931
});
3032
expect(typeof decoded.grants.identity).toEqual('string');
3133
done();

0 commit comments

Comments
 (0)