Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (70 loc) · 3.09 KB
/
Copy pathindex.js
File metadata and controls
95 lines (70 loc) · 3.09 KB
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
import { writeTranscriptToVtt } from './writeTranscriptToVtt.js';
// Load secrets from .env
import dotenv from 'dotenv';
dotenv.config();
// Import the RTMS SDK
import rtms from "@zoom/rtms";
import { startAuthenticatedWebhookServer } from './authenticatedWebhookServer.js';
import { closeHttpServer, installGracefulShutdown } from '../../library/javascript/commonHelpers/gracefulShutdown.js';
function setVideoParamsCompat(client, params) {
if (typeof client.setVideoParams === "function") return client.setVideoParams(params);
if (typeof client.setVideoParameters === "function") return client.setVideoParameters(params);
throw new Error("RTMS SDK client missing setVideoParams/setVideoParameters");
}
let meetingUUID;
const clients = new Set();
// Set up webhook event handler to receive RTMS events from Zoom
const webhookServer = startAuthenticatedWebhookServer(({ event, payload }) => {
console.log(`Received webhook event: ${event}`);
if (event === "meeting.rtms_started") {
meetingUUID = payload.meeting_uuid;
} else if (event === "meeting.rtms_stopped") {
return;
} else {
return;
}
// Create a client instance for this specific meeting
const client = new rtms.Client();
clients.add(client);
// client.setAudioParameters({
// codec: rtms.AudioCodec.L16,
// /** The sample rate in Hz (e.g., 8000, 16000, 44100) */
// sampleRate: rtms.AudioSampleRate.SR_16K,
// /** The number of audio channels (1=mono, 2=stereo) */
// channel: rtms.AudioChannel.MONO,
// /** Additional data options for audio processing */
// dataOpt: rtms.AudioDataOption.AUDIO_MULTI_STREAMS,
// /** The duration of each audio frame in milliseconds */
// duration: 100,
// /** The size of each audio frame in samples */
// frameSize:640
// });
// Configure HD video (720p H.264 at 30fps)
setVideoParamsCompat(client, {
contentType: rtms.VideoContentType.RAW_VIDEO,
codec: rtms.VideoCodec.H264,
resolution: rtms.VideoResolution.HD,
dataOpt: rtms.VideoDataOption.VIDEO_SINGLE_ACTIVE_STREAM,
fps: 25
});
// Set up video data handler
client.onVideoData((data, size, timestamp, metadata) => {
// console.log(`Video data: ${size} bytes from ${metadata.userName}`);
});
// Set up audio data handler
client.onAudioData((data, size, timestamp, metadata) => {
// console.log(`Audio data: ${size} bytes from ${metadata.userName}`);
});
// Set up transcript data handler
client.onTranscriptData((data, size, timestamp, metadata) => {
console.log(`${metadata.userName}: ${data}`);
writeTranscriptToVtt(metadata.userName, timestamp / 1000, data, meetingUUID);
});
// Join the meeting using the webhook payload directly
client.join(payload);
});
installGracefulShutdown({ name: 'Transcript SDK', cleanup: async () => {
await closeHttpServer(webhookServer);
await Promise.allSettled([...clients].map((client) => Promise.resolve(client.leave())));
clients.clear();
} });