-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrenderer.js
74 lines (59 loc) · 2.54 KB
/
renderer.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
// Limitations: The bot can only be in a single call at a time. Multiple
// client crendentials app would be needed to be in multiple calls at
// the same time.
// Specify the file circuit.js which is the browser SDK to get access to WebRTC APIs.
const Circuit = require('circuit-sdk/circuit.js');
const config = require('electron').remote.require('./config.json');
// Create circuit SDK client instance
const client = new Circuit.Client(config.sandbox.options);
async function stream() {
try {
let conv = await client.getConversationById(config.sandbox.conversation);
let call = await client.findCall(conv.rtcSessionId);
if (!call) {
call = await client.startConference(config.sandbox.conversation, {audio: false, video: false});
} else if (call.isRemote) {
await client.joinConference(call.callId, {audio: false, video: false})
}
// Wait 2s second before setting the stream to allow the initial negotiation to finish
// Alternatively we could also listen for callStatus event of reason sdpConnected
await sleep(2000);
// Check if the already streaming on the screenshare stream
if (!call.localMediaType.desktop) {
let constraints = { audio: false, video: { width: 1920, height: 1080 } };
let mediaStream = await navigator.mediaDevices.getUserMedia(constraints);
// For Debugging show on index.html page
/*
let video = document.querySelector('video');
video.srcObject = mediaStream;
video.onloadedmetadata = e => video.play();
*/
// Send stream on Circuit's screenshare stream. setScreenshareStream or setAudioVideoStream
// can be used. setAudioVideoStream includes the audio track as well.
//await client.setScreenshareStream(call.callId, mediaStream);
await client.setAudioVideoStream(call.callId, mediaStream);
}
} catch (err) {
console.error(`${err.name}: ${err.message}`);
}
}
// Helper sleep function
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Program (async IIFE function)
(async () => {
try {
// Logon
const user = await client.logon();
console.log(`Logged on as bot: ${user.emailAddress}`);
// Start conference if not yet started/joined and start streaming
await stream();
// Ensure call is always up and stream is sent. E.g. bot could have been dropped
setInterval(async () => await stream(), 10 * 1000);
} catch (ex) {
console.error(ex);
}
})();
// Print all events for debugging
Circuit.supportedEvents.forEach(e => client.addEventListener(e, console.log));