-
Notifications
You must be signed in to change notification settings - Fork 0
/
receiver.html
88 lines (85 loc) · 3.11 KB
/
receiver.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>simple-peer</title>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/simplepeer.min.js"></script>
<script src="crafy-simple-peer.js"></script>
<style>
textarea {
display:block;
width:80%;
}
video {
display:block;
width:80%;
height:300px;
}
</style>
</head>
<body>
<h1>RECEIVER</h1>
<div>
<textarea id="receiveDataTextarea" placeholder="Signal from other peer"></textarea>
<button type="button" id="receiveDataButton">LOAD</button>
</div>
<p>Signals for the others peer:</p>
<div id="signals_textareas"></div>
<div id="videos_section"></div>
<div>
<button type="button" id="muteAudioButton">Toggle mute my audio</button>
<button type="button" id="muteVideoButton">Toggle mute my video</button>
</div>
<div id="messages_section"></div>
<div>
<textarea id="sendMessageInput" placeholder="write a message"></textarea>
<button type="button" id="sendMessageButton">SEND</button>
</div>
<script>
var im_sender = false;
var signals_textareas = document.getElementById('signals_textareas');
var videos_section = document.getElementById('videos_section');
var messages_section = document.getElementById('messages_section');
var receiveDataTextarea = document.getElementById('receiveDataTextarea');
var receiveDataButton = document.getElementById('receiveDataButton');
var sendMessageInput = document.getElementById('sendMessageInput');
var sendMessageButton = document.getElementById('sendMessageButton');
var muteAudioButton = document.getElementById('muteAudioButton');
var muteVideoButton = document.getElementById('muteVideoButton');
var peer_id;
var CrafySimplePeerInstance = new CrafySimplePeer();
CrafySimplePeerInstance.init().then(function () {
peer_id = CrafySimplePeerInstance.createPeer(im_sender);
});
CrafySimplePeerInstance.onPeerStream = function (stream, peer_id) {
var video = document.createElement('video');
videos_section.appendChild(video);
if ('srcObject' in video) {
video.srcObject = stream;
} else {
video.src = window.URL.createObjectURL(stream); // for older browsers
}
video.play();
};
CrafySimplePeerInstance.onPeerMessage = function (message, peer_id) {
messages_section.innerHTML += '<p>' + message + '</p>';
}
CrafySimplePeerInstance.onMustSignalingPeer = function (info, peer_id) {
signals_textareas.innerHTML += '<textarea>'+info+'</textarea>';
}
receiveDataButton.onclick = function () {
CrafySimplePeerInstance.receiveData(receiveDataTextarea.value, peer_id);
};
sendMessageButton.onclick = function () {
CrafySimplePeerInstance.sendMessage(sendMessageInput.value, peer_id);
};
muteAudioButton.onclick = function () {
CrafySimplePeerInstance.toggleCurrMuteAudio();
};
muteVideoButton.onclick = function () {
CrafySimplePeerInstance.toggleCurrMuteVideo();
};
</script>
</body>
</html>