forked from Ericsson/c3-web-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultiClientConferenceCall.html
More file actions
278 lines (260 loc) · 8.29 KB
/
multiClientConferenceCall.html
File metadata and controls
278 lines (260 loc) · 8.29 KB
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!--
* 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>
<meta charset="utf-8">
<title>MultiClientConferenceCall</title>
<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>
.remoteVideo {
max-width: 16vw;
max-height: 9vw;
margin-top: 1vw;
border: solid white 1px;
}
</style>
</head>
<body>
<header></header>
<main>
<section>
<div class="about">
<h3>Multi Client Conference Call example</h3>
This advanced example shows how a complete conferencing application can be built using <a href="https://get.cct.ericsson.net/latest/docs/reference/ConferenceCall.html">ConferenceCall</a>, <a href="https://get.cct.ericsson.net/latest/docs/reference/MediaBroadcaster.html">MediaBroadcaster</a>, <a href="https://get.cct.ericsson.net/latest/docs/reference/MediaSwitcher.html">MediaSwitcher</a> and <a href="https://get.cct.ericsson.net/latest/docs/reference/AudioMeter.html">AudioMeter</a>.
</div>
<div class="peer-link">
<h3 class="peer-link-title"></h3>
<input class="peer-link-input" type="url" value="" size="55">
</div>
</section>
<div class="margins centered column">
<div class="video-container small">
<video id="selfVideo" muted autoplay></video>
<label>Self view</label>
</div>
<div class="video-container large">
<video id="bigVideo" muted autoplay></video>
<label>Active speaker</label>
</div>
<div id="remoteVideoContainer" class="row"></div>
<div id="controlsContainer" class="row">
<button class="margins" type="button" id="audioButton">Microphone: On</button>
<button class="margins" type="button" id="videoButton">Camera: On</button>
</div>
</div>
<footer></footer>
</main>
<script type="text/javascript">
'use strict'
cct.log.setLogLevel('example', cct.log.ALL)
cct.log.setLogLevel('media-switcher', cct.log.ALL)
cct.log.setLogLevel('media-broadcaster', cct.log.ALL)
cct.log.setLogLevel('conference-call', cct.log.ALL)
var bigVideo = document.getElementById('bigVideo')
var selfVideo = document.getElementById('selfVideo')
var remoteVideoContainer = document.getElementById('remoteVideoContainer')
var microphone
var hdCamera
var sdCamera
// var audioMeters = {}
var client
var room
var videoBroadcaster
var audioBroadcaster
var switcher
cct.webRtcReady()
.then(setupMediaSources)
.then(setupConference)
.then(setupSwitcher)
.then(setupVideoBroadcaster)
.then(setupAudioBroadcaster)
.then(setupButtonListeners)
.catch(function (err) {
cct.log.error('example', 'Failed to setup conference, ' + err)
})
function setupMediaSources() {
cct.log.info('example', 'setting up media sources')
hdCamera = new cct.DeviceSource({
video: {
aspectRatio: 16 / 9,
},
})
sdCamera = new cct.DeviceSource({
video: {
width: {
max: 120,
},
height: {
max: 90,
},
aspectRatio: 16 / 9,
},
})
sdCamera.connect(selfVideo)
selfVideo.onclick = function () {
cct.log.info('example', 'Setting self active')
switcher.setActive()
}
microphone = new cct.DeviceSource({
audio: true,
})
}
function setupConference() {
cct.log.info('example', 'setting up client')
client = new cct.Client({
iceServers: EXAMPLE_UTILS_ICE_SERVERS,
})
return PeerConnecter.clientInRoom(client).then(function (connecter) {
cct.log.info('example', 'setting up conference')
room = connecter.room
return Promise.resolve(room.startConference())
})
}
function setupSwitcher(conference) {
cct.log.info('example', 'setting up switcher')
switcher = new cct.MediaSwitcher()
hdCamera.connect(switcher)
switcher.connect(bigVideo)
conference.attach('videoSwitch', switcher)
// addAudioMeter(conference._userId, microphone)
// startVoiceSwitching(switcher, conference._userId)
switcher.on('activeSpeaker', function (newActive) {
cct.log.info('example', 'Switched to ' + newActive)
})
return conference
}
function setupAudioBroadcaster(conference) {
cct.log.info('example', 'setting up audio broadcast')
audioBroadcaster = new cct.MediaBroadcaster()
microphone.connect(audioBroadcaster)
conference.attach('audioBroadcast', audioBroadcaster)
audioBroadcaster.on('remoteSource', function (event) {
var peer = event.peer
var source = event.source
if (event.source) {
addRemoteAudioElement(peer, source)
} else {
removeRemoteAudioElement(peer)
}
})
return conference
}
function setupVideoBroadcaster(conference) {
cct.log.info('example', 'setting up video broadcast')
videoBroadcaster = new cct.MediaBroadcaster()
sdCamera.connect(videoBroadcaster)
conference.attach('videoBroadcast', videoBroadcaster)
videoBroadcaster.on('remoteSource', function (event) {
var peer = event.peer
var source = event.source
if (event.source) {
addRemoteVideoElement(peer, source)
} else {
removeRemoteVideoElement(peer)
}
})
return conference
}
function setupButtonListeners() {
cct.log.info('example', 'setting up button listeners')
var audioButton = document.getElementById('audioButton')
var videoButton = document.getElementById('videoButton')
audioButton.onclick = function () {
microphone.mute.audio = !microphone.mute.audio
audioButton.innerText = microphone.mute.audio ? 'Microphone: Off' : 'Microphone: On'
}
videoButton.onclick = function () {
hdCamera.mute.video = !hdCamera.mute.video
sdCamera.mute.video = !sdCamera.mute.video
videoButton.innerText = hdCamera.mute.video ? 'Camera: Off' : 'Camera: On'
}
}
/*
function startVoiceSwitching(switcher, selfId) {
setInterval(function () {
var king = switcher.liveMembers.concat().sort()[0]
if (king === selfId) {
var loudestPeer
var loudestLevel = 0
for (var peer in audioMeters) {
var peerLevel = audioMeters[peer].filtered
if (peerLevel > loudestLevel) {
loudestLevel = peerLevel
loudestPeer = peer
}
}
switcher.setActive(loudestPeer)
}
}, 5000)
}
*//*
function addAudioMeter(peer, source) {
var meter = audioMeters[peer] || new cct.AudioMeter()
source.connect(meter)
audioMeters[peer] = meter
}
*//*
function removeAudioMeter(peer) {
var meter = audioMeters[peer]
if (meter) {
meter.stop()
delete audioMeters[peer]
}
}
*/
function addRemoteVideoElement(peer, source) {
var videoId = 'video:' + peer
var videoEl = document.getElementById(videoId)
if (!videoEl) {
videoEl = document.createElement('video')
videoEl.id = videoId
videoEl.autoplay = true
videoEl.className = 'remoteVideo'
videoEl.onclick = function () {
cct.log.info('example', 'Setting active: ' + peer)
switcher.setActive(peer)
}
remoteVideoContainer.appendChild(videoEl)
}
source.connect(videoEl)
}
function removeRemoteVideoElement(peer) {
var videoEl = document.getElementById('video:' + peer)
remoteVideoContainer.removeChild(videoEl)
}
function addRemoteAudioElement(peer, source) {
var audioId = 'audio:' + peer
var audioEl = document.getElementById(audioId)
if (!audioEl) {
audioEl = document.createElement('audio')
audioEl.id = audioId
audioEl.autoplay = true
document.body.appendChild(audioEl)
}
source.connect(audioEl)
}
function removeRemoteAudioElement(peer) {
var audioEl = document.getElementById('audio:' + peer)
document.body.removeChild(audioEl)
}
</script>
</body>
</html>