forked from Ericsson/c3-web-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conferenceCall.html
224 lines (201 loc) · 6.71 KB
/
conferenceCall.html
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<!--
* Copyright (C) 2016 Ericsson AB. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<title>Conference Call</title>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="../resources/main.css">
<link rel="icon" href="../resources/favicon.ico">
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-promise/3.2.1/es6-promise.min.js"></script>
<script type="text/javascript" src="https://get.cct.ericsson.net/latest/cct.js"></script>
<script type="text/javascript" src="../exampleUtils.js"></script>
<style type="text/css">
.activespeaker {
border: 2px solid #4f8;
border-radius: 10px;
box-sizing: border-box;
}
</style>
</head>
<body>
<header></header>
<main class="centered">
<br>
<div class="video-container large margins">
<video class="remote" id="remote" muted autoplay></video>
<label>Active speaker</label>
</div>
<p>
Click one of the videos below to make that user the "active speaker".
</p>
<section>
<div class="video-container small margins">
<video id="self1" muted autoplay></video>
<label>Self view 1</label>
</div>
<div class="video-container small margins">
<video id="self2" muted autoplay></video>
<label>Self view 2</label>
</div>
<div class="video-container small margins">
<video id="self3" muted autoplay></video>
<label>Self view 3</label>
</div>
</section>
<footer></footer>
</main>
<script type="text/javascript">
'use strict'
var el = {
self1: document.getElementById('self1'),
self2: document.getElementById('self2'),
self3: document.getElementById('self3'),
remote: document.getElementById('remote'),
}
cct.log.setLogLevel('example', cct.log.ALL)
cct.log.color = true
var client1 = new cct.Client()
var client2 = new cct.Client()
var client3 = new cct.Client()
Promise.all([
cct.Auth.anonymous({serverUrl: getCctAddress()}).then(client1.auth),
cct.Auth.anonymous({serverUrl: getCctAddress()}).then(client2.auth),
cct.Auth.anonymous({serverUrl: getCctAddress()}).then(client3.auth),
]).then(joinRoom)
.then(setupConference)
.catch(function (error) {
cct.log.error('example', 'Failed to setup conference, ' + error)
})
function joinRoom() {
cct.log.info('example', 'Joining the same room')
return Promise.all([
client1.createRoom({
invite: [client2.user, client3.user],
}),
client2.once('invite').then(function (room) {
return room.join()
}),
client3.once('invite').then(function (room) {
return room.join()
}),
])
}
var camera1
var camera2
var camera3
var conference1
var conference2
var conference3
var switch1
var switch2
var switch3
var broadcaster1
var broadcaster2
var broadcaster3
function setupConference(rooms) {
// Create some camera sources that will be streamed between the participants.
camera1 = camera2 = camera3 = new cct.DeviceSource({
audio: false,
video: true,
})
cct.log.info('example', 'All three clients in same room, initiating conference')
// Start the conference(s)
conference1 = rooms[0].startConference()
conference2 = rooms[1].startConference()
conference3 = rooms[2].startConference()
cct.log.info('example', 'Setting up media switching')
// Create some switchers
switch1 = new cct.MediaSwitcher()
switch2 = new cct.MediaSwitcher()
switch3 = new cct.MediaSwitcher()
// Attach them to their respective conference
conference1.attach('switch', switch1)
conference2.attach('switch', switch2)
conference3.attach('switch', switch3)
// ..and set the input of each switcher
switch1.output.connect(el.remote)
camera1.connect(switch1)
camera2.connect(switch2)
camera3.connect(switch3)
cct.log.info('example', 'Setting up media broadcasting')
// Create some broadcasters
broadcaster1 = new cct.MediaBroadcaster()
broadcaster2 = new cct.MediaBroadcaster()
broadcaster3 = new cct.MediaBroadcaster()
// Attach them to their respective conference
conference1.attach('thumb', broadcaster1)
conference2.attach('thumb', broadcaster2)
conference3.attach('thumb', broadcaster3)
// ..and set the input of each broadcaster.
// this will cause the camera stream to be sent to all other participants.
// NOTE: Broadcasting high-res video requires a LOT of CPU and bandwidth, especially for larger conferences.
// Consider using a DeviceSource with lower resolution/framerate for the smaller videos.
camera1.connect(broadcaster1)
camera2.connect(broadcaster2)
camera3.connect(broadcaster3)
camera1.connect(el.self1)
// Listen for the other broadcasters to connect, set output accordingly.
broadcaster1.on('remoteSource:' + client2.user.id, function (source) {
cct.log.info('example', 'Got a remote source from Client2')
source.connect(el.self2)
})
broadcaster1.on('remoteSource:' + client3.user.id, function (source) {
cct.log.info('example', 'Got a remote source from Client3')
source.connect(el.self3)
})
// Listen for switching events from the switcher.
// Update UI to reflect who the new active speaker is.
switch1.on('activeSpeaker', function (newActive, oldActive) {
cct.log.info('example', 'Switched from ' + oldActive + ' to ' + newActive)
switch (oldActive) {
case client1.user.id:
el.self1.classList.remove('activespeaker')
break
case client2.user.id:
el.self2.classList.remove('activespeaker')
break
case client3.user.id:
el.self3.classList.remove('activespeaker')
break
}
switch (newActive) {
case client1.user.id:
el.self1.classList.add('activespeaker')
break
case client2.user.id:
el.self2.classList.add('activespeaker')
break
case client3.user.id:
el.self3.classList.add('activespeaker')
break
}
})
// Click a thumbnail video to switch the active speaker.
el.self1.onclick = function () {
switch1.setActive() // Set client1 to active
}
el.self2.onclick = function () {
switch1.setActive(client2.user.id) // Set client2 to active
}
el.self3.onclick = function () {
switch3.setActive() // Set client3 to active.
}
switch1.setActive()
}
</script>
</body>
</html>