JSFiddle - React, Tailwind, and code Playground
by ibcaliax
JavaScript
var _getUserMedia;
var _RTCPeerConnection;
var _RTCSessionDescription;
if (window.webkitRTCPeerConnection) {
_getUserMedia = navigator.webkitGetUserMedia.bind(navigator);
_RTCPeerConnection = window.webkitRTCPeerConnection;
_RTCSessionDescription = window.RTCSessionDescription;
} else if (window.mozRTCPeerConnection) {
_getUserMedia = navigator.mozGetUserMedia.bind(navigator);
_RTCPeerConnection = window.mozRTCPeerConnection;
_RTCSessionDescription = window.mozRTCSessionDescription;
}
window.addEventListener('load', function () {
console.log('DOM READY');
// 1 second after DOM is ready run a failing WebSocket.
setTimeout(function () {
var ws = new WebSocket('ws://127.0.0.1:9999/fail');
// 1 second after the WebSocket fails run setRemoteDescription().
ws.onerror = function () {
console.log('OK: WebSocket connection error');
setTimeout(function () {
var pc = new _RTCPeerConnection({iceServers: []});
// 1 second after setRemoteDescription() fails run getUserMedia().
pc.setRemoteDescription(
new _RTCSessionDescription({
type: 'offer',
sdp: 'PLEASE FAIL TO PARSE THIS'
}),
function success () {},
function failure (error) {
console.log('OK: setRemoteDescription() error:', error);
setTimeout(function () {
console.log('calling getUserMedia()');
gUM();
}, 1000);
}
);
}, 1000);
};
}, 1000);
}, false);
function gUM() {
_getUserMedia(
{audio: true, video: true},
function (stream) {
console.log('getUserMedia() success:', stream);
},
function (error) {
...