Store in session if can generate ice candidates, change timeout to 5secs, display error msgs
This commit is contained in:
parent
a875b0b386
commit
c21bb693b4
@ -101,13 +101,6 @@ const MAX_CAMERA_SHARE_FAILED_WAIT_TIME = 60000;
|
||||
const PING_INTERVAL = 15000;
|
||||
|
||||
class VideoProvider extends Component {
|
||||
static checkIceConnectivity() {
|
||||
// Webkit ICE restrictions demand a capture device permission to release
|
||||
// host candidates
|
||||
if (browser().name === 'safari') {
|
||||
tryGenerateIceCandidates();
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
@ -147,6 +140,7 @@ class VideoProvider extends Component {
|
||||
}
|
||||
|
||||
|
||||
|
||||
componentWillMount() {
|
||||
this.ws.onopen = this.onWsOpen;
|
||||
this.ws.onclose = this.onWsClose;
|
||||
@ -156,7 +150,7 @@ class VideoProvider extends Component {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
VideoProvider.checkIceConnectivity();
|
||||
this.checkIceConnectivity();
|
||||
document.addEventListener('joinVideo', this.shareWebcam); // TODO find a better way to do this
|
||||
document.addEventListener('exitVideo', this.unshareWebcam);
|
||||
this.ws.onmessage = this.onWsMessage;
|
||||
@ -284,6 +278,17 @@ class VideoProvider extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
checkIceConnectivity() {
|
||||
// Webkit ICE restrictions demand a capture device permission to release
|
||||
// host candidates
|
||||
if (browser().name === 'safari') {
|
||||
const { intl } = this.props;
|
||||
tryGenerateIceCandidates().catch((e) => {
|
||||
this.notifyError(intl.formatMessage(intlSFUErrors[2021]));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
logger(type, message, options = {}) {
|
||||
const { userId, userName } = this.props;
|
||||
const topic = options.topic || 'video';
|
||||
|
@ -150,7 +150,11 @@ class AudioManager {
|
||||
// Webkit ICE restrictions demand a capture device permission to release
|
||||
// host candidates
|
||||
if (name === 'safari') {
|
||||
await tryGenerateIceCandidates();
|
||||
try {
|
||||
await tryGenerateIceCandidates();
|
||||
} catch (e) {
|
||||
this.notify(this.messages.error.ICE_NEGOTIATION_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
// Call polyfills for webrtc client if navigator is "iOS Webview"
|
||||
|
@ -1,65 +1,89 @@
|
||||
const iceServersList = [
|
||||
{urls:"stun:stun.l.google.com:19302"},
|
||||
{urls:"stun:stun1.l.google.com:19302"},
|
||||
{urls:"stun:stun2.l.google.com:19302"},
|
||||
{urls:"stun:stun3.l.google.com:19302"},
|
||||
{urls:"stun:stun4.l.google.com:19302"},
|
||||
{urls:"stun:stun.ekiga.net"},
|
||||
{urls:"stun:stun.ideasip.com"},
|
||||
{urls:"stun:stun.schlund.de"},
|
||||
{urls:"stun:stun.stunprotocol.org:3478"},
|
||||
{urls:"stun:stun.voiparound.com"},
|
||||
{urls:"stun:stun.voipbuster.com"},
|
||||
{urls:"stun:stun.voipstunt.com"},
|
||||
{urls:"stun:stun.voxgratia.org"},
|
||||
{urls:"stun:stun.services.mozilla.com"}
|
||||
];
|
||||
import { fetchWebRTCMappedStunTurnServers } from '/imports/utils/fetchStunTurnServers';
|
||||
import Auth from '/imports/ui/services/auth';
|
||||
import { Session } from 'meteor/session';
|
||||
|
||||
const defaultIceServersList = [
|
||||
{ urls: 'stun:stun.l.google.com:19302' },
|
||||
{ urls: 'stun:stun1.l.google.com:19302' },
|
||||
{ urls: 'stun:stun2.l.google.com:19302' },
|
||||
{ urls: 'stun:stun3.l.google.com:19302' },
|
||||
{ urls: 'stun:stun4.l.google.com:19302' },
|
||||
{ urls: 'stun:stun.ekiga.net' },
|
||||
{ urls: 'stun:stun.ideasip.com' },
|
||||
{ urls: 'stun:stun.schlund.de' },
|
||||
{ urls: 'stun:stun.stunprotocol.org:3478' },
|
||||
{ urls: 'stun:stun.voiparound.com' },
|
||||
{ urls: 'stun:stun.voipbuster.com' },
|
||||
{ urls: 'stun:stun.voipstunt.com' },
|
||||
{ urls: 'stun:stun.voxgratia.org' },
|
||||
{ urls: 'stun:stun.services.mozilla.com' },
|
||||
];
|
||||
|
||||
const getSessionToken = () => Auth.sessionToken;
|
||||
|
||||
export async function getIceServersList() {
|
||||
try {
|
||||
const iceServers = await fetchWebRTCMappedStunTurnServers(getSessionToken());
|
||||
|
||||
return iceServers || defaultIceServersList;
|
||||
} catch (error) {
|
||||
return defaultIceServersList;
|
||||
}
|
||||
}
|
||||
|
||||
export function canGenerateIceCandidates() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (Session.get('canGenerateIceCandidates')) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
pc = new RTCPeerConnection({iceServers: iceServersList});
|
||||
countIceCandidates = 0;
|
||||
getIceServersList().catch((e) => {
|
||||
reject();
|
||||
}).then((iceServersReceived) => {
|
||||
const pc = new RTCPeerConnection({ iceServers: iceServersReceived });
|
||||
let countIceCandidates = 0;
|
||||
|
||||
try{ pc.addTransceiver('audio'); } catch (e) {}
|
||||
try { pc.addTransceiver('audio'); } catch (e) { }
|
||||
|
||||
pc.onicecandidate = function (e) {
|
||||
if(countIceCandidates) return;
|
||||
if (e.candidate) {
|
||||
countIceCandidates++;
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
pc.onicecandidate = function (e) {
|
||||
if (countIceCandidates) return;
|
||||
if (e.candidate) {
|
||||
countIceCandidates++;
|
||||
Session.set('canGenerateIceCandidates', true);
|
||||
resolve();
|
||||
}
|
||||
}
|
||||
|
||||
pc.onicegatheringstatechange = function(e) {
|
||||
if(e.currentTarget.iceGatheringState == 'complete' && countIceCandidates == 0) reject();
|
||||
}
|
||||
pc.onicegatheringstatechange = function (e) {
|
||||
if (e.currentTarget.iceGatheringState == 'complete' && countIceCandidates == 0) reject();
|
||||
}
|
||||
|
||||
setTimeout(function(){
|
||||
pc.close();
|
||||
if(!countIceCandidates) reject();
|
||||
}, 3000);
|
||||
setTimeout(function () {
|
||||
pc.close();
|
||||
if (!countIceCandidates) reject();
|
||||
}, 5000);
|
||||
|
||||
p = pc.createOffer({offerToReceiveVideo: true});
|
||||
p.then( answer => {pc.setLocalDescription(answer) ; } )
|
||||
});
|
||||
};
|
||||
const p = pc.createOffer({ offerToReceiveVideo: true });
|
||||
p.then((answer) => { pc.setLocalDescription(answer); });
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function tryGenerateIceCandidates() {
|
||||
return new Promise((resolve, reject) => {
|
||||
canGenerateIceCandidates().then(ok => {
|
||||
resolve();
|
||||
}).catch(e => {
|
||||
navigator.mediaDevices.getUserMedia({audio: true, video: false}).then(function (stream) {
|
||||
canGenerateIceCandidates().then(ok => {
|
||||
resolve();
|
||||
}).catch(e => {
|
||||
reject();
|
||||
});
|
||||
}).catch(e => {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
return new Promise((resolve, reject) => {
|
||||
canGenerateIceCandidates().then((ok) => {
|
||||
resolve();
|
||||
}).catch((e) => {
|
||||
navigator.mediaDevices.getUserMedia({ audio: true, video: false }).then(function (stream) {
|
||||
canGenerateIceCandidates().then((ok) => {
|
||||
resolve();
|
||||
}).catch((e) => {
|
||||
reject();
|
||||
});
|
||||
}).catch((e) => {
|
||||
reject();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user