| 2692 | |
| 2693 | var failedMEICheck; |
| 2694 | function record(notAllowedCallback, blockRecordCallback, allowed) { |
| 2695 | if (recording) { |
| 2696 | console.log("Calling onRecord because recording"); |
| 2697 | onRecord(audioChannels, audioCtx ? Math.floor(audioCtx.sampleRate) : 0); |
| 2698 | return; |
| 2699 | } |
| 2700 | if (pendingGetUserMedia) { |
| 2701 | // If there is a pending getUser media, then |
| 2702 | // interested parties will receive the onRecord or onError |
| 2703 | // callbacks from that request. |
| 2704 | return; |
| 2705 | } |
| 2706 | |
| 2707 | |
| 2708 | failedMEICheck = false; |
| 2709 | |
| 2710 | if ((isIOS() || isSafari) && !allowed) { |
| 2711 | cn1RunPrivileged(function() { |
| 2712 | record(notAllowedCallback, blockRecordCallback, true); |
| 2713 | }); |
| 2714 | |
| 2715 | return; |
| 2716 | |
| 2717 | |
| 2718 | } |
| 2719 | |
| 2720 | |
| 2721 | paused = false; |
| 2722 | |
| 2723 | if (stream && (!isIOS() || isIPad())) { |
| 2724 | if (isIOS()) { |
| 2725 | // On iOS we cannot reuse the stream, and it is problematic |
| 2726 | // to create it new every time, so we workaround it by cloning |
| 2727 | // the stream and removing the tracks from the old stream. |
| 2728 | // Thanks Chad Phillips (https://webrtchacks.com/guide-to-safari-webrtc/) |
| 2729 | var tmp = stream.clone(); |
| 2730 | var audioTracks = stream.getAudioTracks(); |
| 2731 | for (var i=0, len = audioTracks.length; i < len; i++) { |
| 2732 | stream.removeTrack(audioTracks[i]); |
| 2733 | } |
| 2734 | stream = tmp; |
| 2735 | } |
| 2736 | resume(notAllowedCallback, blockRecordCallback); |
| 2737 | return; |
| 2738 | } |
| 2739 | |
| 2740 | if (stream) { |
| 2741 | stream.getTracks().forEach(function(track) { |
| 2742 | console.log("Disabling track", track); |
| 2743 | track.stop(); |
| 2744 | }); |
| 2745 | if (stream.stop) { |
| 2746 | stream.stop(); |
| 2747 | } |
| 2748 | if (stream.close) { |
| 2749 | stream.close(); |
| 2750 | } |
| 2751 | stream = null; |