-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathjoinStorageSession.js
64 lines (57 loc) · 2.34 KB
/
joinStorageSession.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
/**
* This function calls joinStorageSession.
*/
async function joinStorageSessionManually(formValues) {
$('#logs-header')[0].scrollIntoView({
block: 'start',
});
try {
console.log('[JOIN_STORAGE_SESSION] Calling JoinStorageSession for channel', formValues.channelName);
// Create KVS client
const kinesisVideoClient = new AWS.KinesisVideo({
region: formValues.region,
accessKeyId: formValues.accessKeyId,
secretAccessKey: formValues.secretAccessKey,
sessionToken: formValues.sessionToken,
endpoint: formValues.endpoint,
});
// Step 1: Obtain the ARN of the Signaling Channel
const describeSignalingChannelResponse = await kinesisVideoClient
.describeSignalingChannel({
ChannelName: formValues.channelName,
})
.promise();
const channelARN = describeSignalingChannelResponse.ChannelInfo.ChannelARN;
// Step 2: Obtain the WEBRTC endpoint
const getSignalingChannelEndpointResponse = await kinesisVideoClient
.getSignalingChannelEndpoint({
ChannelARN: channelARN,
SingleMasterChannelEndpointConfiguration: {
Protocols: ['WEBRTC'],
Role: KVSWebRTC.Role.MASTER,
},
})
.promise();
const webrtcEndpoint = getSignalingChannelEndpointResponse.ResourceEndpointList[0].ResourceEndpoint;
const kinesisVideoWebRTCStorageClient = new AWS.KinesisVideoWebRTCStorage({
region: formValues.region,
accessKeyId: formValues.accessKeyId,
secretAccessKey: formValues.secretAccessKey,
sessionToken: formValues.sessionToken,
endpoint: webrtcEndpoint,
maxRetries: 0,
httpOptions: {
timeout: retryIntervalForJoinStorageSession,
},
});
// Step 3. Call JoinStorageSession
await kinesisVideoWebRTCStorageClient
.joinStorageSession({
channelArn: channelARN,
})
.promise();
console.log('[JOIN_STORAGE_SESSION] Finished invoking JoinStorageSession for channel', formValues.channelName);
} catch (e) {
console.error('[JOIN_STORAGE_SESSION] Encountered error:', e);
}
}