-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
196 lines (174 loc) · 6.66 KB
/
index.html
File metadata and controls
196 lines (174 loc) · 6.66 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
<!DOCTYPE html>
<html>
<head>
<title>Agora Web Sample</title>
<link rel="stylesheet" href="vendor/bootstrap.min.css">
<script src="AgoraRTCSDK-1.14.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="div_join" class="panel panel-default">
<div class="panel-body">
Key: <input id="key" type="text" value="" size="36"></input>
Channel: <input id="channel" type="text" value="1000" size="4"></input>
Host: <input id="video" type="checkbox" checked></input>
<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">
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 vendor key: " + key.value);
client = AgoraRTC.createClient({mode: 'interop'});
client.init(key.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');
}
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());
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>