-
Notifications
You must be signed in to change notification settings - Fork 1
/
Index.js
33 lines (26 loc) · 937 Bytes
/
Index.js
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
navigator.webkitGetUserMedia({ video: true, audio: true}, function (stream) {
var Peer = require('simple-peer');
var peer = new Peer();
initiator: location.hash === '#int';
trickle: false;
stream: stream;
peer.on('signal', function (data){
document.getElementById('yourId').value = JSON.stringify(data);
});
document.getElementById('conect').addEventListener('click', function(){
var otherId = JSON.parse(document.getElementById('otherId').value);
peer.signal(otherId);
});
document.getElementById('send').addEventListener('click', function (){
var yourMessage =document.getElementById('yourMessage').value;
peer.send(yourMessage);
});
peer.on('data', function(data){
document.getElementById('messages').textContent += data + '\n';
});
peer.on('stream', function (stream){
var video = document.createElement('video');
video.src = window.URL.createObjectURL(stream);
video.play();
});
});