sceyt-chat-react-uikit 1.8.8-beta.7 → 1.8.8-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +1009 -487
  2. package/index.modern.js +991 -488
  3. package/package.json +1 -1
package/index.modern.js CHANGED
@@ -12,7 +12,7 @@ import { createPortal } from 'react-dom';
12
12
  import Cropper from 'react-easy-crop';
13
13
  import { CircularProgressbar } from 'react-circular-progressbar';
14
14
  import { FFmpeg } from '@ffmpeg/ffmpeg';
15
- import { fetchFile, toBlobURL } from '@ffmpeg/util';
15
+ import { toBlobURL, fetchFile } from '@ffmpeg/util';
16
16
  import { $applyNodeReplacement, TextNode, $createTextNode, $getSelection, $isRangeSelection, $isTextNode, FORMAT_TEXT_COMMAND, SELECTION_CHANGE_COMMAND, COMMAND_PRIORITY_LOW, $getRoot, $createParagraphNode, KEY_BACKSPACE_COMMAND, KEY_DELETE_COMMAND, PASTE_COMMAND, COMMAND_PRIORITY_NORMAL } from 'lexical';
17
17
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
18
18
  import { LexicalComposer } from '@lexical/react/LexicalComposer';
@@ -14848,198 +14848,677 @@ function calculateSize(width, height, maxWidth, maxHeight) {
14848
14848
  }
14849
14849
  var pica = new Pica();
14850
14850
 
14851
- var getVideoFirstFrame = function getVideoFirstFrame(videoSrc, maxWidth, maxHeight, quality) {
14852
- if (quality === void 0) {
14853
- quality = 0.8;
14851
+ var dbg = function dbg() {
14852
+ var _console;
14853
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14854
+ args[_key] = arguments[_key];
14855
+ }
14856
+ return (_console = console).log.apply(_console, ['[VIDEO_FIRST_FRAME]'].concat(args));
14857
+ };
14858
+ var toHex = function toHex(bytes) {
14859
+ return Array.from(bytes).map(function (b) {
14860
+ return b.toString(16).padStart(2, '0');
14861
+ }).join(' ');
14862
+ };
14863
+ var NATIVE_VIDEO_TYPES = new Set(['video/mp4', 'video/webm', 'video/ogg']);
14864
+ var findFourccs = function findFourccs(bytes, fourccs) {
14865
+ var found = [];
14866
+ for (var _iterator = _createForOfIteratorHelperLoose(fourccs), _step; !(_step = _iterator()).done;) {
14867
+ var cc = _step.value;
14868
+ var c0 = cc.charCodeAt(0);
14869
+ var c1 = cc.charCodeAt(1);
14870
+ var c2 = cc.charCodeAt(2);
14871
+ var c3 = cc.charCodeAt(3);
14872
+ for (var i = 0; i <= bytes.length - 4; i++) {
14873
+ if (bytes[i] === c0 && bytes[i + 1] === c1 && bytes[i + 2] === c2 && bytes[i + 3] === c3) {
14874
+ found.push(cc);
14875
+ break;
14876
+ }
14877
+ }
14854
14878
  }
14879
+ return found;
14880
+ };
14881
+ var VIDEO_CODEC_FOURCCS = ['avc1', 'avc3', 'hvc1', 'hev1', 'av01', 'vp09', 'mp4v', 'apcn', 'apch', 'ap4h'];
14882
+ var isQuickTimeContainer = function isQuickTimeContainer(info) {
14883
+ return info.isoBrand === 'qt ';
14884
+ };
14885
+ var inspectVideoBlob = function inspectVideoBlob(blob) {
14855
14886
  try {
14856
- return Promise.resolve(new Promise(function (resolve) {
14857
- try {
14858
- var video = document.createElement('video');
14859
- video.preload = 'metadata';
14860
- video.muted = true;
14861
- video.setAttribute('playsinline', 'true');
14862
- if (videoSrc instanceof Blob) {
14863
- video.src = URL.createObjectURL(videoSrc);
14864
- } else {
14865
- video.src = videoSrc;
14866
- }
14867
- var videoUrlCreated = false;
14868
- var cleanup = function cleanup() {
14869
- if (videoUrlCreated && videoSrc instanceof Blob) {
14870
- URL.revokeObjectURL(video.src);
14887
+ var info = {
14888
+ mimeType: null,
14889
+ isoBrand: null,
14890
+ codecs: []
14891
+ };
14892
+ return Promise.resolve(_catch(function () {
14893
+ return Promise.resolve(blob.slice(0, 16).arrayBuffer()).then(function (_blob$slice$arrayBuff) {
14894
+ var _exit = false;
14895
+ function _temp4(_result) {
14896
+ if (_exit) return _result;
14897
+ if (head.length >= 4 && head[0] === 0x1a && head[1] === 0x45 && head[2] === 0xdf && head[3] === 0xa3) {
14898
+ dbg('sniff: EBML (webm/mkv) detected');
14899
+ info.mimeType = 'video/webm';
14900
+ return info;
14871
14901
  }
14872
- };
14873
- var extractFrame = function extractFrame() {
14874
- try {
14875
- if (video.videoWidth === 0 || video.videoHeight === 0) {
14876
- cleanup();
14877
- resolve(null);
14878
- return;
14879
- }
14880
- var canvasWidth = maxWidth || video.videoWidth / 2;
14881
- var canvasHeight = maxHeight || video.videoHeight / 2;
14882
- var canvas = document.createElement('canvas');
14883
- canvas.width = canvasWidth;
14884
- canvas.height = canvasHeight;
14885
- var ctx = canvas.getContext('2d');
14886
- if (!ctx) {
14887
- cleanup();
14888
- resolve(null);
14889
- return;
14890
- }
14891
- ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
14892
- canvas.toBlob(function (blob) {
14893
- if (!blob) {
14894
- cleanup();
14895
- resolve(null);
14896
- return;
14902
+ if (head.length >= 4 && head[0] === 0x4f && head[1] === 0x67 && head[2] === 0x67 && head[3] === 0x53) {
14903
+ dbg('sniff: Ogg detected');
14904
+ info.mimeType = 'video/ogg';
14905
+ return info;
14906
+ }
14907
+ dbg('sniff: unknown container');
14908
+ return info;
14909
+ }
14910
+ var head = new Uint8Array(_blob$slice$arrayBuff);
14911
+ dbg('sniff: first bytes =', toHex(head));
14912
+ var _temp3 = function () {
14913
+ if (head.length >= 8 && head[4] === 0x66 && head[5] === 0x74 && head[6] === 0x79 && head[7] === 0x70) {
14914
+ info.mimeType = 'video/mp4';
14915
+ info.isoBrand = String.fromCharCode(head[8] || 0, head[9] || 0, head[10] || 0, head[11] || 0);
14916
+ var scanSize = 512 * 1024;
14917
+ return Promise.resolve(blob.slice(0, Math.min(scanSize, blob.size)).arrayBuffer()).then(function (_blob$slice$arrayBuff2) {
14918
+ function _temp2() {
14919
+ dbg('sniff: ISO-BMFF, major brand =', JSON.stringify(info.isoBrand), 'codecs =', info.codecs.join(',') || 'none-found');
14920
+ _exit = true;
14921
+ return info;
14897
14922
  }
14898
- var frameBlobUrl = URL.createObjectURL(blob);
14899
- cleanup();
14900
- resolve({
14901
- frameBlobUrl: frameBlobUrl,
14902
- blob: blob
14903
- });
14904
- }, 'image/jpeg', quality);
14905
- } catch (error) {
14906
- log.error('Error extracting video frame:', error);
14907
- cleanup();
14908
- resolve(null);
14923
+ var headChunk = new Uint8Array(_blob$slice$arrayBuff2);
14924
+ info.codecs = findFourccs(headChunk, VIDEO_CODEC_FOURCCS);
14925
+ var _temp = function () {
14926
+ if (!info.codecs.length && blob.size > scanSize) {
14927
+ return Promise.resolve(blob.slice(Math.max(0, blob.size - scanSize)).arrayBuffer()).then(function (_blob$slice$arrayBuff3) {
14928
+ var tailChunk = new Uint8Array(_blob$slice$arrayBuff3);
14929
+ info.codecs = findFourccs(tailChunk, VIDEO_CODEC_FOURCCS);
14930
+ });
14931
+ }
14932
+ }();
14933
+ return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
14934
+ });
14909
14935
  }
14910
- };
14911
- video.onloadedmetadata = function () {
14912
- videoUrlCreated = true;
14913
- video.currentTime = 0.01;
14914
- video.onseeked = function () {
14915
- video.onseeked = null;
14916
- var capture = function capture() {
14917
- return requestAnimationFrame(extractFrame);
14918
- };
14919
- video.play().then(function () {
14920
- var done = false;
14921
- var _finish = function finish() {
14922
- if (done) return;
14923
- done = true;
14924
- video.removeEventListener('timeupdate', _finish);
14925
- video.removeEventListener('ended', _finish);
14926
- video.pause();
14927
- capture();
14928
- };
14929
- video.addEventListener('timeupdate', _finish);
14930
- video.addEventListener('ended', _finish);
14931
- setTimeout(_finish, 500);
14932
- })["catch"](capture);
14933
- };
14934
- video.onerror = function (error) {
14935
- log.error('Error seeking video for frame extraction', error);
14936
- cleanup();
14937
- resolve(null);
14936
+ }();
14937
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
14938
+ });
14939
+ }, function (error) {
14940
+ log.error('Failed to sniff video container:', error);
14941
+ return info;
14942
+ }));
14943
+ } catch (e) {
14944
+ return Promise.reject(e);
14945
+ }
14946
+ };
14947
+ var isFirefox = function isFirefox() {
14948
+ return typeof navigator !== 'undefined' && /firefox/i.test(navigator.userAgent);
14949
+ };
14950
+
14951
+ var dbg$1 = function dbg() {
14952
+ var _console;
14953
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
14954
+ args[_key] = arguments[_key];
14955
+ }
14956
+ return (_console = console).log.apply(_console, ['[VIDEO_FIRST_FRAME]'].concat(args));
14957
+ };
14958
+ var REMUX_MAX_BYTES = 200 * 1024 * 1024;
14959
+ var remuxCounter = 0;
14960
+ var remuxToMp4 = function remuxToMp4(blob) {
14961
+ try {
14962
+ if (blob.size > REMUX_MAX_BYTES) {
14963
+ dbg$1('remux: skipped, file too large:', blob.size);
14964
+ log.warn('remuxToMp4: file too large to remux in browser:', blob.size);
14965
+ return Promise.resolve(null);
14966
+ }
14967
+ var id = Date.now() + "_" + remuxCounter++;
14968
+ var inputName = "remux_" + id + "_in.mov";
14969
+ var outputName = "remux_" + id + "_out.mp4";
14970
+ var ffmpeg = null;
14971
+ return Promise.resolve(_finallyRethrows(function () {
14972
+ return _catch(function () {
14973
+ dbg$1('remux: starting ffmpeg -c copy remux, size =', blob.size);
14974
+ return Promise.resolve(Promise.all([Promise.resolve().then(function () { return audioConversion; }), import('@ffmpeg/util')])).then(function (_ref) {
14975
+ var initFFmpeg = _ref[0].initFFmpeg,
14976
+ fetchFile = _ref[1].fetchFile;
14977
+ return Promise.resolve(initFFmpeg()).then(function (_initFFmpeg) {
14978
+ ffmpeg = _initFFmpeg;
14979
+ var _ffmpeg = ffmpeg,
14980
+ _writeFile = _ffmpeg.writeFile;
14981
+ return Promise.resolve(fetchFile(blob)).then(function (_fetchFile) {
14982
+ return Promise.resolve(_writeFile.call(_ffmpeg, inputName, _fetchFile)).then(function () {
14983
+ return Promise.resolve(ffmpeg.exec(['-i', inputName, '-c', 'copy', '-movflags', '+faststart', outputName])).then(function () {
14984
+ return Promise.resolve(ffmpeg.readFile(outputName)).then(function (data) {
14985
+ var bytes;
14986
+ if (data instanceof Uint8Array) {
14987
+ bytes = data;
14988
+ } else if (typeof data === 'string') {
14989
+ var binaryString = atob(data);
14990
+ bytes = new Uint8Array(binaryString.length);
14991
+ for (var i = 0; i < binaryString.length; i++) {
14992
+ bytes[i] = binaryString.charCodeAt(i);
14993
+ }
14994
+ } else {
14995
+ bytes = new Uint8Array(data);
14996
+ }
14997
+ if (!bytes.length) {
14998
+ dbg$1('remux: ffmpeg produced empty output');
14999
+ return null;
15000
+ }
15001
+ var arrayBuffer = bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
15002
+ dbg$1('remux: done, output size =', bytes.length);
15003
+ return new Blob([arrayBuffer], {
15004
+ type: 'video/mp4'
15005
+ });
15006
+ });
15007
+ });
15008
+ });
15009
+ });
15010
+ });
15011
+ });
15012
+ }, function (error) {
15013
+ dbg$1('remux: FAILED', error);
15014
+ log.error('remuxToMp4: remux failed:', error);
15015
+ return null;
15016
+ });
15017
+ }, function (_wasThrown, _result) {
15018
+ function _temp5() {
15019
+ if (_wasThrown) throw _result;
15020
+ return _result;
15021
+ }
15022
+ var _temp4 = function () {
15023
+ if (ffmpeg) {
15024
+ var _temp3 = function _temp3() {
15025
+ var _temp = _catch(function () {
15026
+ return Promise.resolve(ffmpeg.deleteFile(outputName)).then(function () {});
15027
+ }, function () {});
15028
+ if (_temp && _temp.then) return _temp.then(function () {});
14938
15029
  };
15030
+ var _temp2 = _catch(function () {
15031
+ return Promise.resolve(ffmpeg.deleteFile(inputName)).then(function () {});
15032
+ }, function () {});
15033
+ return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
15034
+ }
15035
+ }();
15036
+ return _temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4);
15037
+ }));
15038
+ } catch (e) {
15039
+ return Promise.reject(e);
15040
+ }
15041
+ };
15042
+ var remuxVideoFileForUpload = function remuxVideoFileForUpload(file) {
15043
+ try {
15044
+ return Promise.resolve(_catch(function () {
15045
+ return Promise.resolve(inspectVideoBlob(file)).then(function (info) {
15046
+ if (!isQuickTimeContainer(info)) {
15047
+ return file;
15048
+ }
15049
+ dbg$1('upload: QuickTime file picked, remuxing before upload:', file.name);
15050
+ return Promise.resolve(remuxToMp4(file)).then(function (remuxed) {
15051
+ if (!remuxed) {
15052
+ log.warn('remuxVideoFileForUpload: remux failed, uploading original file');
15053
+ return file;
15054
+ }
15055
+ var newName = /\.(mov|qt)$/i.test(file.name) ? file.name.replace(/\.(mov|qt)$/i, '.mp4') : file.name + ".mp4";
15056
+ return new File([remuxed], newName, {
15057
+ type: 'video/mp4',
15058
+ lastModified: file.lastModified
15059
+ });
15060
+ });
15061
+ });
15062
+ }, function (error) {
15063
+ log.error('remuxVideoFileForUpload failed, uploading original file:', error);
15064
+ return file;
15065
+ }));
15066
+ } catch (e) {
15067
+ return Promise.reject(e);
15068
+ }
15069
+ };
15070
+ var ensurePlayableVideoBlob = function ensurePlayableVideoBlob(blob) {
15071
+ try {
15072
+ return Promise.resolve(_catch(function () {
15073
+ return isFirefox() ? Promise.resolve(inspectVideoBlob(blob)).then(function (info) {
15074
+ if (!isQuickTimeContainer(info)) {
15075
+ return blob;
15076
+ }
15077
+ dbg$1('download: QuickTime blob in Firefox, remuxing for playback');
15078
+ return Promise.resolve(remuxToMp4(blob)).then(function (remuxed) {
15079
+ return remuxed || blob;
15080
+ });
15081
+ }) : blob;
15082
+ }, function (error) {
15083
+ log.error('ensurePlayableVideoBlob failed, using original blob:', error);
15084
+ return blob;
15085
+ }));
15086
+ } catch (e) {
15087
+ return Promise.reject(e);
15088
+ }
15089
+ };
15090
+
15091
+ var getFrame = function getFrame(videoSrc, _time) {
15092
+ try {
15093
+ if (!videoSrc) {
15094
+ throw new Error('src not found');
15095
+ }
15096
+ return Promise.resolve(getVideoFirstFrame(videoSrc)).then(function (frameResult) {
15097
+ if (!frameResult) {
15098
+ throw new Error('Failed to extract video frame');
15099
+ }
15100
+ var frameBlobUrl = frameResult.frameBlobUrl,
15101
+ origWidth = frameResult.width,
15102
+ origHeight = frameResult.height;
15103
+ var duration = Number(frameResult.duration.toFixed(0));
15104
+ var _calculateSize = calculateSize(origWidth, origHeight, 100, 100),
15105
+ newWidth = _calculateSize[0],
15106
+ newHeight = _calculateSize[1];
15107
+ return new Promise(function (resolve, reject) {
15108
+ var img = document.createElement('img');
15109
+ img.onload = function () {
15110
+ var canvas = document.createElement('canvas');
15111
+ canvas.width = newWidth;
15112
+ canvas.height = newHeight;
15113
+ var ctx = canvas.getContext('2d');
15114
+ if (!ctx) {
15115
+ URL.revokeObjectURL(frameBlobUrl);
15116
+ reject(new Error('Failed to get canvas context'));
15117
+ return;
15118
+ }
15119
+ ctx.drawImage(img, 0, 0, newWidth, newHeight);
15120
+ var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
15121
+ var binaryThumbHash = rgbaToThumbHash(pixels.width, pixels.height, pixels.data);
15122
+ var thumb = binaryToBase64(binaryThumbHash);
15123
+ URL.revokeObjectURL(frameBlobUrl);
15124
+ resolve({
15125
+ thumb: thumb,
15126
+ width: origWidth,
15127
+ height: origHeight,
15128
+ duration: duration
15129
+ });
14939
15130
  };
14940
- video.onerror = function () {
14941
- log.error('Error loading video metadata for frame extraction');
14942
- cleanup();
14943
- resolve(null);
15131
+ img.onerror = function () {
15132
+ URL.revokeObjectURL(frameBlobUrl);
15133
+ reject(new Error('Failed to load frame image'));
14944
15134
  };
14945
- } catch (error) {
14946
- log.error('Error in getVideoFirstFrame:', error);
14947
- resolve(null);
15135
+ img.src = frameBlobUrl;
15136
+ });
15137
+ });
15138
+ } catch (e) {
15139
+ return Promise.reject(e);
15140
+ }
15141
+ };
15142
+ var getVideoFirstFrame = function getVideoFirstFrame(videoSrc, maxWidth, maxHeight, quality) {
15143
+ if (quality === void 0) {
15144
+ quality = 0.8;
15145
+ }
15146
+ try {
15147
+ var _exit3 = false;
15148
+ return Promise.resolve(_catch(function () {
15149
+ function _temp0(_result3) {
15150
+ var _exit4 = false;
15151
+ if (_exit3) return _result3;
15152
+ function _temp8(_result4) {
15153
+ if (_exit4) return _result4;
15154
+ dbg$2('source: remote URL —', videoSrc.slice(0, 150));
15155
+ return Promise.resolve(extractFrameFromUrl(videoSrc, maxWidth, maxHeight, quality)).then(function (direct) {
15156
+ if (direct) {
15157
+ return direct;
15158
+ }
15159
+ dbg$2('source: direct remote load failed, retrying via fetch + relabel');
15160
+ return _catch(function () {
15161
+ return Promise.resolve(fetch(videoSrc)).then(function (response) {
15162
+ return Promise.resolve(response.blob()).then(function (blob) {
15163
+ dbg$2('source: remote fetched, Content-Type =', JSON.stringify(response.headers.get('content-type')), 'blob type =', JSON.stringify(blob.type), 'size =', blob.size);
15164
+ return Promise.resolve(_extractFrameFromBlob2(blob, maxWidth, maxHeight, quality));
15165
+ });
15166
+ });
15167
+ }, function (error) {
15168
+ dbg$2('source: remote fetch retry FAILED', error);
15169
+ log.error('getVideoFirstFrame: fetch retry failed:', error);
15170
+ return null;
15171
+ });
15172
+ });
15173
+ }
15174
+ var _temp7 = function () {
15175
+ if (videoSrc.startsWith('blob:')) {
15176
+ dbg$2('source: blob URL string —', videoSrc.slice(0, 100));
15177
+ return _catch(function () {
15178
+ return Promise.resolve(fetch(videoSrc)).then(function (_fetch) {
15179
+ return Promise.resolve(_fetch.blob()).then(function (blob) {
15180
+ dbg$2('source: blob URL re-fetched, type =', JSON.stringify(blob.type), 'size =', blob.size);
15181
+ return Promise.resolve(_extractFrameFromBlob2(blob, maxWidth, maxHeight, quality)).then(function (_await$_extractFrameF2) {
15182
+ _exit4 = true;
15183
+ return _await$_extractFrameF2;
15184
+ });
15185
+ });
15186
+ });
15187
+ }, function (error) {
15188
+ dbg$2('source: blob URL re-fetch FAILED, falling back to direct', error);
15189
+ log.warn('getVideoFirstFrame: failed to re-fetch blob url, trying directly', error);
15190
+ return Promise.resolve(extractFrameFromUrl(videoSrc, maxWidth, maxHeight, quality)).then(function (_await$extractFrameFr) {
15191
+ _exit4 = true;
15192
+ return _await$extractFrameFr;
15193
+ });
15194
+ });
15195
+ }
15196
+ }();
15197
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
14948
15198
  }
15199
+ var _temp9 = function () {
15200
+ if (videoSrc instanceof Blob) {
15201
+ dbg$2('source: Blob, type =', JSON.stringify(videoSrc.type), 'size =', videoSrc.size);
15202
+ return Promise.resolve(_extractFrameFromBlob2(videoSrc, maxWidth, maxHeight, quality)).then(function (_await$_extractFrameF) {
15203
+ _exit3 = true;
15204
+ return _await$_extractFrameF;
15205
+ });
15206
+ }
15207
+ }();
15208
+ return _temp9 && _temp9.then ? _temp9.then(_temp0) : _temp0(_temp9);
15209
+ }, function (error) {
15210
+ log.error('Error in getVideoFirstFrame:', error);
15211
+ return null;
14949
15212
  }));
14950
15213
  } catch (e) {
14951
15214
  return Promise.reject(e);
14952
15215
  }
14953
15216
  };
14954
- var getFrame = function getFrame(videoSrc, _time) {
15217
+ var dbg$2 = function dbg() {
15218
+ var _console;
15219
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
15220
+ args[_key] = arguments[_key];
15221
+ }
15222
+ return (_console = console).log.apply(_console, ['[VIDEO_FIRST_FRAME]'].concat(args));
15223
+ };
15224
+ var normalizeVideoBlob = function normalizeVideoBlob(blob) {
14955
15225
  try {
14956
- return Promise.resolve(new Promise(function (resolve, reject) {
14957
- if (!videoSrc) {
14958
- reject(new Error('src not found'));
14959
- return;
15226
+ return Promise.resolve(inspectVideoBlob(blob)).then(function (info) {
15227
+ var baseType = (blob.type || '').split(';')[0].trim().toLowerCase();
15228
+ if (NATIVE_VIDEO_TYPES.has(baseType)) {
15229
+ dbg$2('normalize: declared type is native:', JSON.stringify(blob.type), '→', JSON.stringify(baseType));
15230
+ return {
15231
+ safeBlob: baseType === blob.type ? blob : new Blob([blob], {
15232
+ type: baseType
15233
+ }),
15234
+ info: info
15235
+ };
14960
15236
  }
15237
+ var relabeledType = info.mimeType || 'video/mp4';
15238
+ dbg$2('normalize: declared', JSON.stringify(blob.type), '→ relabeled to', JSON.stringify(relabeledType));
15239
+ return {
15240
+ safeBlob: new Blob([blob], {
15241
+ type: relabeledType
15242
+ }),
15243
+ info: info
15244
+ };
15245
+ });
15246
+ } catch (e) {
15247
+ return Promise.reject(e);
15248
+ }
15249
+ };
15250
+ var FRAME_LOAD_TIMEOUT_MS = 8000;
15251
+ var READY_STATES = ['HAVE_NOTHING', 'HAVE_METADATA', 'HAVE_CURRENT_DATA', 'HAVE_FUTURE_DATA', 'HAVE_ENOUGH_DATA'];
15252
+ var NETWORK_STATES = ['NETWORK_EMPTY', 'NETWORK_IDLE', 'NETWORK_LOADING', 'NETWORK_NO_SOURCE'];
15253
+ var describeVideoState = function describeVideoState(video) {
15254
+ var buffered = 'none';
15255
+ try {
15256
+ var ranges = [];
15257
+ for (var i = 0; i < video.buffered.length; i++) {
15258
+ ranges.push(video.buffered.start(i).toFixed(2) + "-" + video.buffered.end(i).toFixed(2));
15259
+ }
15260
+ buffered = ranges.join(',') || 'empty';
15261
+ } catch (e) {
15262
+ buffered = 'unavailable';
15263
+ }
15264
+ return "readyState=" + (READY_STATES[video.readyState] || video.readyState) + " " + ("networkState=" + (NETWORK_STATES[video.networkState] || video.networkState) + " ") + ("currentTime=" + video.currentTime + " duration=" + video.duration + " ") + ("videoWidth=" + video.videoWidth + " videoHeight=" + video.videoHeight + " ") + ("buffered=[" + buffered + "] error=" + (video.error ? video.error.code + ":" + video.error.message : 'null'));
15265
+ };
15266
+ var extractFrameFromUrl = function extractFrameFromUrl(srcUrl, maxWidth, maxHeight, quality) {
15267
+ if (quality === void 0) {
15268
+ quality = 0.8;
15269
+ }
15270
+ return new Promise(function (resolve) {
15271
+ try {
15272
+ dbg$2('extract: start, src =', srcUrl.slice(0, 100));
14961
15273
  var video = document.createElement('video');
14962
- video.preload = 'metadata';
15274
+ video.preload = 'auto';
14963
15275
  video.muted = true;
14964
15276
  video.setAttribute('playsinline', 'true');
14965
- video.src = videoSrc;
14966
- video.onloadedmetadata = function () {
15277
+ if (!srcUrl.startsWith('blob:') && !srcUrl.startsWith('data:')) {
15278
+ video.crossOrigin = 'anonymous';
15279
+ }
15280
+ video.style.position = 'fixed';
15281
+ video.style.bottom = '0';
15282
+ video.style.left = '0';
15283
+ video.style.width = '2px';
15284
+ video.style.height = '2px';
15285
+ video.style.opacity = '0';
15286
+ video.style.pointerEvents = 'none';
15287
+ video.style.zIndex = '-1';
15288
+ document.body.appendChild(video);
15289
+ var settled = false;
15290
+ var finishOnce = function finishOnce(result) {
15291
+ if (settled) return;
15292
+ settled = true;
15293
+ clearTimeout(stallTimer);
15294
+ if (video.parentNode) {
15295
+ video.parentNode.removeChild(video);
15296
+ }
15297
+ dbg$2('extract: finished,', result ? 'SUCCESS' : 'NULL');
15298
+ resolve(result);
15299
+ };
15300
+ var stallTimer = setTimeout(function () {
15301
+ dbg$2('extract: TIMEOUT —', describeVideoState(video));
15302
+ log.warn('getVideoFirstFrame: timed out waiting for video to load');
15303
+ finishOnce(null);
15304
+ }, FRAME_LOAD_TIMEOUT_MS);
15305
+ var extractFrame = function extractFrame() {
14967
15306
  try {
14968
- var _video$duration;
14969
- var origWidth = video.videoWidth;
14970
- var origHeight = video.videoHeight;
14971
- var duration = Number((_video$duration = video.duration) === null || _video$duration === void 0 ? void 0 : _video$duration.toFixed(0));
14972
- var _calculateSize = calculateSize(origWidth, origHeight, 100, 100),
14973
- newWidth = _calculateSize[0],
14974
- newHeight = _calculateSize[1];
14975
- return Promise.resolve(_catch(function () {
14976
- return Promise.resolve(getVideoFirstFrame(videoSrc, newWidth, newHeight)).then(function (frameResult) {
14977
- if (!frameResult) {
14978
- reject(new Error('Failed to extract video frame'));
14979
- return;
14980
- }
14981
- var img = document.createElement('img');
14982
- img.onload = function () {
14983
- var canvas = document.createElement('canvas');
14984
- canvas.width = newWidth;
14985
- canvas.height = newHeight;
14986
- var ctx = canvas.getContext('2d');
14987
- if (!ctx) {
14988
- URL.revokeObjectURL(frameResult.frameBlobUrl);
14989
- reject(new Error('Failed to get canvas context'));
14990
- return;
14991
- }
14992
- ctx.drawImage(img, 0, 0, newWidth, newHeight);
14993
- var pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
14994
- var binaryThumbHash = rgbaToThumbHash(pixels.width, pixels.height, pixels.data);
14995
- var thumb = binaryToBase64(binaryThumbHash);
14996
- URL.revokeObjectURL(frameResult.frameBlobUrl);
14997
- resolve({
14998
- thumb: thumb,
14999
- width: origWidth,
15000
- height: origHeight,
15001
- duration: duration
15002
- });
15003
- };
15004
- img.onerror = function () {
15005
- URL.revokeObjectURL(frameResult.frameBlobUrl);
15006
- reject(new Error('Failed to load frame image'));
15007
- };
15008
- img.src = frameResult.frameBlobUrl;
15307
+ dbg$2('extract: extractFrame,', describeVideoState(video));
15308
+ if (video.videoWidth === 0 || video.videoHeight === 0) {
15309
+ finishOnce(null);
15310
+ return;
15311
+ }
15312
+ var width = video.videoWidth;
15313
+ var height = video.videoHeight;
15314
+ var duration = Number.isFinite(video.duration) ? video.duration : 0;
15315
+ var canvasWidth = maxWidth || width / 2;
15316
+ var canvasHeight = maxHeight || height / 2;
15317
+ var canvas = document.createElement('canvas');
15318
+ canvas.width = canvasWidth;
15319
+ canvas.height = canvasHeight;
15320
+ var ctx = canvas.getContext('2d');
15321
+ if (!ctx) {
15322
+ finishOnce(null);
15323
+ return;
15324
+ }
15325
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
15326
+ canvas.toBlob(function (blob) {
15327
+ if (!blob) {
15328
+ dbg$2('extract: canvas.toBlob returned null');
15329
+ finishOnce(null);
15330
+ return;
15331
+ }
15332
+ var frameBlobUrl = URL.createObjectURL(blob);
15333
+ finishOnce({
15334
+ frameBlobUrl: frameBlobUrl,
15335
+ blob: blob,
15336
+ width: width,
15337
+ height: height,
15338
+ duration: duration
15009
15339
  });
15010
- }, function (err) {
15011
- reject(err);
15012
- }));
15013
- } catch (e) {
15014
- return Promise.reject(e);
15340
+ }, 'image/jpeg', quality);
15341
+ } catch (error) {
15342
+ dbg$2('extract: extractFrame threw', error);
15343
+ log.error('Error extracting video frame:', error);
15344
+ finishOnce(null);
15015
15345
  }
15016
15346
  };
15347
+ video.addEventListener('loadstart', function () {
15348
+ return dbg$2('event: loadstart,', describeVideoState(video));
15349
+ });
15350
+ video.addEventListener('loadeddata', function () {
15351
+ return dbg$2('event: loadeddata,', describeVideoState(video));
15352
+ });
15353
+ video.addEventListener('canplay', function () {
15354
+ return dbg$2('event: canplay,', describeVideoState(video));
15355
+ });
15356
+ video.addEventListener('canplaythrough', function () {
15357
+ return dbg$2('event: canplaythrough');
15358
+ });
15359
+ video.addEventListener('seeking', function () {
15360
+ return dbg$2('event: seeking, currentTime =', video.currentTime);
15361
+ });
15362
+ video.addEventListener('stalled', function () {
15363
+ return dbg$2('event: stalled,', describeVideoState(video));
15364
+ });
15365
+ video.addEventListener('suspend', function () {
15366
+ return dbg$2('event: suspend,', describeVideoState(video));
15367
+ });
15368
+ video.addEventListener('waiting', function () {
15369
+ return dbg$2('event: waiting,', describeVideoState(video));
15370
+ });
15371
+ video.addEventListener('emptied', function () {
15372
+ return dbg$2('event: emptied,', describeVideoState(video));
15373
+ });
15374
+ video.onloadedmetadata = function () {
15375
+ dbg$2('event: loadedmetadata,', describeVideoState(video));
15376
+ video.currentTime = 0.01;
15377
+ video.onseeked = function () {
15378
+ dbg$2('event: seeked,', describeVideoState(video));
15379
+ video.onseeked = null;
15380
+ var capture = function capture() {
15381
+ return requestAnimationFrame(extractFrame);
15382
+ };
15383
+ video.play().then(function () {
15384
+ dbg$2('play(): resolved');
15385
+ var done = false;
15386
+ var _finish = function finish() {
15387
+ if (done) return;
15388
+ done = true;
15389
+ video.removeEventListener('timeupdate', _finish);
15390
+ video.removeEventListener('ended', _finish);
15391
+ video.pause();
15392
+ capture();
15393
+ };
15394
+ video.addEventListener('timeupdate', _finish);
15395
+ video.addEventListener('ended', _finish);
15396
+ setTimeout(_finish, 500);
15397
+ })["catch"](function (err) {
15398
+ dbg$2('play(): rejected —', err === null || err === void 0 ? void 0 : err.name, err === null || err === void 0 ? void 0 : err.message);
15399
+ capture();
15400
+ });
15401
+ };
15402
+ };
15017
15403
  video.onerror = function () {
15018
- reject(new Error('Failed to load video'));
15404
+ dbg$2('event: error,', describeVideoState(video));
15405
+ log.warn('getVideoFirstFrame: video failed to load', video.error);
15406
+ finishOnce(null);
15019
15407
  };
15020
- }));
15021
- } catch (e) {
15022
- return Promise.reject(e);
15408
+ video.onabort = function () {
15409
+ dbg$2('event: abort,', describeVideoState(video));
15410
+ finishOnce(null);
15411
+ };
15412
+ video.src = srcUrl;
15413
+ dbg$2('extract: src assigned,', describeVideoState(video));
15414
+ } catch (error) {
15415
+ log.error('Error in extractFrameFromUrl:', error);
15416
+ resolve(null);
15417
+ }
15418
+ });
15419
+ };
15420
+ var DATA_URL_MAX_BYTES = 64 * 1024 * 1024;
15421
+ var blobToDataUrl = function blobToDataUrl(blob) {
15422
+ return new Promise(function (resolve, reject) {
15423
+ var reader = new FileReader();
15424
+ reader.onload = function () {
15425
+ return resolve(reader.result);
15426
+ };
15427
+ reader.onerror = function () {
15428
+ return reject(reader.error);
15429
+ };
15430
+ reader.readAsDataURL(blob);
15431
+ });
15432
+ };
15433
+ var _extractFrameFromBlob2 = function extractFrameFromBlob(blob, maxWidth, maxHeight, quality, allowRemux) {
15434
+ if (quality === void 0) {
15435
+ quality = 0.8;
15436
+ }
15437
+ if (allowRemux === void 0) {
15438
+ allowRemux = true;
15023
15439
  }
15440
+ return Promise.resolve(normalizeVideoBlob(blob)).then(function (_ref) {
15441
+ var _exit = false;
15442
+ var safeBlob = _ref.safeBlob,
15443
+ info = _ref.info;
15444
+ function _temp6(_result) {
15445
+ var _exit2 = false;
15446
+ if (_exit) return _result;
15447
+ function _temp4(_result2) {
15448
+ if (_exit2) return _result2;
15449
+ if (safeBlob.size > DATA_URL_MAX_BYTES) {
15450
+ dbg$2('fallback: blob too large for data URL fallback, size =', safeBlob.size);
15451
+ return null;
15452
+ }
15453
+ return _catch(function () {
15454
+ dbg$2('fallback: retrying via data URL, size =', safeBlob.size);
15455
+ return Promise.resolve(blobToDataUrl(safeBlob)).then(function (dataUrl) {
15456
+ return Promise.resolve(extractFrameFromUrl(dataUrl, maxWidth, maxHeight, quality));
15457
+ });
15458
+ }, function (error) {
15459
+ dbg$2('fallback: data URL conversion failed', error);
15460
+ log.error('getVideoFirstFrame: data URL fallback failed:', error);
15461
+ return null;
15462
+ });
15463
+ }
15464
+ var url = URL.createObjectURL(safeBlob);
15465
+ var _temp3 = _finallyRethrows(function () {
15466
+ return Promise.resolve(extractFrameFromUrl(url, maxWidth, maxHeight, quality)).then(function (result) {
15467
+ if (result) {
15468
+ _exit2 = true;
15469
+ return result;
15470
+ }
15471
+ });
15472
+ }, function (_wasThrown, _result2) {
15473
+ URL.revokeObjectURL(url);
15474
+ if (_wasThrown) throw _result2;
15475
+ return _result2;
15476
+ });
15477
+ return _temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3);
15478
+ }
15479
+ var _temp5 = function () {
15480
+ if (isQuickTimeContainer(info) && isFirefox()) {
15481
+ if (!allowRemux) {
15482
+ dbg$2('skip: remuxed output is still a QuickTime container — giving up');
15483
+ var _temp = null;
15484
+ _exit = true;
15485
+ return _temp;
15486
+ }
15487
+ dbg$2('skip: QuickTime (qt brand) container — Firefox cannot demux this, remuxing. codecs =', info.codecs.join(',') || '?');
15488
+ return Promise.resolve(remuxToMp4(safeBlob)).then(function (remuxed) {
15489
+ if (!remuxed) {
15490
+ log.warn('getVideoFirstFrame: QuickTime container is not supported by Firefox and remux failed');
15491
+ var _temp2 = null;
15492
+ _exit = true;
15493
+ return _temp2;
15494
+ }
15495
+ var _extractFrameFromBlob = _extractFrameFromBlob2(remuxed, maxWidth, maxHeight, quality, false);
15496
+ _exit = true;
15497
+ return _extractFrameFromBlob;
15498
+ });
15499
+ }
15500
+ }();
15501
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
15502
+ });
15024
15503
  };
15025
15504
  var compressAndCacheImage = function compressAndCacheImage(url, cacheKey, maxWidth, maxHeight, quality) {
15026
15505
  try {
15027
15506
  return Promise.resolve(_catch(function () {
15028
15507
  return Promise.resolve(fetch(url)).then(function (response) {
15029
15508
  return response.ok ? Promise.resolve(response.blob()).then(function (blob) {
15030
- var _exit = false;
15031
- function _temp2(_result2) {
15032
- if (_exit) return _result2;
15509
+ var _exit5 = false;
15510
+ function _temp10(_result5) {
15511
+ if (_exit5) return _result5;
15033
15512
  setAttachmentToCache(cacheKey, response);
15034
15513
  return '';
15035
15514
  }
15036
- var _temp = function () {
15515
+ var _temp1 = function () {
15037
15516
  if (blob.type.startsWith('image/')) {
15038
15517
  var file = new File([blob], 'image.jpeg', {
15039
15518
  type: blob.type
15040
15519
  });
15041
- return Promise.resolve(resizeImageWithPica(file, maxWidth || 1280, maxHeight || 1080, quality || 1)).then(function (_ref) {
15042
- var compressedBlob = _ref.blob;
15520
+ return Promise.resolve(resizeImageWithPica(file, maxWidth || 1280, maxHeight || 1080, quality || 1)).then(function (_ref2) {
15521
+ var compressedBlob = _ref2.blob;
15043
15522
  var returningUrl = compressedBlob ? URL.createObjectURL(compressedBlob) : '';
15044
15523
  if (compressedBlob) {
15045
15524
  var compressedResponse = new Response(compressedBlob, {
@@ -15048,13 +15527,13 @@ var compressAndCacheImage = function compressAndCacheImage(url, cacheKey, maxWid
15048
15527
  }
15049
15528
  });
15050
15529
  setAttachmentToCache(cacheKey, compressedResponse);
15051
- _exit = true;
15530
+ _exit5 = true;
15052
15531
  return returningUrl;
15053
15532
  }
15054
15533
  });
15055
15534
  }
15056
15535
  }();
15057
- return _temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp);
15536
+ return _temp1 && _temp1.then ? _temp1.then(_temp10) : _temp10(_temp1);
15058
15537
  }) : '';
15059
15538
  });
15060
15539
  }, function (error) {
@@ -37190,6 +37669,7 @@ var convertToAac = function convertToAac(file, messageId) {
37190
37669
  return Promise.reject(e);
37191
37670
  }
37192
37671
  };
37672
+ var convertMp3ToAac = convertToAac;
37193
37673
  var SAFARI_SUPPORTED_TYPES = new Set(['audio/mp4', 'audio/aac', 'audio/x-m4a', 'audio/wav', 'audio/x-wav', 'audio/aiff']);
37194
37674
  var convertAudioForSafari = function convertAudioForSafari(file, messageId) {
37195
37675
  try {
@@ -37211,6 +37691,15 @@ var convertAudioForSafari = function convertAudioForSafari(file, messageId) {
37211
37691
  }
37212
37692
  };
37213
37693
 
37694
+ var audioConversion = {
37695
+ __proto__: null,
37696
+ isSafari: isSafari,
37697
+ initFFmpeg: initFFmpeg,
37698
+ convertToAac: convertToAac,
37699
+ convertMp3ToAac: convertMp3ToAac,
37700
+ convertAudioForSafari: convertAudioForSafari
37701
+ };
37702
+
37214
37703
  var _templateObject$v, _templateObject2$r, _templateObject3$l, _templateObject4$h, _templateObject5$e, _templateObject6$b, _templateObject7$a;
37215
37704
  var AudioPlayer = function AudioPlayer(_ref) {
37216
37705
  var _file$metadata6, _file$metadata7;
@@ -38198,80 +38687,82 @@ var Attachment = function Attachment(_ref) {
38198
38687
  }, messageType);
38199
38688
  setDownloadFilePromise(attachment.id, urlPromise);
38200
38689
  return Promise.resolve(urlPromise).then(function (result) {
38201
- function _temp5() {
38202
- setIsCached(true);
38203
- setDownloadingFile(false);
38204
- setAttachmentUrl(downloadingUrl);
38205
- }
38206
- var url = URL.createObjectURL(result.Body);
38207
- setSizeProgress(undefined);
38208
- var downloadingUrl = url;
38209
- var _temp4 = function () {
38210
- if (attachment.type === attachmentTypes.image) {
38211
- return Promise.resolve(compressAndCacheImage(url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38212
- if (compressedUrl) {
38213
- downloadingUrl = compressedUrl;
38214
- }
38215
- setAttachmentToCache(attachment.url + '_original_image_url', new Response(result.Body, {
38216
- headers: {
38217
- 'Content-Type': 'image/jpeg'
38690
+ function _temp7(body) {
38691
+ function _temp6() {
38692
+ setIsCached(true);
38693
+ setDownloadingFile(false);
38694
+ setAttachmentUrl(downloadingUrl);
38695
+ }
38696
+ var url = URL.createObjectURL(body);
38697
+ setSizeProgress(undefined);
38698
+ var downloadingUrl = url;
38699
+ var _temp5 = function () {
38700
+ if (attachment.type === attachmentTypes.image) {
38701
+ return Promise.resolve(compressAndCacheImage(url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38702
+ if (compressedUrl) {
38703
+ downloadingUrl = compressedUrl;
38218
38704
  }
38219
- }));
38220
- dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', url));
38221
- });
38222
- } else {
38223
- var _temp3 = function _temp3() {
38224
- if (attachment.type === attachmentTypes.video) {
38225
- setAttachmentToCache(attachment.url + "_original_video_url", new Response(result.Body, {
38226
- headers: {
38227
- 'Content-Type': attachment.type || 'application/octet-stream'
38228
- }
38229
- }));
38230
- dispatch(setUpdateMessageAttachmentAC(attachment.url + "_original_video_url", url));
38231
- } else {
38232
- setAttachmentToCache(attachment.url, new Response(result.Body, {
38705
+ setAttachmentToCache(attachment.url + '_original_image_url', new Response(result.Body, {
38233
38706
  headers: {
38234
- 'Content-Type': attachment.type || 'application/octet-stream'
38707
+ 'Content-Type': 'image/jpeg'
38235
38708
  }
38236
38709
  }));
38237
- dispatch(setUpdateMessageAttachmentAC(attachment.url, url));
38238
- }
38239
- };
38240
- var _temp2 = function () {
38241
- if (attachment.type === attachmentTypes.video) {
38242
- return Promise.resolve(getVideoFirstFrame(url, renderWidth, renderHeight, 0.8)).then(function (result) {
38243
- var _temp = function () {
38244
- if (result) {
38245
- var frameBlobUrl = result.frameBlobUrl,
38246
- blob = result.blob;
38247
- var response = new Response(blob, {
38710
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_image_url', url));
38711
+ });
38712
+ } else {
38713
+ var _temp4 = function () {
38714
+ if (attachment.type === attachmentTypes.video) {
38715
+ return Promise.resolve(getVideoFirstFrame(body, renderWidth, renderHeight, 0.8)).then(function (frameResult) {
38716
+ function _temp3() {
38717
+ setAttachmentToCache(attachment.url + "_original_video_url", new Response(body, {
38248
38718
  headers: {
38249
- 'Content-Type': 'image/jpeg'
38719
+ 'Content-Type': body.type || 'application/octet-stream'
38250
38720
  }
38251
- });
38252
- var key = attachment.url;
38253
- return Promise.resolve(setAttachmentToCache(key, response)).then(function () {
38254
- dispatch(setUpdateMessageAttachmentAC(key, frameBlobUrl));
38255
- });
38721
+ }));
38722
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + "_original_video_url", url));
38256
38723
  }
38257
- }();
38258
- if (_temp && _temp.then) return _temp.then(function () {});
38259
- });
38260
- }
38261
- }();
38262
- return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
38263
- }
38264
- }();
38265
- return _temp4 && _temp4.then ? _temp4.then(_temp5) : _temp5(_temp4);
38724
+ var _temp2 = function () {
38725
+ if (frameResult) {
38726
+ var frameBlobUrl = frameResult.frameBlobUrl,
38727
+ blob = frameResult.blob;
38728
+ var response = new Response(blob, {
38729
+ headers: {
38730
+ 'Content-Type': 'image/jpeg'
38731
+ }
38732
+ });
38733
+ var key = attachment.url;
38734
+ return Promise.resolve(setAttachmentToCache(key, response)).then(function () {
38735
+ dispatch(setUpdateMessageAttachmentAC(key, frameBlobUrl));
38736
+ });
38737
+ }
38738
+ }();
38739
+ return _temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2);
38740
+ });
38741
+ } else {
38742
+ setAttachmentToCache(attachment.url, new Response(result.Body, {
38743
+ headers: {
38744
+ 'Content-Type': attachment.type || 'application/octet-stream'
38745
+ }
38746
+ }));
38747
+ dispatch(setUpdateMessageAttachmentAC(attachment.url, url));
38748
+ }
38749
+ }();
38750
+ if (_temp4 && _temp4.then) return _temp4.then(function () {});
38751
+ }
38752
+ }();
38753
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
38754
+ }
38755
+ var _temp = attachment.type === attachmentTypes.video;
38756
+ return _temp ? Promise.resolve(ensurePlayableVideoBlob(result.Body)).then(_temp7) : _temp7(result.Body);
38266
38757
  });
38267
38758
  } else {
38268
- var _temp7 = function _temp7(_result2) {
38759
+ var _temp9 = function _temp9(_result2) {
38269
38760
  if (_exit) return _result2;
38270
38761
  setAttachmentUrl(downloadingUrl);
38271
38762
  };
38272
38763
  var _exit = false;
38273
38764
  var downloadingUrl = attachment.url;
38274
- var _temp6 = function () {
38765
+ var _temp8 = function () {
38275
38766
  if (attachment.type === attachmentTypes.image) {
38276
38767
  return Promise.resolve(compressAndCacheImage(attachment.url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38277
38768
  if (compressedUrl) {
@@ -38282,47 +38773,51 @@ var Attachment = function Attachment(_ref) {
38282
38773
  } else {
38283
38774
  fetch(attachment.url).then(function (response) {
38284
38775
  try {
38285
- return Promise.resolve(response.blob()).then(function (blob) {
38286
- function _temp1() {
38287
- setAttachmentUrl(blobUrl);
38288
- setIsCached(true);
38289
- }
38290
- var blobUrl = URL.createObjectURL(blob);
38291
- var _temp0 = function () {
38292
- if (attachment.type === attachmentTypes.video) {
38293
- return Promise.resolve(getVideoFirstFrame(blobUrl, renderWidth, renderHeight, 0.8)).then(function (frameResult) {
38294
- function _temp9() {
38295
- setAttachmentToCache(attachment.url + '_original_video_url', new Response(blob, {
38296
- headers: {
38297
- 'Content-Type': blob.type || 'video/mp4'
38298
- }
38299
- }));
38300
- dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_video_url', blobUrl));
38301
- }
38302
- var _temp8 = function () {
38303
- if (frameResult) {
38304
- var frameBlobUrl = frameResult.frameBlobUrl,
38305
- frameBlob = frameResult.blob;
38306
- return Promise.resolve(setAttachmentToCache(attachment.url, new Response(frameBlob, {
38776
+ return Promise.resolve(response.blob()).then(function (rawBlob) {
38777
+ function _temp13(blob) {
38778
+ function _temp12() {
38779
+ setAttachmentUrl(blobUrl);
38780
+ setIsCached(true);
38781
+ }
38782
+ var blobUrl = URL.createObjectURL(blob);
38783
+ var _temp11 = function () {
38784
+ if (attachment.type === attachmentTypes.video) {
38785
+ return Promise.resolve(getVideoFirstFrame(blob, renderWidth, renderHeight, 0.8)).then(function (frameResult) {
38786
+ function _temp10() {
38787
+ setAttachmentToCache(attachment.url + '_original_video_url', new Response(blob, {
38307
38788
  headers: {
38308
- 'Content-Type': 'image/jpeg'
38789
+ 'Content-Type': blob.type || 'video/mp4'
38309
38790
  }
38310
- }))).then(function () {
38311
- dispatch(setUpdateMessageAttachmentAC(getAttachmentURLWithVersion(attachment.url), frameBlobUrl));
38312
- });
38791
+ }));
38792
+ dispatch(setUpdateMessageAttachmentAC(attachment.url + '_original_video_url', blobUrl));
38313
38793
  }
38314
- }();
38315
- return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
38316
- });
38317
- } else {
38318
- setAttachmentToCache(attachment.url, new Response(blob, {
38319
- headers: {
38320
- 'Content-Type': blob.type || 'application/octet-stream'
38321
- }
38322
- }));
38323
- }
38324
- }();
38325
- return _temp0 && _temp0.then ? _temp0.then(_temp1) : _temp1(_temp0);
38794
+ var _temp1 = function () {
38795
+ if (frameResult) {
38796
+ var frameBlobUrl = frameResult.frameBlobUrl,
38797
+ frameBlob = frameResult.blob;
38798
+ return Promise.resolve(setAttachmentToCache(attachment.url, new Response(frameBlob, {
38799
+ headers: {
38800
+ 'Content-Type': 'image/jpeg'
38801
+ }
38802
+ }))).then(function () {
38803
+ dispatch(setUpdateMessageAttachmentAC(getAttachmentURLWithVersion(attachment.url), frameBlobUrl));
38804
+ });
38805
+ }
38806
+ }();
38807
+ return _temp1 && _temp1.then ? _temp1.then(_temp10) : _temp10(_temp1);
38808
+ });
38809
+ } else {
38810
+ setAttachmentToCache(attachment.url, new Response(blob, {
38811
+ headers: {
38812
+ 'Content-Type': blob.type || 'application/octet-stream'
38813
+ }
38814
+ }));
38815
+ }
38816
+ }();
38817
+ return _temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11);
38818
+ }
38819
+ var _temp0 = attachment.type === attachmentTypes.video;
38820
+ return _temp0 ? Promise.resolve(ensurePlayableVideoBlob(rawBlob)).then(_temp13) : _temp13(rawBlob);
38326
38821
  });
38327
38822
  } catch (e) {
38328
38823
  return Promise.reject(e);
@@ -38333,7 +38828,7 @@ var Attachment = function Attachment(_ref) {
38333
38828
  _exit = true;
38334
38829
  }
38335
38830
  }();
38336
- return _temp6 && _temp6.then ? _temp6.then(_temp7) : _temp7(_temp6);
38831
+ return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
38337
38832
  }
38338
38833
  }());
38339
38834
  } catch (e) {
@@ -38349,9 +38844,9 @@ var Attachment = function Attachment(_ref) {
38349
38844
  if (!attachment.attachmentUrl && connectionStatus === CONNECTION_STATUS.CONNECTED && attachment.id && !attachmentUrlFromMap && !(attachment.type === attachmentTypes.file || attachment.type === attachmentTypes.link)) {
38350
38845
  getAttachmentUrlFromCache(attachment.url).then(function (cachedUrl) {
38351
38846
  try {
38352
- var _temp12 = function () {
38847
+ var _temp16 = function () {
38353
38848
  if (attachment.type === attachmentTypes.image && !isPreview) {
38354
- var _temp11 = function () {
38849
+ var _temp15 = function () {
38355
38850
  if (cachedUrl) {
38356
38851
  setAttachmentUrl(cachedUrl);
38357
38852
  dispatch(setUpdateMessageAttachmentAC(attachment.url, cachedUrl));
@@ -38359,7 +38854,7 @@ var Attachment = function Attachment(_ref) {
38359
38854
  } else {
38360
38855
  setIsCached(false);
38361
38856
  setDownloadingFile(true);
38362
- var _temp10 = function () {
38857
+ var _temp14 = function () {
38363
38858
  if (customDownloader) {
38364
38859
  customDownloader(attachment.url, false, function (progress) {
38365
38860
  var loadedRes = progress.loaded && progress.loaded / progress.total;
@@ -38411,10 +38906,10 @@ var Attachment = function Attachment(_ref) {
38411
38906
  });
38412
38907
  }
38413
38908
  }();
38414
- if (_temp10 && _temp10.then) return _temp10.then(function () {});
38909
+ if (_temp14 && _temp14.then) return _temp14.then(function () {});
38415
38910
  }
38416
38911
  }();
38417
- if (_temp11 && _temp11.then) return _temp11.then(function () {});
38912
+ if (_temp15 && _temp15.then) return _temp15.then(function () {});
38418
38913
  } else {
38419
38914
  if (cachedUrl) {
38420
38915
  setAttachmentUrl(cachedUrl);
@@ -38428,7 +38923,7 @@ var Attachment = function Attachment(_ref) {
38428
38923
  }
38429
38924
  }
38430
38925
  }();
38431
- return Promise.resolve(_temp12 && _temp12.then ? _temp12.then(function () {}) : void 0);
38926
+ return Promise.resolve(_temp16 && _temp16.then ? _temp16.then(function () {}) : void 0);
38432
38927
  } catch (e) {
38433
38928
  return Promise.reject(e);
38434
38929
  }
@@ -38446,13 +38941,13 @@ var Attachment = function Attachment(_ref) {
38446
38941
  setProgress(uploadPercent);
38447
38942
  }, messageType).then(function (url) {
38448
38943
  try {
38449
- var _temp14 = function _temp14() {
38944
+ var _temp18 = function _temp18() {
38450
38945
  setAttachmentUrl(downloadingUrl);
38451
38946
  dispatch(setUpdateMessageAttachmentAC(attachment.url, attachment.url));
38452
38947
  setDownloadingFile(false);
38453
38948
  };
38454
38949
  var downloadingUrl = url;
38455
- var _temp13 = function () {
38950
+ var _temp17 = function () {
38456
38951
  if (attachment.type === attachmentTypes.image) {
38457
38952
  return Promise.resolve(compressAndCacheImage(url, attachment.url, renderWidth, renderHeight)).then(function (compressedUrl) {
38458
38953
  if (compressedUrl) {
@@ -38465,7 +38960,7 @@ var Attachment = function Attachment(_ref) {
38465
38960
  });
38466
38961
  }
38467
38962
  }();
38468
- return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(_temp14) : _temp14(_temp13));
38963
+ return Promise.resolve(_temp17 && _temp17.then ? _temp17.then(_temp18) : _temp18(_temp17));
38469
38964
  } catch (e) {
38470
38965
  return Promise.reject(e);
38471
38966
  }
@@ -51383,252 +51878,260 @@ var SendMessageInput = function SendMessageInput(_ref3) {
51383
51878
  };
51384
51879
  var handleAddAttachment = function handleAddAttachment(file, isMediaAttachment) {
51385
51880
  try {
51386
- var customUploader = getCustomUploader();
51387
- var fileType = file.type.split('/')[0];
51388
- var tid = v4();
51389
- var reader = new FileReader();
51390
- var handleAttachmentImageForCache = function handleAttachmentImageForCache(attachment) {
51391
- try {
51392
- var _attachment$metadata;
51393
- var url = URL.createObjectURL(attachment.data);
51394
- dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata = attachment.metadata) === null || _attachment$metadata === void 0 ? void 0 : _attachment$metadata.tmb) || '', url));
51395
- return Promise.resolve();
51396
- } catch (e) {
51397
- return Promise.reject(e);
51398
- }
51399
- };
51400
- var handleAttachmentVideoForCache = function handleAttachmentVideoForCache(attachment) {
51401
- try {
51402
- var _calculateRenderedIma = calculateRenderedImageWidth(attachment.metadata.szh || 400, attachment.metadata.szh || 400),
51403
- newWidth = _calculateRenderedIma[0],
51404
- newHeight = _calculateRenderedIma[1];
51405
- var url = URL.createObjectURL(attachment.data);
51406
- return Promise.resolve(getVideoFirstFrame(url, newWidth, newHeight, 0.8)).then(function (result) {
51407
- if (result) {
51408
- var _attachment$metadata2;
51409
- var frameBlobUrl = result.frameBlobUrl;
51410
- dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata2 = attachment.metadata) === null || _attachment$metadata2 === void 0 ? void 0 : _attachment$metadata2.tmb) || '', frameBlobUrl));
51411
- }
51412
- });
51413
- } catch (e) {
51414
- return Promise.reject(e);
51415
- }
51416
- };
51417
- reader.onload = function () {
51418
- try {
51419
- setPendingAttachment(tid, {
51420
- file: file
51421
- });
51422
- var _temp8 = function () {
51423
- if (customUploader) {
51424
- var _temp4 = function () {
51425
- if (fileType === 'image') {
51426
- resizeImage(file).then(function (resizedFile) {
51427
- try {
51428
- return Promise.resolve(createImageThumbnail(file)).then(function (_ref4) {
51429
- var _resizedFile$blob;
51430
- var thumbnail = _ref4.thumbnail,
51431
- imageWidth = _ref4.imageWidth,
51432
- imageHeight = _ref4.imageHeight;
51433
- var attachment = {
51434
- data: file,
51435
- upload: false,
51436
- type: isMediaAttachment ? fileType : 'file',
51437
- attachmentUrl: URL.createObjectURL(resizedFile.blob),
51438
- tid: tid,
51439
- size: isMediaAttachment ? resizedFile !== null && resizedFile !== void 0 && resizedFile.blob ? resizedFile === null || resizedFile === void 0 ? void 0 : (_resizedFile$blob = resizedFile.blob) === null || _resizedFile$blob === void 0 ? void 0 : _resizedFile$blob.size : file.size : file.size,
51440
- metadata: {
51441
- szw: imageWidth,
51442
- szh: imageHeight,
51443
- tmb: thumbnail
51444
- }
51445
- };
51446
- handleAttachmentImageForCache(attachment);
51881
+ var _temp4 = function _temp4() {
51882
+ var fileType = file.type.split('/')[0];
51883
+ var tid = v4();
51884
+ var reader = new FileReader();
51885
+ var handleAttachmentImageForCache = function handleAttachmentImageForCache(attachment) {
51886
+ try {
51887
+ var _attachment$metadata;
51888
+ var url = URL.createObjectURL(attachment.data);
51889
+ dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata = attachment.metadata) === null || _attachment$metadata === void 0 ? void 0 : _attachment$metadata.tmb) || '', url));
51890
+ return Promise.resolve();
51891
+ } catch (e) {
51892
+ return Promise.reject(e);
51893
+ }
51894
+ };
51895
+ var handleAttachmentVideoForCache = function handleAttachmentVideoForCache(attachment) {
51896
+ try {
51897
+ var _calculateRenderedIma = calculateRenderedImageWidth(attachment.metadata.szh || 400, attachment.metadata.szh || 400),
51898
+ newWidth = _calculateRenderedIma[0],
51899
+ newHeight = _calculateRenderedIma[1];
51900
+ return Promise.resolve(getVideoFirstFrame(attachment.data, newWidth, newHeight, 0.8)).then(function (result) {
51901
+ if (result) {
51902
+ var _attachment$metadata2;
51903
+ var frameBlobUrl = result.frameBlobUrl;
51904
+ dispatch(setUpdateMessageAttachmentAC((attachment === null || attachment === void 0 ? void 0 : (_attachment$metadata2 = attachment.metadata) === null || _attachment$metadata2 === void 0 ? void 0 : _attachment$metadata2.tmb) || '', frameBlobUrl));
51905
+ }
51906
+ });
51907
+ } catch (e) {
51908
+ return Promise.reject(e);
51909
+ }
51910
+ };
51911
+ reader.onload = function () {
51912
+ try {
51913
+ setPendingAttachment(tid, {
51914
+ file: file
51915
+ });
51916
+ var _temp0 = function () {
51917
+ if (customUploader) {
51918
+ var _temp6 = function () {
51919
+ if (fileType === 'image') {
51920
+ resizeImage(file).then(function (resizedFile) {
51921
+ try {
51922
+ return Promise.resolve(createImageThumbnail(file)).then(function (_ref4) {
51923
+ var _resizedFile$blob;
51924
+ var thumbnail = _ref4.thumbnail,
51925
+ imageWidth = _ref4.imageWidth,
51926
+ imageHeight = _ref4.imageHeight;
51927
+ var attachment = {
51928
+ data: file,
51929
+ upload: false,
51930
+ type: isMediaAttachment ? fileType : 'file',
51931
+ attachmentUrl: URL.createObjectURL(resizedFile.blob),
51932
+ tid: tid,
51933
+ size: isMediaAttachment ? resizedFile !== null && resizedFile !== void 0 && resizedFile.blob ? resizedFile === null || resizedFile === void 0 ? void 0 : (_resizedFile$blob = resizedFile.blob) === null || _resizedFile$blob === void 0 ? void 0 : _resizedFile$blob.size : file.size : file.size,
51934
+ metadata: {
51935
+ szw: imageWidth,
51936
+ szh: imageHeight,
51937
+ tmb: thumbnail
51938
+ }
51939
+ };
51940
+ handleAttachmentImageForCache(attachment);
51941
+ setAttachments(function (prevState) {
51942
+ return [].concat(prevState, [attachment]);
51943
+ });
51944
+ });
51945
+ } catch (e) {
51946
+ return Promise.reject(e);
51947
+ }
51948
+ });
51949
+ } else {
51950
+ var _temp1 = function () {
51951
+ if (fileType === 'video') {
51952
+ return Promise.resolve(getFrame(file, 0)).then(function (_ref5) {
51953
+ var thumb = _ref5.thumb,
51954
+ width = _ref5.width,
51955
+ height = _ref5.height,
51956
+ duration = _ref5.duration;
51957
+ var attachment = {
51958
+ data: file,
51959
+ upload: false,
51960
+ type: isMediaAttachment ? fileType : 'file',
51961
+ attachmentUrl: URL.createObjectURL(file),
51962
+ tid: tid,
51963
+ size: file.size,
51964
+ metadata: {
51965
+ szw: width,
51966
+ szh: height,
51967
+ tmb: thumb,
51968
+ dur: duration
51969
+ }
51970
+ };
51971
+ handleAttachmentVideoForCache(attachment);
51972
+ setAttachments(function (prevState) {
51973
+ return [].concat(prevState, [attachment]);
51974
+ });
51975
+ });
51976
+ } else {
51447
51977
  setAttachments(function (prevState) {
51448
- return [].concat(prevState, [attachment]);
51978
+ return [].concat(prevState, [{
51979
+ data: file,
51980
+ upload: false,
51981
+ type: 'file',
51982
+ tid: tid,
51983
+ size: file.size
51984
+ }]);
51449
51985
  });
51450
- });
51451
- } catch (e) {
51452
- return Promise.reject(e);
51453
- }
51454
- });
51455
- } else {
51456
- var _temp9 = function () {
51457
- if (fileType === 'video') {
51458
- return Promise.resolve(getFrame(URL.createObjectURL(file), 0)).then(function (_ref5) {
51459
- var thumb = _ref5.thumb,
51460
- width = _ref5.width,
51461
- height = _ref5.height,
51462
- duration = _ref5.duration;
51463
- var attachment = {
51464
- data: file,
51465
- upload: false,
51466
- type: isMediaAttachment ? fileType : 'file',
51467
- attachmentUrl: URL.createObjectURL(file),
51468
- tid: tid,
51469
- size: file.size,
51470
- metadata: {
51471
- szw: width,
51472
- szh: height,
51473
- tmb: thumb,
51474
- dur: duration
51986
+ }
51987
+ }();
51988
+ if (_temp1 && _temp1.then) return _temp1.then(function () {});
51989
+ }
51990
+ }();
51991
+ if (_temp6 && _temp6.then) return _temp6.then(function () {});
51992
+ } else {
51993
+ var _temp9 = function () {
51994
+ if (fileType === 'image') {
51995
+ var _temp7 = function () {
51996
+ if (isMediaAttachment) {
51997
+ return Promise.resolve(createImageThumbnail(file)).then(function (_ref6) {
51998
+ var thumbnail = _ref6.thumbnail,
51999
+ imageWidth = _ref6.imageWidth,
52000
+ imageHeight = _ref6.imageHeight;
52001
+ var metas = {
52002
+ thumbnail: thumbnail,
52003
+ imageWidth: imageWidth,
52004
+ imageHeight: imageHeight
52005
+ };
52006
+ if (file.type === 'image/gif') {
52007
+ setAttachments(function (prevState) {
52008
+ return [].concat(prevState, [{
52009
+ data: file,
52010
+ upload: true,
52011
+ attachmentUrl: URL.createObjectURL(file),
52012
+ tid: tid,
52013
+ type: fileType,
52014
+ size: file.size,
52015
+ metadata: JSON.stringify({
52016
+ tmb: metas.thumbnail,
52017
+ szw: metas.imageWidth,
52018
+ szh: metas.imageHeight
52019
+ })
52020
+ }]);
52021
+ });
52022
+ } else {
52023
+ resizeImage(file).then(function (resizedFileData) {
52024
+ try {
52025
+ var resizedFile = new File([resizedFileData.blob], resizedFileData.file.name);
52026
+ var attachment = {
52027
+ data: resizedFile,
52028
+ upload: true,
52029
+ attachmentUrl: URL.createObjectURL(resizedFile),
52030
+ tid: tid,
52031
+ type: fileType,
52032
+ size: resizedFile.size,
52033
+ metadata: JSON.stringify({
52034
+ tmb: metas.thumbnail,
52035
+ szw: resizedFileData.newWidth,
52036
+ szh: resizedFileData.newHeight
52037
+ })
52038
+ };
52039
+ handleAttachmentImageForCache(attachment);
52040
+ setAttachments(function (prevState) {
52041
+ return [].concat(prevState, [attachment]);
52042
+ });
52043
+ return Promise.resolve();
52044
+ } catch (e) {
52045
+ return Promise.reject(e);
52046
+ }
52047
+ });
51475
52048
  }
51476
- };
51477
- handleAttachmentVideoForCache(attachment);
51478
- setAttachments(function (prevState) {
51479
- return [].concat(prevState, [attachment]);
51480
52049
  });
51481
- });
51482
- } else {
51483
- setAttachments(function (prevState) {
51484
- return [].concat(prevState, [{
51485
- data: file,
51486
- upload: false,
51487
- type: 'file',
51488
- tid: tid,
51489
- size: file.size
51490
- }]);
51491
- });
51492
- }
51493
- }();
51494
- if (_temp9 && _temp9.then) return _temp9.then(function () {});
51495
- }
51496
- }();
51497
- if (_temp4 && _temp4.then) return _temp4.then(function () {});
51498
- } else {
51499
- var _temp7 = function () {
51500
- if (fileType === 'image') {
51501
- var _temp5 = function () {
51502
- if (isMediaAttachment) {
51503
- return Promise.resolve(createImageThumbnail(file)).then(function (_ref6) {
51504
- var thumbnail = _ref6.thumbnail,
51505
- imageWidth = _ref6.imageWidth,
51506
- imageHeight = _ref6.imageHeight;
51507
- var metas = {
51508
- thumbnail: thumbnail,
51509
- imageWidth: imageWidth,
51510
- imageHeight: imageHeight
51511
- };
51512
- if (file.type === 'image/gif') {
52050
+ } else {
52051
+ return Promise.resolve(createImageThumbnail(file, undefined, 50, 50)).then(function (_ref7) {
52052
+ var thumbnail = _ref7.thumbnail;
51513
52053
  setAttachments(function (prevState) {
51514
52054
  return [].concat(prevState, [{
51515
52055
  data: file,
52056
+ type: 'file',
51516
52057
  upload: true,
51517
52058
  attachmentUrl: URL.createObjectURL(file),
51518
52059
  tid: tid,
51519
- type: fileType,
51520
52060
  size: file.size,
51521
52061
  metadata: JSON.stringify({
51522
- tmb: metas.thumbnail,
51523
- szw: metas.imageWidth,
51524
- szh: metas.imageHeight
52062
+ tmb: thumbnail
51525
52063
  })
51526
52064
  }]);
51527
52065
  });
51528
- } else {
51529
- resizeImage(file).then(function (resizedFileData) {
51530
- try {
51531
- var resizedFile = new File([resizedFileData.blob], resizedFileData.file.name);
51532
- var attachment = {
51533
- data: resizedFile,
51534
- upload: true,
51535
- attachmentUrl: URL.createObjectURL(resizedFile),
51536
- tid: tid,
51537
- type: fileType,
51538
- size: resizedFile.size,
51539
- metadata: JSON.stringify({
51540
- tmb: metas.thumbnail,
51541
- szw: resizedFileData.newWidth,
51542
- szh: resizedFileData.newHeight
51543
- })
51544
- };
51545
- handleAttachmentImageForCache(attachment);
51546
- setAttachments(function (prevState) {
51547
- return [].concat(prevState, [attachment]);
51548
- });
51549
- return Promise.resolve();
51550
- } catch (e) {
51551
- return Promise.reject(e);
51552
- }
52066
+ });
52067
+ }
52068
+ }();
52069
+ if (_temp7 && _temp7.then) return _temp7.then(function () {});
52070
+ } else {
52071
+ var _temp10 = function () {
52072
+ if (fileType === 'video') {
52073
+ return Promise.resolve(getFrame(file, 0)).then(function (_ref8) {
52074
+ var thumb = _ref8.thumb,
52075
+ width = _ref8.width,
52076
+ height = _ref8.height,
52077
+ duration = _ref8.duration;
52078
+ var metas = JSON.stringify({
52079
+ tmb: thumb,
52080
+ width: width,
52081
+ height: height,
52082
+ dur: duration
51553
52083
  });
51554
- }
51555
- });
51556
- } else {
51557
- return Promise.resolve(createImageThumbnail(file, undefined, 50, 50)).then(function (_ref7) {
51558
- var thumbnail = _ref7.thumbnail;
51559
- setAttachments(function (prevState) {
51560
- return [].concat(prevState, [{
52084
+ var attachment = {
51561
52085
  data: file,
51562
- type: 'file',
52086
+ type: 'video',
51563
52087
  upload: true,
52088
+ size: file.size,
51564
52089
  attachmentUrl: URL.createObjectURL(file),
51565
52090
  tid: tid,
51566
- size: file.size,
51567
- metadata: JSON.stringify({
51568
- tmb: thumbnail
51569
- })
51570
- }]);
51571
- });
51572
- });
51573
- }
51574
- }();
51575
- if (_temp5 && _temp5.then) return _temp5.then(function () {});
51576
- } else {
51577
- var _temp0 = function () {
51578
- if (fileType === 'video') {
51579
- return Promise.resolve(getFrame(URL.createObjectURL(file), 0)).then(function (_ref8) {
51580
- var thumb = _ref8.thumb,
51581
- width = _ref8.width,
51582
- height = _ref8.height,
51583
- duration = _ref8.duration;
51584
- var metas = JSON.stringify({
51585
- tmb: thumb,
51586
- width: width,
51587
- height: height,
51588
- dur: duration
52091
+ metadata: metas
52092
+ };
52093
+ handleAttachmentVideoForCache(attachment);
52094
+ setAttachments(function (prevState) {
52095
+ return [].concat(prevState, [attachment]);
52096
+ });
51589
52097
  });
51590
- var attachment = {
51591
- data: file,
51592
- type: 'video',
51593
- upload: true,
51594
- size: file.size,
51595
- attachmentUrl: URL.createObjectURL(file),
51596
- tid: tid,
51597
- metadata: metas
51598
- };
51599
- handleAttachmentVideoForCache(attachment);
52098
+ } else {
51600
52099
  setAttachments(function (prevState) {
51601
- return [].concat(prevState, [attachment]);
52100
+ return [].concat(prevState, [{
52101
+ data: file,
52102
+ upload: true,
52103
+ type: 'file',
52104
+ size: file.size,
52105
+ tid: tid
52106
+ }]);
51602
52107
  });
51603
- });
51604
- } else {
51605
- setAttachments(function (prevState) {
51606
- return [].concat(prevState, [{
51607
- data: file,
51608
- upload: true,
51609
- type: 'file',
51610
- size: file.size,
51611
- tid: tid
51612
- }]);
51613
- });
51614
- }
51615
- }();
51616
- if (_temp0 && _temp0.then) return _temp0.then(function () {});
51617
- }
51618
- }();
51619
- if (_temp7 && _temp7.then) return _temp7.then(function () {});
51620
- }
51621
- }();
51622
- return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
51623
- } catch (e) {
51624
- return Promise.reject(e);
51625
- }
51626
- };
51627
- reader.onerror = function (e) {
51628
- log.info(' error on read file onError', e);
52108
+ }
52109
+ }();
52110
+ if (_temp10 && _temp10.then) return _temp10.then(function () {});
52111
+ }
52112
+ }();
52113
+ if (_temp9 && _temp9.then) return _temp9.then(function () {});
52114
+ }
52115
+ }();
52116
+ return Promise.resolve(_temp0 && _temp0.then ? _temp0.then(function () {}) : void 0);
52117
+ } catch (e) {
52118
+ return Promise.reject(e);
52119
+ }
52120
+ };
52121
+ reader.onerror = function (e) {
52122
+ log.info(' error on read file onError', e);
52123
+ };
52124
+ reader.readAsBinaryString(file);
51629
52125
  };
51630
- reader.readAsBinaryString(file);
51631
- return Promise.resolve();
52126
+ var customUploader = getCustomUploader();
52127
+ var _temp3 = function () {
52128
+ if (file.type.split('/')[0] === 'video') {
52129
+ return Promise.resolve(remuxVideoFileForUpload(file)).then(function (_remuxVideoFileForUpl) {
52130
+ file = _remuxVideoFileForUpl;
52131
+ });
52132
+ }
52133
+ }();
52134
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3));
51632
52135
  } catch (e) {
51633
52136
  return Promise.reject(e);
51634
52137
  }
@@ -51687,14 +52190,14 @@ var SendMessageInput = function SendMessageInput(_ref3) {
51687
52190
  }
51688
52191
  }
51689
52192
  }
51690
- var _temp1 = function () {
52193
+ var _temp11 = function () {
51691
52194
  if (allowUpload) {
51692
52195
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, isMediaAttachment)).then(function () {});
51693
52196
  } else {
51694
52197
  showFileUploadError(errorMessage);
51695
52198
  }
51696
52199
  }();
51697
- return Promise.resolve(_temp1 && _temp1.then ? _temp1.then(function () {}) : void 0);
52200
+ return Promise.resolve(_temp11 && _temp11.then ? _temp11.then(function () {}) : void 0);
51698
52201
  } catch (e) {
51699
52202
  return Promise.reject(e);
51700
52203
  }