return new Promise((resolve, reject) => { this.reject = reject; this.localMedia.start(this.options, (err) => { if (err) { this.logger.log(`webrtc-troubleshooter: Video Local media start failed ${err.name}`); reject(err); } else { this.logger.log('webrtc-troubleshooter: Video Local media started'); } }); this.localMedia.on('localStream', (stream) => { if (stream.getVideoTracks().length) { var videoTrack = stream.getVideoTracks()[0]; if (videoTrack) { this.logger.log('webrtc-troubleshooter: Video stream passed'); resolve(); } else { this.logger.error('webrtc-troubleshooter: Video stream failed'); reject('no video track available'); } } }); });
return new Promise((resolve, reject) => { this.reject = reject; var volumeCheckFailure = window.setTimeout(() => { this.logger.error('webrtc-troubleshooter: No change in mic volume'); reject('audio timeout'); }, this.volumeTimeout); this.localMedia.start(this.options, (err) => { if (err) { this.logger.error('webrtc-troubleshooter: Audio Local media start failed'); reject(err); } else { this.logger.log('webrtc-troubleshooter: Audio Local media started'); } }); this.localMedia.on('volumeChange', () => { window.clearTimeout(volumeCheckFailure); resolve(); }); this.localMedia.on('localStream', (stream) => { if (stream.getAudioTracks().length) { var audioTrack = stream.getAudioTracks()[0]; if (audioTrack) { this.logger.log('webrtc-troubleshooter: Audio stream passed'); } else { this.logger.error('webrtc-troubleshooter: Audio stream failed'); reject('no audio tracks available'); } } }); });
start () { super.start(); const volumeCheckFailure = window.setTimeout(() => { this.logger.error('No change in mic volume'); this.reject(new Error('audio timeout')); }, this.volumeTimeout); this.localMedia.start(this.options, (err) => { if (err) { this.logger.error('Audio Local media start failed'); this.reject(err); } else { this.logger.log('Audio Local media started'); } }); this.localMedia.on('volumeChange', (volume) => { if (volume > MIC_DETECTION_THRESHOLD) { window.clearTimeout(volumeCheckFailure); this.resolve(); } }); this.localMedia.on('localStream', (stream) => { if (stream.getAudioTracks().length) { var audioTrack = stream.getAudioTracks()[0]; if (audioTrack) { this.logger.log('Audio stream passed'); } else { this.logger.error('Audio stream failed'); this.reject(new Error('no audio tracks available')); } } }); return this.promise; }