generated from akshatvg/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert.html
262 lines (231 loc) · 9.41 KB
/
alert.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
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
<!DOCTYPE html>
<html>
<head>
<title>Agora Web Sample</title>
<link rel="stylesheet" href="vendor/bootstrap.min.css">
<link rel="stylesheet" href="css/alert.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Poppins:300,400,700" rel="stylesheet">
<script src="AgoraRTCSDK-2.4.1.js"></script>
<script src="vendor/jquery.js"></script>
</head>
<body>
<h1>
BROADCAST
</h1>
<div class="Pan" style=" max-width: 400px;
width: 100%;">
<div id="div_device" class="panel panel-default">
<div class="select" style="margin-bottom: 10px;margin-top: 10px;">
<label for="audioSource">Audio source: </label><select id="audioSource" style="max-width: 90%;"></select>
</div>
<div class="select" style="margin-bottom: 10px;">
<label for="videoSource">Video source: </label><select id="videoSource"></select>
</div>
</div>
<div id="div_join" class="panel panel-default">
<div class="panel-body">
App ID: <input class="form-control" id="appId" type="text" value="" size="36"></input>
<br>
Channel: <input id="channel" type="text" value="1000" size="4"></input>
Host: <input id="video" type="checkbox" checked></input>
<br><br><br>
<div>
<button id="join" class="btn btn-primary btnc" onclick="join()">Join</button>
<button id="leave" class="btn btn-primary btnc" onclick="leave()">Leave</button>
<button id="publish" class="btn btn-primary btnc" onclick="publish()">Publish</button>
<button id="unpublish" class="btn btn-primary btnc" onclick="unpublish()">Unpublish</button>
</div>
</div>
</div>
</div>
<!--style>
.video__box{width:910px; margin:0 auto; overflow:hidden;}
.video__main{ width:810px; height:607px;float:left }
.video__list{ width:200px; height:607px; float:left;}
.video__item{ width:200px; height:174px; hei background:url(/img/icon_live.png) center center no-repeat; }
</style>
<div class="video__main">
</div>
<div class="video__list">
<div class="video__item"></div>
<div id="video" class="video__item">
<div id="agora_local"></div>
</div>
</div-->
<div id="video" style="margin:0 auto;">
<div id="agora_local" style="float:right;width:210px;height:147px;display:inline-block;"></div>
</div>
<script language="javascript">
if (!AgoraRTC.checkSystemRequirements()) {
alert("Your browser does not support WebRTC!");
}
/* select Log type */
// AgoraRTC.Logger.setLogLevel(AgoraRTC.Logger.NONE);
// AgoraRTC.Logger.setLogLevel(AgoraRTC.Logger.ERROR);
// AgoraRTC.Logger.setLogLevel(AgoraRTC.Logger.WARNING);
// AgoraRTC.Logger.setLogLevel(AgoraRTC.Logger.INFO);
// AgoraRTC.Logger.setLogLevel(AgoraRTC.Logger.DEBUG);
/* simulated data to proof setLogLevel() */
AgoraRTC.Logger.error('this is error');
AgoraRTC.Logger.warning('this is warning');
AgoraRTC.Logger.info('this is info');
AgoraRTC.Logger.debug('this is debug');
var client, localStream, camera, microphone;
var audioSelect = document.querySelector('select#audioSource');
var videoSelect = document.querySelector('select#videoSource');
function join() {
document.getElementById("join").disabled = true;
document.getElementById("video").disabled = true;
var channel_key = null;
console.log("Init AgoraRTC client with App ID: " + appId.value);
client = AgoraRTC.createClient({
mode: 'interop'
});
client.init(appId.value, function () {
console.log("AgoraRTC client initialized");
client.join(channel_key, channel.value, null, function (uid) {
console.log("User " + uid + " join channel successfully");
if (document.getElementById("video").checked) {
camera = videoSource.value;
microphone = audioSource.value;
localStream = AgoraRTC.createStream({
streamID: uid,
audio: true,
cameraId: camera,
microphoneId: microphone,
video: document.getElementById("video").checked,
screen: false
});
//localStream = AgoraRTC.createStream({streamID: uid, audio: false, cameraId: camera, microphoneId: microphone, video: false, screen: true, extensionId: 'minllpmhdgpndnkomcoccfekfegnlikg'});
if (document.getElementById("video").checked) {
localStream.setVideoProfile('720p_3');
}
// The user has granted access to the camera and mic.
localStream.on("accessAllowed", function () {
console.log("accessAllowed");
$('video').addClass('as');
});
// The user has denied access to the camera and mic.
localStream.on("accessDenied", function () {
console.log("accessDenied");
$('video').addClass('as');
});
localStream.init(function () {
console.log("getUserMedia successfully");
localStream.play('agora_local');
client.publish(localStream, function (err) {
console.log("Publish local stream error: " + err);
});
client.on('stream-published', function (evt) {
console.log("Publish local stream successfully");
$('video').addClass('as')
});
}, function (err) {
console.log("getUserMedia failed", err);
});
}
}, function (err) {
console.log("Join channel failed", err);
});
}, function (err) {
console.log("AgoraRTC client init failed", err);
});
channelKey = "";
client.on('error', function (err) {
$('video').addClass('as')
console.log("Got error msg:", err.reason);
if (err.reason === 'DYNAMIC_KEY_TIMEOUT') {
client.renewChannelKey(channelKey, function () {
console.log("Renew channel key successfully");
}, function (err) {
console.log("Renew channel key failed: ", err);
});
}
});
client.on('stream-added', function (evt) {
$('video').addClass('as');
var stream = evt.stream;
console.log("New stream added: " + stream.getId());
console.log("Subscribe ", stream);
client.subscribe(stream, function (err) {
console.log("Subscribe stream failed", err);
});
$('video').addClass('as');
});
client.on('stream-subscribed', function (evt) {
var stream = evt.stream;
console.log("Subscribe remote stream successfully: " + stream.getId());
$('video').addClass('as')
if ($('div#video #agora_remote' + stream.getId()).length === 0) {
$('div#video').append('<div id="agora_remote' + stream.getId() +
'" style="float:left; width:210px;height:147px;display:inline-block;"></div>');
}
stream.play('agora_remote' + stream.getId());
$('video').addClass('as');
});
client.on('stream-removed', function (evt) {
var stream = evt.stream;
stream.stop();
$('#agora_remote' + stream.getId()).remove();
console.log("Remote stream is removed " + stream.getId());
$('video').addClass('as');
});
client.on('peer-leave', function (evt) {
var stream = evt.stream;
if (stream) {
stream.stop();
$('#agora_remote' + stream.getId()).remove();
console.log(evt.uid + " leaved from this channel");
}
$('video').addClass('as');
});
}
function leave() {
document.getElementById("leave").disabled = true;
client.leave(function () {
console.log("Leavel channel successfully");
}, function (err) {
console.log("Leave channel failed");
});
$('video').addClass('as');
}
function publish() {
document.getElementById("publish").disabled = true;
document.getElementById("unpublish").disabled = false;
client.publish(localStream, function (err) {
console.log("Publish local stream error: " + err);
});
$('video').addClass('as');
}
function unpublish() {
document.getElementById("publish").disabled = false;
document.getElementById("unpublish").disabled = true;
client.unpublish(localStream, function (err) {
console.log("Unpublish local stream failed" + err);
});
}
function getDevices() {
AgoraRTC.getDevices(function (devices) {
for (var i = 0; i !== devices.length; ++i) {
var device = devices[i];
var option = document.createElement('option');
option.value = device.deviceId;
if (device.kind === 'audioinput') {
option.text = device.label || 'microphone ' + (audioSelect.length + 1);
audioSelect.appendChild(option);
} else if (device.kind === 'videoinput') {
option.text = device.label || 'camera ' + (videoSelect.length + 1);
videoSelect.appendChild(option);
} else {
console.log('Some other kind of source/device: ', device);
}
}
});
}
//audioSelect.onchange = getDevices;
//videoSelect.onchange = getDevices;
getDevices();
</script>
</body>
</html>