* @param {Blob} file - File or Blob object. This parameter is required. * @param {string} fileName - Optional file name e.g. "Recorded-Video.webm" * @example * invokeSaveAsDialog(blob or file, [optional] fileName); * @see https://github.com/muaz-khan/RecordRTC|RecordRTC Source Code
(file, fileName)
| 929 | * @see {@link https://github.com/muaz-khan/RecordRTC|RecordRTC Source Code} |
| 930 | */ |
| 931 | function invokeSaveAsDialog(file, fileName) { |
| 932 | if (!file) { |
| 933 | throw 'Blob object is required.'; |
| 934 | } |
| 935 | |
| 936 | if (!file.type) { |
| 937 | try { |
| 938 | file.type = 'video/webm'; |
| 939 | } catch (e) {} |
| 940 | } |
| 941 | |
| 942 | var fileExtension = (file.type || 'video/webm').split('/')[1]; |
| 943 | |
| 944 | if (fileName && fileName.indexOf('.') !== -1) { |
| 945 | var splitted = fileName.split('.'); |
| 946 | fileName = splitted[0]; |
| 947 | fileExtension = splitted[1]; |
| 948 | } |
| 949 | |
| 950 | var fileFullName = (fileName || (Math.round(Math.random() * 9999999999) + 888888888)) + '.' + fileExtension; |
| 951 | |
| 952 | if (typeof navigator.msSaveOrOpenBlob !== 'undefined') { |
| 953 | return navigator.msSaveOrOpenBlob(file, fileFullName); |
| 954 | } else if (typeof navigator.msSaveBlob !== 'undefined') { |
| 955 | return navigator.msSaveBlob(file, fileFullName); |
| 956 | } |
| 957 | |
| 958 | var hyperlink = document.createElement('a'); |
| 959 | hyperlink.href = URL.createObjectURL(file); |
| 960 | hyperlink.target = '_blank'; |
| 961 | hyperlink.download = fileFullName; |
| 962 | |
| 963 | if (!!navigator.mozGetUserMedia) { |
| 964 | hyperlink.onclick = function() { |
| 965 | (document.body || document.documentElement).removeChild(hyperlink); |
| 966 | }; |
| 967 | (document.body || document.documentElement).appendChild(hyperlink); |
| 968 | } |
| 969 | |
| 970 | var evt = new MouseEvent('click', { |
| 971 | view: window, |
| 972 | bubbles: true, |
| 973 | cancelable: true |
| 974 | }); |
| 975 | |
| 976 | hyperlink.dispatchEvent(evt); |
| 977 | |
| 978 | if (!navigator.mozGetUserMedia) { |
| 979 | URL.revokeObjectURL(hyperlink.href); |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | function bytesToSize(bytes) { |
| 984 | var k = 1000; |
no outgoing calls
no test coverage detected