Skip to content

Commit c120501

Browse files
committed
fix generating Zoom link in round-robin
1 parent 013b57e commit c120501

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

src/services/ZoomService.js

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,36 @@ const config = require('config')
55

66
// get & parse all Zoom account credentials in an in-memory array
77
const ALL_ZOOM_ACCOUNTS = _.split(config.ZOOM_ACCOUNTS, ',')
8-
// this is the number of Zoom accounts left to use. This number gets reduced after each usage
9-
let AVAILABLE_ZOOM_ACCOUNTS = ALL_ZOOM_ACCOUNTS.length
8+
let currentZoomAccountIndex = -1
9+
10+
/**
11+
* Get Zoom account credentials from the list credentials by round robin
12+
*
13+
* @returns { zoomAccountApiKey: string, zoomAccountApiSecret: string } zoom account credentials
14+
*/
15+
function getZoomAccountByRoundRobin () {
16+
if (ALL_ZOOM_ACCOUNTS.length === 0) {
17+
throw new Error('No Zoom accounts is configured by "ALL_ZOOM_ACCOUNTS" environment variable.')
18+
}
19+
20+
const nextIndex = currentZoomAccountIndex + 1
21+
currentZoomAccountIndex = nextIndex >= ALL_ZOOM_ACCOUNTS.length ? 0 : nextIndex
22+
23+
const [zoomAccountApiKey, zoomAccountApiSecret] = ALL_ZOOM_ACCOUNTS[currentZoomAccountIndex].split(':')
24+
25+
return {
26+
zoomAccountApiKey,
27+
zoomAccountApiSecret
28+
}
29+
}
1030

1131
/**
1232
* Generate a Zoom JWT bearer access token
1333
*
1434
* @returns JWT bearer access token for Zoom API access
1535
*/
1636
async function generateZoomJWTBearerAccessToken () {
17-
// parse the Zoom account API key & secret from the credentials string
18-
const zoomAccountCredentials = _.split(ALL_ZOOM_ACCOUNTS[AVAILABLE_ZOOM_ACCOUNTS - 1], ':')
19-
const zoomAccountApiKey = zoomAccountCredentials[0]
20-
const zoomAccountApiSecret = zoomAccountCredentials[1]
37+
const { zoomAccountApiKey, zoomAccountApiSecret } = getZoomAccountByRoundRobin()
2138

2239
const token = jwt.sign(
2340
{},
@@ -29,8 +46,6 @@ async function generateZoomJWTBearerAccessToken () {
2946
}
3047
)
3148

32-
// reduce number of available Zoom accounts after each usage
33-
AVAILABLE_ZOOM_ACCOUNTS--
3449
return token
3550
}
3651

@@ -40,24 +55,19 @@ async function generateZoomJWTBearerAccessToken () {
4055
* @returns Zoom API response
4156
*/
4257
async function createZoomMeeting () {
43-
// only proceed if there are Zoom accounts available for use
44-
if (AVAILABLE_ZOOM_ACCOUNTS > 0) {
45-
const accessToken = await generateZoomJWTBearerAccessToken()
58+
const accessToken = await generateZoomJWTBearerAccessToken()
4659

47-
// POST request details in Zoom API docs:
48-
// https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingcreate
49-
const res = await axios.post('https://api.zoom.us/v2/users/me/meetings', {
50-
type: 3
51-
}, {
52-
headers: {
53-
Authorization: `Bearer ${accessToken}`
54-
}
55-
})
60+
// POST request details in Zoom API docs:
61+
// https://marketplace.zoom.us/docs/api-reference/zoom-api/meetings/meetingcreate
62+
const res = await axios.post('https://api.zoom.us/v2/users/me/meetings', {
63+
type: 3
64+
}, {
65+
headers: {
66+
Authorization: `Bearer ${accessToken}`
67+
}
68+
})
5669

57-
return res.data
58-
} else {
59-
throw new Error('No Zoom accounts available to use.')
60-
}
70+
return res.data
6171
}
6272

6373
/**

0 commit comments

Comments
 (0)