-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·60 lines (52 loc) · 2.21 KB
/
app.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
var token = 'T1==cGFydG5lcl9pZD00NTkzMTM4MiZzaWc9NGY4NDQyMzc5ZDNiZTczNmFiYWI3OTljMmUxZjQxNjEzYWFmYjlmNTpzZXNzaW9uX2lkPTFfTVg0ME5Ua3pNVE00TW41LU1UVXdNVGd5TXpnd01USXpNbjVTYXpWYUwwMHZkRUpGVmpsRU5sYzJlRXhKTUd0R2FrOS1VSDQmY3JlYXRlX3RpbWU9MTUwMTgyMzgwMSZyb2xlPXB1Ymxpc2hlciZub25jZT0xNTAxODIzODAxLjMzMDIxODY1NDYzODE2';
var session_key = '1_MX40NTkzMTM4Mn5-MTUwMTgyMzgwMTIzMn5SazVaL00vdEJFVjlENlc2eExJMGtGak9-UH4';
var api_key = '45931382';
// var pubOptions = {publishAudio:true, publishVideo:false};
// connect to open tok api using client side library
var session = OT.initSession(api_key, session_key);
// when other user is connected we want to show them
// in subscriber div element
session.on('streamCreated', function (event) {
session.subscribe(event.stream, 'subscriber', {
insertMode: 'append',
width: '100%',
height: '100%'
});
});
// when first user loads this page we want him to
// be shown in publisher div element
var publisher = OT.initPublisher('publisher', {
insertMode: 'append',
width: '100%',
height: '100%'
});
// if we have any connection error let's put an alert box
session.connect(token, function (error) {
var publisher = OT.initPublisher('camera');
session.publish(publisher, function () {
screenshare();
});
if (error) {
alert(error.message);
} else {
session.publish(publisher);
}
});
OT.registerScreenSharingExtension('chrome', extensionId, 2);
function screenshare() {
OT.checkScreenSharingCapability(function (response) {
if (!response.supported || response.extensionRegistered === false) {
alert('This browser does not support screen sharing.');
} else if (response.extensionInstalled === false) {
alert('Please install the screen sharing extension and load your app over https.');
} else {
// Screen sharing is available. Publish the screen.
var screenSharingPublisher = OT.initPublisher('screen-preview', {videoSource: 'screen'});
session.publish(screenSharingPublisher, function (error) {
if (error) {
alert('Could not share the screen: ' + error.message);
}
});
}
});
}