forked from paul-em/tiny-webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.html
64 lines (54 loc) · 1.56 KB
/
sample.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
<!DOCTYPE html>
<html>
<head>
<title>Sample WebRTC Conference</title>
<meta charset="utf-8">
<style>
#me {
transform: scaleX(-1);
-webkit-transform: scaleX(-1);
}
</style>
</head>
<body>
<div>Room: <span id="room">connecting...</span></div>
<video id="me" autoplay="autoplay"></video>
<script src="lib/tiny-webrtc.js"></script>
<script>
var webRTC = new WebRTC();
webRTC.onCameraAccess(function (stream) {
document.getElementById("me").src = stream;
console.log("camera access");
});
webRTC.onRoomJoin(function (room) {
document.getElementById("room").innerHTML = room;
console.log("joined room")
});
webRTC.onConnect(function (userId) {
console.log("ready my userId",userId);
});
webRTC.onError(function (id, msg) {
console.error(msg);
});
webRTC.onUserConnect(function (userId) {
console.log("userConnect", userId);
var video = document.createElement('video');
video.src = webRTC.getRemoteStream(userId);
video.autoplay = "autoplay";
video.id = "remote-" + userId;
document.body.appendChild(video);
webRTC.sendData(userId, 'Hello!')
});
webRTC.onUserLeave(function (userId) {
console.log("userLeave", userId);
var el = document.getElementById("remote-" + userId);
if (el) {
el.parentElement.removeChild(el);
}
});
webRTC.onData(function (userId, data) {
console.log("data", userId, data);
})
</script>
</body>
</html>