-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhandlers.js
76 lines (66 loc) · 2.18 KB
/
handlers.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
const AWS = require("aws-sdk");
const chime = new AWS.Chime();
const { v4: uuidv4 } = require("uuid");
// Set the AWS SDK Chime endpoint. The global endpoint is https://service.chime.aws.amazon.com.
chime.endpoint = new AWS.Endpoint("https://service.chime.aws.amazon.com");
const json = (statusCode, contentType, body) => {
return {
statusCode,
headers: { "content-type": contentType },
body: JSON.stringify(body),
};
};
exports.join = async (event, context, callback) => {
console.log("here");
const query = event.queryStringParameters;
let meetingId = null;
let meeting = null;
if (!query.meetingId) {
//new meeting
meetingId = uuidv4();
meeting = await chime
.createMeeting({
ClientRequestToken: meetingId,
MediaRegion: "eu-west-1",
ExternalMeetingId: meetingId,
})
.promise();
} else {
//join to old meeting
meetingId = query.meetingId;
meeting = await chime
.getMeeting({
MeetingId: meetingId,
})
.promise();
}
//We've initialized our meeting! Now let's add attendees.
const attendee = await chime
.createAttendee({
//ID of the meeting
MeetingId: meeting.Meeting.MeetingId,
//User ID that we want to associate to
ExternalUserId: `${uuidv4().substring(0, 8)}#${query.clientId}`,
})
.promise();
return json(200, "application/json", {
Info: {
Meeting: meeting,
Attendee: attendee,
},
});
};
exports.end = async (event, context) => {
const body = JSON.parse(event.body);
console.log(body.meetingId);
const deleteRequest = await chime.deleteMeeting({
MeetingId: body.meetingId
}).promise();
return json(200, "application/json", {});
};
const StaticFileHandler = require('serverless-aws-static-file-handler')
exports.index = async (event, context, callback) => {
const clientFilesPath = __dirname + "/html/";
const fileHandler = new StaticFileHandler(clientFilesPath)
return await fileHandler.get(event,context);
}