-
Notifications
You must be signed in to change notification settings - Fork 144
/
Copy pathjoinStorageSessionAsViewer.js
65 lines (58 loc) · 2.53 KB
/
joinStorageSessionAsViewer.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
/**
* This function calls joinStorageSessionAsViewer.
*/
async function joinStorageSessionAsViewerManually(formValues) {
$('#logs-header')[0].scrollIntoView({
block: 'start',
});
try {
console.log('[JOIN_STORAGE_SESSION_AS_VIEWER] Calling JoinStorageSessionAsViewer for channel', formValues.channelName, 'and clientId', formValues.clientId);
// 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.VIEWER,
},
})
.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
.joinStorageSessionAsViewer({
channelArn: channelARN,
clientId: formValues.clientId,
})
.promise();
console.log('[JOIN_STORAGE_SESSION_AS_VIEWER] Finished invoking JoinStorageSessionAsViewer for channel', formValues.channelName, 'and clientId', formValues.clientId);
} catch (e) {
console.error('[JOIN_STORAGE_SESSION_AS_VIEWER] Encountered error:', e);
}
}