Remove spaghetti.

pull/25/head
Pontus Persson 2017-12-08 16:46:04 +01:00 committed by Pontus Alexander
parent 36408ab97b
commit c2357b879a
1 changed files with 17 additions and 13 deletions

View File

@ -19,16 +19,7 @@ function pageReady() {
serverConnection = createPeerExchange('wss://' + window.location.hostname + ':8443'); serverConnection = createPeerExchange('wss://' + window.location.hostname + ':8443');
serverConnection.listen(gotMessageFromServer); serverConnection.listen(gotMessageFromServer);
var constraints = { setup();
video: true,
audio: true,
};
if(navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia(constraints).then(getUserMediaSuccess).catch(errorHandler);
} else {
alert('Your browser does not support getUserMedia API');
}
} }
function getUserMediaSuccess(stream) { function getUserMediaSuccess(stream) {
@ -41,7 +32,22 @@ function setup() {
peerConnection.addEventListener('icecandidate', gotIceCandidate); peerConnection.addEventListener('icecandidate', gotIceCandidate);
peerConnection.addEventListener('addstream', gotRemoteStream); peerConnection.addEventListener('addstream', gotRemoteStream);
peerConnection.addStream(localStream);
if(navigator.mediaDevices.getUserMedia) {
var constraints = {
video: true,
audio: true,
};
navigator.mediaDevices.getUserMedia(constraints)
.then(getUserMediaSuccess)
.then(() => {
peerConnection.addStream(localStream);
})
.catch(errorHandler);
} else {
alert('Your browser does not support getUserMedia API');
}
peerConnection.addEventListener('datachannel', function(dataChannel) { peerConnection.addEventListener('datachannel', function(dataChannel) {
dataChannel.channel.send('Hello there, I got your signal'); dataChannel.channel.send('Hello there, I got your signal');
@ -66,8 +72,6 @@ function setup() {
} }
function start(isCaller) { function start(isCaller) {
setup();
if(isCaller) { if(isCaller) {
peerConnection.createOffer().then(createdDescription).catch(errorHandler); peerConnection.createOffer().then(createdDescription).catch(errorHandler);
} }