-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathupdateMediaStorageConfiguration.js
73 lines (63 loc) · 3.04 KB
/
updateMediaStorageConfiguration.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
/**
* 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({
region: formValues.region,
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.describeStream({ StreamName: formValues.streamName }).promise();
const streamARN = describeStreamResponse.StreamInfo.StreamARN;
// Then, grab the Channel ARN
const describeSignalingChannelResponse = await kinesisVideoClient.describeSignalingChannel({ ChannelName: formValues.channelName }).promise();
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.describeSignalingChannel({ ChannelName: formValues.channelName }).promise();
const channelARN = describeSignalingChannelResponse.ChannelInfo.ChannelARN;
// Then, update the media storage configuration.
await kinesisVideoClient
.updateMediaStorageConfiguration({
ChannelARN: channelARN,
MediaStorageConfiguration: {
Status: 'DISABLED',
StreamARN: null,
},
})
.promise();
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);
}
}