-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
89 lines (80 loc) · 2.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const express = require('express')
const bodyParser = require('body-parser')
const crypto = require('crypto')
const cors = require('cors')
const jwt = require('jsonwebtoken');
const rp = require('request-promise');
const app = express()
const port = process.env.PORT || 4000
app.use(bodyParser.json(), cors())
app.options('*', cors());
app.post('/api/signature', (req, res) => {
const timestamp = new Date().getTime() - 30000
const msg = Buffer.from(req.body.api_key + req.body.meetingNumber + timestamp + req.body.role).toString('base64')
const hash = crypto.createHmac('sha256', req.body.api_key_secret).update(msg).digest('base64')
const signature = Buffer.from(`${req.body.api_key}.${req.body.meetingNumber}.${timestamp}.${req.body.role}.${hash}`).toString('base64')
res.json({
signature: signature
})
})
app.post('/api/zoomfeature/meetings', async (req, res) => {
const zoomAccessToken = jwt.sign(req.body.playload, req.body.api_secret);
var options = {
uri: "https://api.zoom.us/v2/users",
qs: {
status: 'active'
},
auth: {
'bearer': zoomAccessToken
},
headers: {
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
},
json: true
};
rp(options)
.then(response => {
if(response.users) {
const userId = response.users[0].id;
var options1 = {
method: 'POST',
uri: `https://api.zoom.us/v2/users/${userId}/meetings`,
auth: {
'bearer': zoomAccessToken
},
headers: {
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
},
json: true,
body: {
'settings': {
'approval_type': 0,
'host_video': true,
'join_before_host': true,
'mute_upon_entry': true,
'participant_video': true
}
}
};
rp(options1)
.then((response) => {
if(response) {
res.json({
meeting: response
})
} else {
console.log(response);
}
}).catch(err => {
console.log(err);
});
} else {
console.log(response);
}
}).catch(err => {
console.log(err);
});
})
app.listen(port, () => console.log(`Zoom Web Meeting SDK Sample Signature Node.js on port ${port}!`))