at least it wroks on some browsers
parent
572bab2f00
commit
ff9baa4d4c
|
|
@ -1,7 +1,9 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
|
<!--
|
||||||
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
|
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
|
||||||
|
-->
|
||||||
<script src="webrtc.js"></script>
|
<script src="webrtc.js"></script>
|
||||||
<style>
|
<style>
|
||||||
video {
|
video {
|
||||||
|
|
@ -26,5 +28,8 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
pageReady();
|
pageReady();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div id="log">
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,39 @@ class Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageReady() {
|
class View {
|
||||||
Entropy.pageReady();
|
static write(color, msg) {
|
||||||
|
document.getElementById("log").innerHTML +=
|
||||||
|
'<br><span style="color: ' + color + ';">' + msg + '</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
static info(msg) {
|
||||||
|
rconsole.info(msg);
|
||||||
|
View.write("gray", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static warn(msg) {
|
||||||
|
rconsole.warn(msg);
|
||||||
|
View.write("orange", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static log(msg) {
|
||||||
|
rconsole.log(msg);
|
||||||
|
View.write("black", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static error(msg) {
|
||||||
|
rconsole.error(msg);
|
||||||
|
View.write("red", msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Controller {
|
||||||
|
static serverConnection;
|
||||||
|
|
||||||
|
constructor(address) {
|
||||||
|
Controller.serverConnection = new WebSocket(address);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Entropy {
|
class Entropy {
|
||||||
|
|
@ -56,7 +87,6 @@ class Entropy {
|
||||||
static localStream = null;
|
static localStream = null;
|
||||||
static remoteVideo = null;
|
static remoteVideo = null;
|
||||||
static peerConnection = null;
|
static peerConnection = null;
|
||||||
static serverConnection = null;
|
|
||||||
|
|
||||||
static pageReady() {
|
static pageReady() {
|
||||||
Config.getUUID();
|
Config.getUUID();
|
||||||
|
|
@ -64,16 +94,16 @@ class Entropy {
|
||||||
Entropy.localVideo = document.getElementById('localVideo');
|
Entropy.localVideo = document.getElementById('localVideo');
|
||||||
Entropy.remoteVideo = document.getElementById('remoteVideo');
|
Entropy.remoteVideo = document.getElementById('remoteVideo');
|
||||||
|
|
||||||
Entropy.serverConnection = new WebSocket('wss://' + window.location.hostname + '/abc');
|
new Controller('wss://' + window.location.hostname + '/abc');
|
||||||
Entropy.serverConnection.onmessage = Entropy.gotMessageFromServer;
|
Controller.serverConnection.onmessage = Entropy.gotMessageFromServer;
|
||||||
|
|
||||||
var constraints = {
|
var constraints = {
|
||||||
video: true,
|
video: true,
|
||||||
audio: true,
|
audio: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
if(navigator.mediaDevices.getUserMedia) {
|
if(navigator.mediaDevices.getUserMedia) {
|
||||||
navigator.mediaDevices.getUserMedia(constraints).then(Entropy.getUserMediaSuccess).catch(Entropy.errorHandler);
|
navigator.mediaDevices.getUserMedia(constraints).then(Entropy.getUserMediaSuccess).catch(View.error);
|
||||||
} else {
|
} else {
|
||||||
alert('Your browser does not support getUserMedia API');
|
alert('Your browser does not support getUserMedia API');
|
||||||
}
|
}
|
||||||
|
|
@ -97,7 +127,7 @@ class Entropy {
|
||||||
'voiceActivityDetection': true,
|
'voiceActivityDetection': true,
|
||||||
})
|
})
|
||||||
.then(Entropy.createdDescription)
|
.then(Entropy.createdDescription)
|
||||||
.catch(Entropy.errorHandler);
|
.catch(View.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,40 +143,51 @@ class Entropy {
|
||||||
Entropy.peerConnection.setRemoteDescription(new RTCSessionDescription(signal.sdp)).then(function() {
|
Entropy.peerConnection.setRemoteDescription(new RTCSessionDescription(signal.sdp)).then(function() {
|
||||||
// Only create answers in response to offers
|
// Only create answers in response to offers
|
||||||
if(signal.sdp.type == 'offer') {
|
if(signal.sdp.type == 'offer') {
|
||||||
Entropy.peerConnection.createAnswer().then(Entropy.createdDescription).catch(Entropy.errorHandler);
|
Entropy.peerConnection.createAnswer().then(Entropy.createdDescription).catch(View.error);
|
||||||
}
|
}
|
||||||
}).catch(Entropy.errorHandler);
|
}).catch(View.error);
|
||||||
} else if(signal.ice) {
|
} else if(signal.ice) {
|
||||||
Entropy.peerConnection.addIceCandidate(new RTCIceCandidate(signal.ice)).catch(Entropy.errorHandler);
|
Entropy.peerConnection.addIceCandidate(new RTCIceCandidate(signal.ice)).catch(View.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gotIceCandidate(event) {
|
static gotIceCandidate(event) {
|
||||||
if(event.candidate != null) {
|
if(event.candidate != null) {
|
||||||
Entropy.serverConnection.send(JSON.stringify({'ice': event.candidate, 'uuid': Config.getUUID()}));
|
Controller.serverConnection.send(JSON.stringify({'ice': event.candidate, 'uuid': Config.getUUID()}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static createdDescription(description) {
|
static createdDescription(description) {
|
||||||
console.log('got description');
|
View.log('got description');
|
||||||
|
|
||||||
Entropy.peerConnection
|
Entropy.peerConnection
|
||||||
.setLocalDescription(description)
|
.setLocalDescription(description)
|
||||||
.then(function() {
|
.then(function() {
|
||||||
Entropy.serverConnection.send(JSON.stringify({
|
Controller.serverConnection.send(JSON.stringify({
|
||||||
'sdp': Entropy.peerConnection.localDescription,
|
'sdp': Entropy.peerConnection.localDescription,
|
||||||
'uuid': Config.getUUID(),
|
'uuid': Config.getUUID(),
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
.catch(errorHandler);
|
.catch(View.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gotRemoteStream(event) {
|
static gotRemoteStream(event) {
|
||||||
console.log('got remote stream');
|
View.log('got remote stream');
|
||||||
Entropy.remoteVideo.srcObject = event.streams[0];
|
Entropy.remoteVideo.srcObject = event.streams[0];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static errorHandler(error) {
|
function pageReady() {
|
||||||
console.log(error);
|
Entropy.pageReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function start(b) {
|
||||||
|
Entropy.start(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var rconsole = console;
|
||||||
|
var console = {}
|
||||||
|
for (var i in ["log", "info", "warn", "error"]) {
|
||||||
|
console[i] = View[i];
|
||||||
|
}
|
||||||
|
window.console = console;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue