-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.html
233 lines (205 loc) · 8.41 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Agora Web Sample</title>
<link rel="stylesheet" href="vendor/bootstrap.min.css">
<script src="AgoraRTCSDK-2.1.0.js"></script>
<script src="vendor/jquery.js"></script>
</head>
<body>
<div id="div_device" class="panel panel-default" style="display:none">
<div class="select">
<label for="audioSource">Audio source: </label><select id="audioSource"></select>
</div>
<div class="select">
<label for="videoSource">Video source: </label><select id="videoSource"></select>
</div>
</div>
<div id="debugdata">
</div>
<div id="div_join" class="panel panel-default">
<div class="panel-body">
Channel: <input id="channel" type="text" value="demoChannel1" size="4"></input>
Video: <input id="video" type="checkbox" checked></input>
API Key: <input id="key" type="text" value="your key here" />
<button id="join" class="btn btn-primary" onclick="join()">Join</button>
<button id="leave" class="btn btn-primary" onclick="leave()">Leave</button>
<button id="publish" class="btn btn-primary" onclick="publish()">Publish</button>
<button id="unpublish" class="btn btn-primary" onclick="unpublish()">Unpublish</button>
</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("browser is no 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, localId, remoteId;
var audioSelect = document.querySelector('select#audioSource');
var videoSelect = document.querySelector('select#videoSource');
function debugData() {
document.getElementById("debugdata").innerHTML = "local: " + localId + "\nremote: " + remoteId;
}
function join() {
document.getElementById("join").disabled = true;
document.getElementById("video").disabled = true;
var channel = document.getElementById("channel").value;
var vendorKey = document.getElementById('key').value;
console.log("Init AgoraRTC client with vendor key: " + vendorKey);
client = AgoraRTC.createClient({ mode: 'interop' });
client.init(vendorKey, function () {
console.log("AgoraRTC client initialized");
client.join(null, channel, null, function (uid) {
console.log("User " + uid + " join channel successfully");
localId = uid;
debugData();
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 });
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");
});
// The user has denied access to the camera and mic.
localStream.on("accessDenied", function () {
console.log("accessDenied");
});
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");
});
}, 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) {
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) {
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);
});
});
client.on('stream-subscribed', function (evt) {
var stream = evt.stream;
console.log("Subscribe remote stream successfully: " + stream.getId());
remoteId = stream.getId();
debugData();
if ($('div#video #agora_remote' + stream.getId()).length === 0) {
$('div#video').append('<div id="agora_remote' + stream.getId() + '" style="float:left; width:810px;height:607px;display:inline-block;"></div>');
}
stream.play('agora_remote' + stream.getId());
});
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());
});
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");
}
});
}
function leave() {
document.getElementById("leave").disabled = true;
client.leave(function () {
console.log("Leavel channel successfully");
}, function (err) {
console.log("Leave channel failed");
});
}
function publish() {
document.getElementById("publish").disabled = true;
document.getElementById("unpublish").disabled = false;
client.publish(localStream, function (err) {
console.log("Publish local stream error: " + err);
});
}
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>