-
Notifications
You must be signed in to change notification settings - Fork 21
/
Meeting.js
169 lines (155 loc) · 5.86 KB
/
Meeting.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import React, { useState, useEffect } from 'react';
import {
useMeetingManager,
useLocalVideo,
useAudioVideo,
ControlBar,
ControlBarButton,
Meeting,
LeaveMeeting,
AudioInputControl,
DeviceLabels,
VideoTileGrid,
Remove,
VideoInputControl,
AudioOutputControl,
MeetingStatus,
useMeetingStatus,
} from 'amazon-chime-sdk-component-library-react';
import Container from '@cloudscape-design/components/container';
import Header from '@cloudscape-design/components/header';
import SpaceBetween from '@cloudscape-design/components/space-between';
import { MeetingSessionConfiguration } from 'amazon-chime-sdk-js';
import './App.css';
import { AmplifyConfig as config } from './Config';
import { Amplify, API, Auth } from 'aws-amplify';
import '@aws-amplify/ui-react/styles.css';
Amplify.configure(config);
Amplify.Logger.LOG_LEVEL = 'DEBUG';
console.log(config.API);
export const Meetings = () => {
const meetingManager = useMeetingManager();
const meetingStatus = useMeetingStatus();
const [meetingId, setMeetingId] = useState('');
const [attendeeId, setAttendeeId] = useState('');
const [transcripts, setTranscripts] = useState([]);
const [lines, setLine] = useState([]);
const [currentLine, setCurrentLine] = useState('');
const audioVideo = useAudioVideo();
const { toggleVideo } = useLocalVideo();
useEffect(() => {
async function tog() {
if (meetingStatus === MeetingStatus.Succeeded) {
await toggleVideo();
}
}
tog();
}, [meetingStatus]);
useEffect(() => {
if (transcripts) {
if (transcripts.results !== undefined) {
console.log(`Transcript Results: ${JSON.stringify(transcripts.results)}`);
if (!transcripts.results[0].isPartial) {
setLine((lines) => [
...lines,
`${transcripts.results[0].alternatives[0].items[0].attendee.externalUserId}: ${transcripts.results[0].alternatives[0].transcript}`,
]);
setCurrentLine('');
} else {
setCurrentLine(
`${transcripts.results[0].alternatives[0].items[0].attendee.externalUserId}: ${transcripts.results[0].alternatives[0].transcript}`,
);
}
}
}
}, [transcripts]);
useEffect(() => {
if (audioVideo) {
audioVideo.transcriptionController?.subscribeToTranscriptEvent((transcriptEvent) => {
setTranscripts(transcriptEvent);
});
}
}, [audioVideo]);
const JoinButtonProps = {
icon: <Meeting />,
onClick: (event) => handleJoin(event),
label: 'Join',
};
const LeaveButtonProps = {
icon: <LeaveMeeting />,
onClick: (event) => handleLeave(event),
label: 'Leave',
};
const EndButtonProps = {
icon: <Remove />,
onClick: (event) => handleEnd(event),
label: 'End',
};
const handleLeave = async (event) => {
await meetingManager.leave();
};
const handleEnd = async (event) => {
console.log(`Auth ${JSON.stringify(await Auth.currentUserInfo())}`);
event.preventDefault();
try {
await API.post('meetingApi', 'end', { body: { meetingId: meetingId } });
setLine([]);
} catch (err) {
console.log(err);
}
};
const handleJoin = async (event) => {
event.preventDefault();
const email = (await Auth.currentUserInfo()).attributes.email;
console.log(email);
try {
const joinResponse = await API.post('meetingApi', 'meeting', { body: { email: email } });
const meetingSessionConfiguration = new MeetingSessionConfiguration(
joinResponse.Meeting,
joinResponse.Attendee,
);
const options = {
deviceLabels: DeviceLabels.AudioAndVideo,
};
await meetingManager.join(meetingSessionConfiguration, options);
await meetingManager.start();
meetingManager.invokeDeviceProvider(DeviceLabels.AudioAndVideo);
setMeetingId(joinResponse.Meeting.MeetingId);
setAttendeeId(joinResponse.Attendee.AttendeeId);
} catch (err) {
console.log(err);
}
};
return (
<SpaceBetween direction="horizontal" size="xs">
<SpaceBetween direction="vertical" size="l">
<Container header={<Header variant="h2">Amazon Chime SDK Meeting</Header>}>
<div style={{ height: '600px', width: '720px' }}>
<VideoTileGrid />
</div>
</Container>
<ControlBar showLabels={true} responsive={true} layout="undocked-horizontal">
<ControlBarButton {...JoinButtonProps} />
<ControlBarButton {...LeaveButtonProps} />
<ControlBarButton {...EndButtonProps} />
<AudioInputControl />
<AudioOutputControl />
<VideoInputControl />
</ControlBar>
</SpaceBetween>
<Container header={<Header variant="h2">Transcription</Header>}>
<SpaceBetween size="xs">
<div style={{ height: '600px', width: '240px' }}>
{lines.slice(Math.max(lines.length - 10, 0)).map((line, index) => (
<div key={index}>
{line}
<br />
</div>
))}
{currentLine.length > 0 && currentLine}
</div>
</SpaceBetween>
</Container>
</SpaceBetween>
);
};