<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">function $t(category, key, fallback = '') {
  if (typeof Yii != 'undefined') {
    return Yii.t(category, key);
  }
  return fallback ? fallback : key;
}

window.audioComments = {
	recordAudio: '',
	recordStatus: '',
	mediaStream: '',

	isMimeTypeSupported(mimeType) {

		return true;

		if (typeof MediaRecorder.isTypeSupported !== 'function') {
			return true;
		}
		if ( mimeType == 'audio/webm' &amp;&amp; window.testDisableWebm ) {
			return false;
		}

		return MediaRecorder.isTypeSupported(mimeType);
	},

	record: function (x) {
		var self = $(x);

		if (!self.parent().children('div.audio-upload').length) {
			$('&lt;div class="audio-upload"&gt;&lt;/div&gt;').appendTo(self.parent());
		}

		var inputUpload = self.parent().children('div.audio-upload');
		var audioStatus = self.children('span.audio-status');
		var microphone = self.children('i.fa-microphone');

		if (
			!window.audioComments.recordStatus
			|| window.audioComments.recordStatus == 'stop'
		) {
			window.audioComments.recordStatus = 'allow';

			var buttons = $(
				[
					'&lt;div class="audio-tip"&gt;',
					'&lt;div class="tooltip-inner"&gt;',
					'&lt;div class="audio-record"&gt;&lt;span class="glyphicon glyphicon-record" aria-hidden="true"&gt;&lt;/span&gt; ' + $t('common', 'запись') + '&lt;/div&gt;',
					'&lt;div class="audio-cancel"&gt;&lt;span class="glyphicon glyphicon-trash" aria-hidden="true"&gt;&lt;/span&gt; ' + $t('common', 'отменить') + '&lt;/div&gt;',
					'&lt;div class="audio-save"&gt;&lt;span class="glyphicon glyphicon-stop" aria-hidden="true"&gt;&lt;/span&gt; ' + $t('common', 'стоп') + '&lt;/div&gt; ',
					'&lt;/div&gt;&lt;/div&gt;'
				].join(' ')).appendTo(self.next()).hide();

			audioStatus.show().html($t('common', 'разрешите доступ к микрофону...'));
		}

		if (window.audioComments.recordStatus == 'allow') {
			window.audioComments.recordStatus = 'check';

			var recorderType = StereoAudioRecorder;
			var mimeType = "audio/wav";


			if ( this.isMimeTypeSupported("audio/webm") ) {
				recorderType = MediaStreamRecorder;
				mimeType = "audio/webm";
			}

			var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
			if(isSafari){
				recorderType = StereoAudioRecorder;
				mimeType = "audio/wav";
			}

			window.navigator.mediaDevices.getUserMedia({audio: true})
				.then(function(localMediaStream) {

					window.audioComments.recordAudio = RecordRTC(localMediaStream, {
						type: 'audio',
						mimeType: mimeType,
						recorderType: recorderType,
						disableLogs: false
					});

					window.audioComments.mediaStream = localMediaStream;
					audioStatus.hide();
					buttons.show();
					window.audioComments.recordStatus = 'start';
				})
				.catch(function(err) {
					/* handle the error */
					audioStatus.show().html($t('common', 'доступ к микрофону запрещен!'));
				});

			/*
			window.navigator.mediaDevices.getUserMedia({audio: true}, function (localMediaStream) {
				window.audioComments.recordAudio = RecordRTC(localMediaStream, {
					type: 'audio',
					mimeType: mimeType,
					recorderType: recorderType,
					disableLogs: false
				});

				window.audioComments.mediaStream = localMediaStream;
				audioStatus.hide();
				buttons.show();
				window.audioComments.recordStatus = 'start';

			}, function (e) {
				audioStatus.show().html('доступ к микрофону запрещен!');
			});
			*/
		}

		$('.audio-cancel', buttons).click(function () {
			if (window.audioComments.recordStatus == 'allow') {
				return;
			}
			microphone.css('color', '#999');
			if (window.audioComments.mediaStream) {
				window.audioComments.mediaStream.getAudioTracks()[0].stop();
			}
			audioStatus.html('');
			buttons.remove();
			window.audioComments.recordStatus = 'stop';
		});

		$('.audio-record', buttons).click(function() {
			if (window.audioComments.recordStatus == 'start') {
				window.audioComments.startRecord(audioStatus, microphone);
			}

		});

		//	var extension = this.isMimeTypeSupported("audio/webm") ? "webm" : "wav";
		var extension = isSafari ? "wav": "webm" ;

		$('.audio-save', buttons).click(function () {

			if (window.audioComments.recordStatus == 'recording') {
				buttons.remove();
				window.audioComments.recordStatus = 'stop';

				window.audioComments.recordAudio.stopRecording(function () {

					microphone.css('color', '#999');
					audioStatus.html($t('common', 'сохранение...'));

					window.audioComments.mediaStream.getAudioTracks()[0].stop();


					var now = new Date();
					var fileName = now.getFullYear() + '' + now.getMonth() + '' + now.getDate() + '' + now.getHours() + '' + now.getMinutes() + '' + now.getSeconds();
					fileName += '_';
					fileName += Math.round(Math.random() * 9999) + '.' + extension;

					var formData = new FormData();
					var audioBlob = window.audioComments.recordAudio.getBlob();
					formData.append('Filedata', audioBlob);
					formData.append('BlobfileName', fileName);

					var uploadFormToUrl = function (url, formData) {
						$.ajax({
							url: url,
							type: 'POST',
							data: formData,
							processData: false,
							contentType: false,
							success: function (data) {
								if (data == 'Error') {
									alert($t('common', 'Невозможно сохранить файл!'));
								} else {

									var info = $('&lt;span class="audio-info"&gt;'
										+ '&lt;span class="close-info" style="float:right;"&gt;x&lt;/span&gt;'
										+ '&lt;div&gt;'
										+ '&lt;audio controls=""&gt;&lt;source src="' + data.download_url + '" type="audio/mpeg"&gt;&lt;/audio&gt;'
										+ '&lt;br&gt;' + fileName
										+ '&lt;/div&gt;'
										+ '&lt;/span&gt;'
									);
									$('.close-info', info).click(function () {
										info.remove();
									});

									var input = $('&lt;input type="hidden" class="audio-value" name="GetCourseComment[audioFiles][]"&gt;');
									input.val(data.hash);
									input.appendTo(info);
									info.appendTo(inputUpload);
									audioStatus.html('');
									self.parent().children('.comment-form-wrapper .new-comment .btn-send').show();
									self.next().next().children('.save-button').removeClass('disabled');
								}
							},
							error: function (error) {
								buttons.show();
								audioStatus.html($t('common', 'ошибка сохранения') +': ' + error.statusText);
							}
						});
					};

					if (window.fileserviceUploadHost) {
						formData.append('fullAnswer', true);
						var secureDirectUploadUri = '/fileservice/widget/secure-direct-upload';
						try {
							var session = localStorage.getItem('session');
							var requestParams = {"fs_ref": window.location.href};

							if (session !== undefined &amp;&amp; session != null){
								var objSession = jQuery.parseJSON(session);

								if (objSession.hasOwnProperty('user_id') &amp;&amp; objSession.user_id != null) {
									requestParams.fs_u = objSession.user_id;
								} else {
									requestParams.fs_u = -1;
								}
							}

							secureDirectUploadUri += '?' + jQuery.param(requestParams);
						} catch (err) {
						}

						$.ajax({
							url: '/fileservice/widget/create-secret-link',
							method: 'GET',
							data: {
								host: window.fileserviceUploadHost,
								uri: secureDirectUploadUri,
								expires: 600
							},
							success: function (data) {
								if (data.link) {
									uploadFormToUrl(data.link, formData);
								} else {
									buttons.show();
									audioStatus.html($t('common', 'ошибка сохранения'));
								}
							},
							error: function (error) {
								buttons.show();
								audioStatus.html($t('common', 'ошибка сохранения') +': ' + error.statusText);
								try{sendCreateLinkError(http, message, exc);}catch (e) {}
							},
							async: false
						});
					} else {
						uploadFormToUrl(
							'/fileservice/widget/upload?deprecated=9'
								+ '&amp;secure=' + window.isEnabledSecureUpload
								+ '&amp;host=' + window.fileserviceUploadHost,
							formData
						);
					}

				});
			}

		});
	},

	startRecord: function(audioStatus, microphone) {
		window.audioComments.recordAudio.startRecording();

		window.audioComments.recordStatus = 'recording';

		audioStatus.show().html($t('common', 'идет запись...'));
		microphone.css('color', 'red');
		$('.audio-record').css('color', 'red');
	},

	init: function() {
		$('.audio-comment').on('click', function() {
			return window.audioComments.record(this);
		});
	}
};

$(function() {
	window.audioComments.init();

	$( document ).ready(function() {
		try {
			window.AudioContext = window.AudioContext || window.webkitAudioContext;
			window.navigator.getUserMedia = window.navigator.getUserMedia || window.navigator.webkitGetUserMedia || window.navigator.mediaDevices.getUserMedia;
			window.URL = window.URL || window.webkitURL;



			if (window.AudioContext &amp;&amp; window.navigator.getUserMedia &amp;&amp; window.URL) {
				$('.audio-comment').show();
			}

		} catch (e) {
			$('.audio-comment').hide();
		}
	});

});
</pre></body></html>