-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathupdateMediaStorageConfiguration.js
More file actions
74 lines (64 loc) · 3.19 KB
/
updateMediaStorageConfiguration.js
File metadata and controls
74 lines (64 loc) · 3.19 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
/**
* This function updates the media storage configuration.
*/
async function updateMediaStorageConfiguration(formValues) {
$('#logs-header')[0].scrollIntoView({
block: 'start',
});
try {
console.log(
'[UPDATE_MEDIA_STORAGE_CONFIGURATION] Attempting to update media storage configuration to have media from',
formValues.channelName,
formValues.streamName ? '' : 'not',
'to be ingested and stored',
formValues.streamName ? ' in ' + formValues.streamName : '',
);
// Create KVS client
const kinesisVideoClient = new AWS.KinesisVideo.KinesisVideoClient({
region: formValues.region,
credentials: {
accessKeyId: formValues.accessKeyId,
secretAccessKey: formValues.secretAccessKey,
sessionToken: formValues.sessionToken,
},
endpoint: formValues.endpoint,
});
if (formValues.streamName) {
// We want to update the media storage configuration
// First, grab the Stream ARN
const describeStreamResponse = await kinesisVideoClient.send(new AWS.KinesisVideo.DescribeStreamCommand({ StreamName: formValues.streamName }));
const streamARN = describeStreamResponse.StreamInfo.StreamARN;
// Then, grab the Channel ARN
const describeSignalingChannelResponse = await kinesisVideoClient.send(new AWS.KinesisVideo.DescribeSignalingChannelCommand({ ChannelName: formValues.channelName }));
const channelARN = describeSignalingChannelResponse.ChannelInfo.ChannelARN;
// Finally, update the media storage configuration.
await kinesisVideoClient
.updateMediaStorageConfiguration({
ChannelARN: channelARN,
MediaStorageConfiguration: {
Status: 'ENABLED',
StreamARN: streamARN,
},
})
.promise();
console.log('[UPDATE_MEDIA_STORAGE_CONFIGURATION] Success! Media for', channelARN, 'will be ingested and stored in', streamARN);
} else {
// We want to disable the media storage configuration
// First, grab the Channel ARN
const describeSignalingChannelResponse = await kinesisVideoClient.send(new AWS.KinesisVideo.DescribeSignalingChannelCommand({ ChannelName: formValues.channelName }));
const channelARN = describeSignalingChannelResponse.ChannelInfo.ChannelARN;
// Then, update the media storage configuration.
await kinesisVideoClient
.send(new AWS.KinesisVideo.UpdateMediaStorageConfigurationCommand({
ChannelARN: channelARN,
MediaStorageConfiguration: {
Status: 'DISABLED',
StreamARN: null,
},
}));
console.log('[UPDATE_MEDIA_STORAGE_CONFIGURATION] Success! Media for', channelARN, 'will be no longer be ingested and stored');
}
} catch (e) {
console.error('[UPDATE_MEDIA_STORAGE_CONFIGURATION] Encountered error:', e);
}
}