@@ -5,19 +5,36 @@ const config = require('config')
5
5
6
6
// get & parse all Zoom account credentials in an in-memory array
7
7
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
+ }
10
30
11
31
/**
12
32
* Generate a Zoom JWT bearer access token
13
33
*
14
34
* @returns JWT bearer access token for Zoom API access
15
35
*/
16
36
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 ( )
21
38
22
39
const token = jwt . sign (
23
40
{ } ,
@@ -29,8 +46,6 @@ async function generateZoomJWTBearerAccessToken () {
29
46
}
30
47
)
31
48
32
- // reduce number of available Zoom accounts after each usage
33
- AVAILABLE_ZOOM_ACCOUNTS --
34
49
return token
35
50
}
36
51
@@ -40,24 +55,19 @@ async function generateZoomJWTBearerAccessToken () {
40
55
* @returns Zoom API response
41
56
*/
42
57
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 ( )
46
59
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
+ } )
56
69
57
- return res . data
58
- } else {
59
- throw new Error ( 'No Zoom accounts available to use.' )
60
- }
70
+ return res . data
61
71
}
62
72
63
73
/**
0 commit comments