stream-chat-react 11.13.1 → 11.15.0
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.
- package/dist/{Window-44a85f63.js → Window-847d5d88.js} +13943 -397
- package/dist/browser.full-bundle.js +17317 -3876
- package/dist/browser.full-bundle.js.map +1 -1
- package/dist/browser.full-bundle.min.js +4 -4
- package/dist/browser.full-bundle.min.js.map +1 -1
- package/dist/components/Attachment/Audio.d.ts.map +1 -1
- package/dist/components/Attachment/Audio.js +7 -4
- package/dist/components/Attachment/Card.d.ts +1 -1
- package/dist/components/Attachment/Card.d.ts.map +1 -1
- package/dist/components/Attachment/Card.js +4 -2
- package/dist/components/Attachment/VoiceRecording.d.ts.map +1 -1
- package/dist/components/Attachment/VoiceRecording.js +6 -4
- package/dist/components/Attachment/audioSampling.d.ts +10 -0
- package/dist/components/Attachment/audioSampling.d.ts.map +1 -0
- package/dist/components/Attachment/audioSampling.js +83 -0
- package/dist/components/Attachment/components/FileSizeIndicator.js +2 -2
- package/dist/components/Attachment/components/WaveProgressBar.d.ts +3 -10
- package/dist/components/Attachment/components/WaveProgressBar.d.ts.map +1 -1
- package/dist/components/Attachment/components/WaveProgressBar.js +23 -90
- package/dist/components/Attachment/hooks/useAudioController.d.ts +11 -3
- package/dist/components/Attachment/hooks/useAudioController.d.ts.map +1 -1
- package/dist/components/Attachment/hooks/useAudioController.js +89 -26
- package/dist/components/Attachment/index.d.ts +1 -0
- package/dist/components/Attachment/index.d.ts.map +1 -1
- package/dist/components/Attachment/index.js +1 -0
- package/dist/components/Attachment/utils.d.ts +5 -3
- package/dist/components/Attachment/utils.d.ts.map +1 -1
- package/dist/components/Attachment/utils.js +1 -0
- package/dist/components/Channel/Channel.d.ts +5 -1
- package/dist/components/Channel/Channel.d.ts.map +1 -1
- package/dist/components/Channel/Channel.js +2 -0
- package/dist/components/ChannelSearch/SearchResults.d.ts +2 -2
- package/dist/components/ChannelSearch/SearchResults.d.ts.map +1 -1
- package/dist/components/ChannelSearch/SearchResults.js +1 -1
- package/dist/components/ChannelSearch/hooks/useChannelSearch.d.ts +1 -1
- package/dist/components/ChannelSearch/hooks/useChannelSearch.d.ts.map +1 -1
- package/dist/components/ChannelSearch/hooks/useChannelSearch.js +1 -1
- package/dist/components/Emojis/EmojiPicker.d.ts +2 -2
- package/dist/components/Emojis/index.cjs.js +2 -3
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecorder.d.ts +3 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecorder.d.ts.map +1 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecorder.js +24 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingButtons.d.ts +4 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingButtons.d.ts.map +1 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingButtons.js +5 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingInProgress.d.ts +3 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingInProgress.d.ts.map +1 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingInProgress.js +47 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingPreview.d.ts +8 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingPreview.d.ts.map +1 -0
- package/dist/components/MediaRecorder/AudioRecorder/AudioRecordingPreview.js +21 -0
- package/dist/components/MediaRecorder/AudioRecorder/RecordingTimer.d.ts +6 -0
- package/dist/components/MediaRecorder/AudioRecorder/RecordingTimer.d.ts.map +1 -0
- package/dist/components/MediaRecorder/AudioRecorder/RecordingTimer.js +9 -0
- package/dist/components/MediaRecorder/AudioRecorder/index.d.ts +4 -0
- package/dist/components/MediaRecorder/AudioRecorder/index.d.ts.map +1 -0
- package/dist/components/MediaRecorder/AudioRecorder/index.js +3 -0
- package/dist/components/MediaRecorder/RecordingPermissionDeniedNotification.d.ts +8 -0
- package/dist/components/MediaRecorder/RecordingPermissionDeniedNotification.d.ts.map +1 -0
- package/dist/components/MediaRecorder/RecordingPermissionDeniedNotification.js +21 -0
- package/dist/components/MediaRecorder/classes/AmplitudeRecorder.d.ts +55 -0
- package/dist/components/MediaRecorder/classes/AmplitudeRecorder.d.ts.map +1 -0
- package/dist/components/MediaRecorder/classes/AmplitudeRecorder.js +93 -0
- package/dist/components/MediaRecorder/classes/BrowserPermission.d.ts +23 -0
- package/dist/components/MediaRecorder/classes/BrowserPermission.d.ts.map +1 -0
- package/dist/components/MediaRecorder/classes/BrowserPermission.js +98 -0
- package/dist/components/MediaRecorder/classes/MediaRecorderController.d.ts +83 -0
- package/dist/components/MediaRecorder/classes/MediaRecorderController.d.ts.map +1 -0
- package/dist/components/MediaRecorder/classes/MediaRecorderController.js +313 -0
- package/dist/components/MediaRecorder/classes/index.d.ts +4 -0
- package/dist/components/MediaRecorder/classes/index.d.ts.map +1 -0
- package/dist/components/MediaRecorder/classes/index.js +2 -0
- package/dist/components/MediaRecorder/hooks/index.d.ts +2 -0
- package/dist/components/MediaRecorder/hooks/index.d.ts.map +1 -0
- package/dist/components/MediaRecorder/hooks/index.js +1 -0
- package/dist/components/MediaRecorder/hooks/useMediaRecorder.d.ts +20 -0
- package/dist/components/MediaRecorder/hooks/useMediaRecorder.d.ts.map +1 -0
- package/dist/components/MediaRecorder/hooks/useMediaRecorder.js +73 -0
- package/dist/components/MediaRecorder/index.d.ts +6 -0
- package/dist/components/MediaRecorder/index.d.ts.map +1 -0
- package/dist/components/MediaRecorder/index.js +5 -0
- package/dist/components/MediaRecorder/observable/BehaviorSubject.d.ts +11 -0
- package/dist/components/MediaRecorder/observable/BehaviorSubject.d.ts.map +1 -0
- package/dist/components/MediaRecorder/observable/BehaviorSubject.js +34 -0
- package/dist/components/MediaRecorder/observable/Observable.d.ts +18 -0
- package/dist/components/MediaRecorder/observable/Observable.d.ts.map +1 -0
- package/dist/components/MediaRecorder/observable/Observable.js +29 -0
- package/dist/components/MediaRecorder/observable/Observer.d.ts +10 -0
- package/dist/components/MediaRecorder/observable/Observer.d.ts.map +1 -0
- package/dist/components/MediaRecorder/observable/Observer.js +3 -0
- package/dist/components/MediaRecorder/observable/Subject.d.ts +16 -0
- package/dist/components/MediaRecorder/observable/Subject.d.ts.map +1 -0
- package/dist/components/MediaRecorder/observable/Subject.js +70 -0
- package/dist/components/MediaRecorder/observable/Subscription.d.ts +11 -0
- package/dist/components/MediaRecorder/observable/Subscription.d.ts.map +1 -0
- package/dist/components/MediaRecorder/observable/Subscription.js +13 -0
- package/dist/components/MediaRecorder/observable/index.d.ts +6 -0
- package/dist/components/MediaRecorder/observable/index.d.ts.map +1 -0
- package/dist/components/MediaRecorder/observable/index.js +5 -0
- package/dist/components/MediaRecorder/transcode/audioProcessing.d.ts +16 -0
- package/dist/components/MediaRecorder/transcode/audioProcessing.d.ts.map +1 -0
- package/dist/components/MediaRecorder/transcode/audioProcessing.js +51 -0
- package/dist/components/MediaRecorder/transcode/index.d.ts +8 -0
- package/dist/components/MediaRecorder/transcode/index.d.ts.map +1 -0
- package/dist/components/MediaRecorder/transcode/index.js +18 -0
- package/dist/components/MediaRecorder/transcode/mp3.d.ts +2 -0
- package/dist/components/MediaRecorder/transcode/mp3.d.ts.map +1 -0
- package/dist/components/MediaRecorder/transcode/mp3.js +53 -0
- package/dist/components/MediaRecorder/transcode/wav.d.ts +8 -0
- package/dist/components/MediaRecorder/transcode/wav.d.ts.map +1 -0
- package/dist/components/MediaRecorder/transcode/wav.js +117 -0
- package/dist/components/Message/MessageSimple.d.ts.map +1 -1
- package/dist/components/Message/MessageSimple.js +3 -2
- package/dist/components/MessageInput/AttachmentPreviewList.d.ts +2 -1
- package/dist/components/MessageInput/AttachmentPreviewList.d.ts.map +1 -1
- package/dist/components/MessageInput/AttachmentPreviewList.js +66 -20
- package/dist/components/MessageInput/CooldownTimer.d.ts.map +1 -1
- package/dist/components/MessageInput/CooldownTimer.js +4 -17
- package/dist/components/MessageInput/MessageInput.d.ts +10 -0
- package/dist/components/MessageInput/MessageInput.d.ts.map +1 -1
- package/dist/components/MessageInput/MessageInputFlat.d.ts.map +1 -1
- package/dist/components/MessageInput/MessageInputFlat.js +31 -9
- package/dist/components/MessageInput/MessageInputSmall.d.ts.map +1 -1
- package/dist/components/MessageInput/MessageInputSmall.js +3 -2
- package/dist/components/MessageInput/SendButton.d.ts +8 -0
- package/dist/components/MessageInput/SendButton.d.ts.map +1 -0
- package/dist/components/MessageInput/SendButton.js +9 -0
- package/dist/components/MessageInput/hooks/useAttachments.d.ts +5 -2
- package/dist/components/MessageInput/hooks/useAttachments.d.ts.map +1 -1
- package/dist/components/MessageInput/hooks/useAttachments.js +87 -3
- package/dist/components/MessageInput/hooks/useCreateMessageInputContext.d.ts.map +1 -1
- package/dist/components/MessageInput/hooks/useCreateMessageInputContext.js +12 -2
- package/dist/components/MessageInput/hooks/useMessageInputState.d.ts +22 -7
- package/dist/components/MessageInput/hooks/useMessageInputState.d.ts.map +1 -1
- package/dist/components/MessageInput/hooks/useMessageInputState.js +31 -5
- package/dist/components/MessageInput/hooks/useSubmitHandler.d.ts +2 -2
- package/dist/components/MessageInput/hooks/useSubmitHandler.d.ts.map +1 -1
- package/dist/components/MessageInput/hooks/useSubmitHandler.js +15 -6
- package/dist/components/MessageInput/hooks/useTimeElapsed.d.ts +10 -0
- package/dist/components/MessageInput/hooks/useTimeElapsed.d.ts.map +1 -0
- package/dist/components/MessageInput/hooks/useTimeElapsed.js +30 -0
- package/dist/components/MessageInput/hooks/useTimer.d.ts +4 -0
- package/dist/components/MessageInput/hooks/useTimer.d.ts.map +1 -0
- package/dist/components/MessageInput/hooks/useTimer.js +20 -0
- package/dist/components/MessageInput/hooks/utils.d.ts +1 -0
- package/dist/components/MessageInput/hooks/utils.d.ts.map +1 -1
- package/dist/components/MessageInput/hooks/utils.js +24 -7
- package/dist/components/MessageInput/icons.d.ts +5 -6
- package/dist/components/MessageInput/icons.d.ts.map +1 -1
- package/dist/components/MessageInput/icons.js +13 -10
- package/dist/components/MessageInput/index.d.ts +1 -0
- package/dist/components/MessageInput/index.d.ts.map +1 -1
- package/dist/components/MessageInput/index.js +1 -0
- package/dist/components/MessageInput/types.d.ts +36 -1
- package/dist/components/MessageInput/types.d.ts.map +1 -1
- package/dist/components/ReactFileUtilities/types.d.ts +1 -0
- package/dist/components/ReactFileUtilities/types.d.ts.map +1 -1
- package/dist/components/ReactFileUtilities/utils.d.ts +9 -1
- package/dist/components/ReactFileUtilities/utils.d.ts.map +1 -1
- package/dist/components/ReactFileUtilities/utils.js +25 -0
- package/dist/components/Reactions/utils/utils.d.ts +2 -1
- package/dist/components/Reactions/utils/utils.d.ts.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/constants/limits.d.ts +1 -0
- package/dist/constants/limits.d.ts.map +1 -1
- package/dist/constants/limits.js +1 -0
- package/dist/context/ComponentContext.d.ts +7 -4
- package/dist/context/ComponentContext.d.ts.map +1 -1
- package/dist/context/MessageInputContext.d.ts +4 -1
- package/dist/context/MessageInputContext.d.ts.map +1 -1
- package/dist/css/v2/index.css +3 -1
- package/dist/css/v2/index.layout.css +3 -1
- package/dist/i18n/Streami18n.d.ts +14 -0
- package/dist/i18n/Streami18n.d.ts.map +1 -1
- package/dist/i18n/de.json +14 -0
- package/dist/i18n/en.json +14 -0
- package/dist/i18n/es.json +14 -0
- package/dist/i18n/fr.json +14 -0
- package/dist/i18n/hi.json +14 -0
- package/dist/i18n/it.json +14 -0
- package/dist/i18n/ja.json +14 -0
- package/dist/i18n/ko.json +14 -0
- package/dist/i18n/nl.json +14 -0
- package/dist/i18n/pt.json +14 -0
- package/dist/i18n/ru.json +14 -0
- package/dist/i18n/tr.json +14 -0
- package/dist/index.cjs.js +22 -4
- package/dist/scss/v2/AttachmentList/AttachmentList-layout.scss +56 -8
- package/dist/scss/v2/AttachmentList/AttachmentList-theme.scss +22 -4
- package/dist/scss/v2/ImageCarousel/ImageCarousel-layout.scss +11 -2
- package/dist/scss/v2/ImageCarousel/ImageCarousel-theme.scss +14 -0
- package/dist/scss/v2/_global-theme-variables.scss +13 -13
- package/dist/utils/mergeDeep.d.ts +4 -0
- package/dist/utils/mergeDeep.d.ts.map +1 -0
- package/dist/utils/mergeDeep.js +5 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -3
- package/dist/components/MessageInput/hooks/useFileState.d.ts +0 -7
- package/dist/components/MessageInput/hooks/useFileState.d.ts.map +0 -1
- package/dist/components/MessageInput/hooks/useFileState.js +0 -8
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RecordedMediaType } from '../../ReactFileUtilities';
|
|
2
|
+
import { Subject } from '../observable/Subject';
|
|
3
|
+
import { BehaviorSubject } from '../observable/BehaviorSubject';
|
|
4
|
+
export declare enum RecordingPermission {
|
|
5
|
+
CAM = "camera",
|
|
6
|
+
MIC = "microphone"
|
|
7
|
+
}
|
|
8
|
+
export type BrowserPermissionOptions = {
|
|
9
|
+
mediaType: RecordedMediaType;
|
|
10
|
+
};
|
|
11
|
+
export declare class BrowserPermission {
|
|
12
|
+
name: string;
|
|
13
|
+
state: BehaviorSubject<PermissionState | undefined>;
|
|
14
|
+
status: BehaviorSubject<PermissionStatus | undefined>;
|
|
15
|
+
error: Subject<Error | undefined>;
|
|
16
|
+
private changeSubscriptions;
|
|
17
|
+
constructor({ mediaType }: BrowserPermissionOptions);
|
|
18
|
+
get isWatching(): boolean;
|
|
19
|
+
watch(): Promise<void>;
|
|
20
|
+
unwatch(): void;
|
|
21
|
+
check(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=BrowserPermission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrowserPermission.d.ts","sourceRoot":"","sources":["../../../../src/components/MediaRecorder/classes/BrowserPermission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE,oBAAY,mBAAmB;IAC7B,GAAG,WAAW;IACd,GAAG,eAAe;CACnB;AAOD,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,iBAAiB,CAAC;CAC9B,CAAC;AAEF,qBAAa,iBAAiB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,+CAA+D;IACpE,MAAM,gDAAgE;IACtE,KAAK,6BAAoC;IAEzC,OAAO,CAAC,mBAAmB,CAAsB;gBAErC,EAAE,SAAS,EAAE,EAAE,wBAAwB;IAInD,IAAI,UAAU,YAEb;IAEK,KAAK;IAoBX,OAAO;IAID,KAAK;CAoBZ"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { Subscription } from '../observable/Subscription';
|
|
3
|
+
import { Subject } from '../observable/Subject';
|
|
4
|
+
import { BehaviorSubject } from '../observable/BehaviorSubject';
|
|
5
|
+
export var RecordingPermission;
|
|
6
|
+
(function (RecordingPermission) {
|
|
7
|
+
RecordingPermission["CAM"] = "camera";
|
|
8
|
+
RecordingPermission["MIC"] = "microphone";
|
|
9
|
+
})(RecordingPermission || (RecordingPermission = {}));
|
|
10
|
+
var MEDIA_TO_PERMISSION = {
|
|
11
|
+
audio: RecordingPermission.MIC,
|
|
12
|
+
video: RecordingPermission.CAM,
|
|
13
|
+
};
|
|
14
|
+
var BrowserPermission = /** @class */ (function () {
|
|
15
|
+
function BrowserPermission(_a) {
|
|
16
|
+
var mediaType = _a.mediaType;
|
|
17
|
+
this.state = new BehaviorSubject(undefined);
|
|
18
|
+
this.status = new BehaviorSubject(undefined);
|
|
19
|
+
this.error = new Subject();
|
|
20
|
+
this.changeSubscriptions = [];
|
|
21
|
+
this.name = MEDIA_TO_PERMISSION[mediaType];
|
|
22
|
+
}
|
|
23
|
+
Object.defineProperty(BrowserPermission.prototype, "isWatching", {
|
|
24
|
+
get: function () {
|
|
25
|
+
return this.changeSubscriptions.some(function (subscription) { return !subscription.closed; });
|
|
26
|
+
},
|
|
27
|
+
enumerable: false,
|
|
28
|
+
configurable: true
|
|
29
|
+
});
|
|
30
|
+
BrowserPermission.prototype.watch = function () {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
32
|
+
var status, handlePermissionChange;
|
|
33
|
+
var _this = this;
|
|
34
|
+
return __generator(this, function (_a) {
|
|
35
|
+
switch (_a.label) {
|
|
36
|
+
case 0:
|
|
37
|
+
if (!!this.status.value) return [3 /*break*/, 2];
|
|
38
|
+
return [4 /*yield*/, this.check()];
|
|
39
|
+
case 1:
|
|
40
|
+
_a.sent();
|
|
41
|
+
if (!this.status.value)
|
|
42
|
+
return [2 /*return*/];
|
|
43
|
+
_a.label = 2;
|
|
44
|
+
case 2:
|
|
45
|
+
status = this.status.value;
|
|
46
|
+
handlePermissionChange = function (e) {
|
|
47
|
+
var state = e.target.state;
|
|
48
|
+
_this.state.next(state);
|
|
49
|
+
};
|
|
50
|
+
status.addEventListener('change', handlePermissionChange);
|
|
51
|
+
this.changeSubscriptions.push(new Subscription(function () {
|
|
52
|
+
status.removeEventListener('change', handlePermissionChange);
|
|
53
|
+
}));
|
|
54
|
+
return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
BrowserPermission.prototype.unwatch = function () {
|
|
60
|
+
this.changeSubscriptions.forEach(function (subscription) { return subscription.unsubscribe(); });
|
|
61
|
+
};
|
|
62
|
+
BrowserPermission.prototype.check = function () {
|
|
63
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
+
var permissionState, permissionStatus, e_1;
|
|
65
|
+
return __generator(this, function (_a) {
|
|
66
|
+
switch (_a.label) {
|
|
67
|
+
case 0:
|
|
68
|
+
if (!this.name) {
|
|
69
|
+
this.error.next(new Error('Unknown media recording permission'));
|
|
70
|
+
return [2 /*return*/];
|
|
71
|
+
}
|
|
72
|
+
_a.label = 1;
|
|
73
|
+
case 1:
|
|
74
|
+
_a.trys.push([1, 3, , 4]);
|
|
75
|
+
return [4 /*yield*/, navigator.permissions.query({
|
|
76
|
+
name: this.name,
|
|
77
|
+
})];
|
|
78
|
+
case 2:
|
|
79
|
+
permissionStatus = _a.sent();
|
|
80
|
+
permissionState = permissionStatus.state;
|
|
81
|
+
this.status.next(permissionStatus);
|
|
82
|
+
return [3 /*break*/, 4];
|
|
83
|
+
case 3:
|
|
84
|
+
e_1 = _a.sent();
|
|
85
|
+
// permission does not exist - cannot be queried
|
|
86
|
+
// an example would be Firefox - camera, neither microphone perms can be queried
|
|
87
|
+
permissionState = 'granted';
|
|
88
|
+
return [3 /*break*/, 4];
|
|
89
|
+
case 4:
|
|
90
|
+
this.state.next(permissionState);
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return BrowserPermission;
|
|
97
|
+
}());
|
|
98
|
+
export { BrowserPermission };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { AmplitudeRecorder, AmplitudeRecorderConfig } from './AmplitudeRecorder';
|
|
2
|
+
import { BrowserPermission } from './BrowserPermission';
|
|
3
|
+
import { BehaviorSubject, Subject } from '../observable';
|
|
4
|
+
import { RecordedMediaType } from '../../ReactFileUtilities';
|
|
5
|
+
import { TranslationContextValue } from '../../../context';
|
|
6
|
+
import type { LocalVoiceRecordingAttachment } from '../../MessageInput';
|
|
7
|
+
export declare const POSSIBLE_TRANSCODING_MIME_TYPES: readonly ["audio/wav", "audio/mp3"];
|
|
8
|
+
export declare const DEFAULT_MEDIA_RECORDER_CONFIG: MediaRecorderConfig;
|
|
9
|
+
export declare const DEFAULT_AUDIO_TRANSCODER_CONFIG: TranscoderConfig;
|
|
10
|
+
type SupportedTranscodeMimeTypes = typeof POSSIBLE_TRANSCODING_MIME_TYPES[number];
|
|
11
|
+
export type TranscoderConfig = {
|
|
12
|
+
sampleRate: number;
|
|
13
|
+
targetMimeType: SupportedTranscodeMimeTypes;
|
|
14
|
+
};
|
|
15
|
+
type MediaRecorderConfig = Omit<MediaRecorderOptions, 'mimeType'> & Required<Pick<MediaRecorderOptions, 'mimeType'>>;
|
|
16
|
+
export type AudioRecorderConfig = {
|
|
17
|
+
amplitudeRecorderConfig: AmplitudeRecorderConfig;
|
|
18
|
+
mediaRecorderConfig: MediaRecorderOptions;
|
|
19
|
+
transcoderConfig: TranscoderConfig;
|
|
20
|
+
};
|
|
21
|
+
export type AudioRecorderOptions = {
|
|
22
|
+
config?: Partial<AudioRecorderConfig>;
|
|
23
|
+
generateRecordingTitle?: (mimeType: string) => string;
|
|
24
|
+
t?: TranslationContextValue['t'];
|
|
25
|
+
};
|
|
26
|
+
export declare enum MediaRecordingState {
|
|
27
|
+
PAUSED = "paused",
|
|
28
|
+
RECORDING = "recording",
|
|
29
|
+
STOPPED = "stopped"
|
|
30
|
+
}
|
|
31
|
+
export declare enum RecordingAttachmentType {
|
|
32
|
+
VOICE_RECORDING = "voiceRecording"
|
|
33
|
+
}
|
|
34
|
+
export declare class MediaRecorderController {
|
|
35
|
+
permission: BrowserPermission;
|
|
36
|
+
mediaRecorder: MediaRecorder | undefined;
|
|
37
|
+
amplitudeRecorder: AmplitudeRecorder | undefined;
|
|
38
|
+
amplitudeRecorderConfig: AmplitudeRecorderConfig;
|
|
39
|
+
mediaRecorderConfig: MediaRecorderConfig;
|
|
40
|
+
transcoderConfig: TranscoderConfig;
|
|
41
|
+
startTime: number | undefined;
|
|
42
|
+
recordedChunkDurations: number[];
|
|
43
|
+
recordedData: Blob[];
|
|
44
|
+
recordingUri: string | undefined;
|
|
45
|
+
mediaType: RecordedMediaType;
|
|
46
|
+
signalRecordingReady: ((r: LocalVoiceRecordingAttachment) => void) | undefined;
|
|
47
|
+
recordingState: BehaviorSubject<MediaRecordingState | undefined>;
|
|
48
|
+
recording: BehaviorSubject<LocalVoiceRecordingAttachment<import("../../..").DefaultStreamChatGenerics> | undefined>;
|
|
49
|
+
error: Subject<Error | undefined>;
|
|
50
|
+
notification: Subject<{
|
|
51
|
+
text: string;
|
|
52
|
+
type: 'success' | 'error';
|
|
53
|
+
} | undefined>;
|
|
54
|
+
customGenerateRecordingTitle: ((mimeType: string) => string) | undefined;
|
|
55
|
+
t: TranslationContextValue['t'];
|
|
56
|
+
constructor({ config, generateRecordingTitle, t }?: AudioRecorderOptions);
|
|
57
|
+
get durationMs(): number;
|
|
58
|
+
generateRecordingTitle: (mimeType: string) => string;
|
|
59
|
+
makeVoiceRecording: () => Promise<{
|
|
60
|
+
$internal: {
|
|
61
|
+
file: File;
|
|
62
|
+
id: string;
|
|
63
|
+
};
|
|
64
|
+
asset_url: string;
|
|
65
|
+
duration: number;
|
|
66
|
+
file_size: number;
|
|
67
|
+
mime_type: string;
|
|
68
|
+
title: string;
|
|
69
|
+
type: RecordingAttachmentType;
|
|
70
|
+
waveform_data: number[];
|
|
71
|
+
} | undefined>;
|
|
72
|
+
handleErrorEvent: (e: Event) => void;
|
|
73
|
+
handleDataavailableEvent: (e: BlobEvent) => Promise<void>;
|
|
74
|
+
resetRecordingState: () => void;
|
|
75
|
+
cleanUp: () => void;
|
|
76
|
+
start: () => Promise<void>;
|
|
77
|
+
pause: () => void;
|
|
78
|
+
resume: () => void;
|
|
79
|
+
stop: () => Promise<undefined> | Promise<LocalVoiceRecordingAttachment<import("../../..").DefaultStreamChatGenerics>>;
|
|
80
|
+
cancel: () => void;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=MediaRecorderController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MediaRecorderController.d.ts","sourceRoot":"","sources":["../../../../src/components/MediaRecorder/classes/MediaRecorderController.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
+
import fixWebmDuration from 'fix-webm-duration';
|
|
3
|
+
import { nanoid } from 'nanoid';
|
|
4
|
+
import { AmplitudeRecorder, DEFAULT_AMPLITUDE_RECORDER_CONFIG, } from './AmplitudeRecorder';
|
|
5
|
+
import { BrowserPermission } from './BrowserPermission';
|
|
6
|
+
import { BehaviorSubject, Subject } from '../observable';
|
|
7
|
+
import { transcode } from '../transcode';
|
|
8
|
+
import { resampleWaveformData } from '../../Attachment';
|
|
9
|
+
import { createFileFromBlobs, getExtensionFromMimeType, getRecordedMediaTypeFromMimeType, } from '../../ReactFileUtilities';
|
|
10
|
+
import { defaultTranslatorFunction } from '../../../i18n';
|
|
11
|
+
import { isSafari } from '../../../utils/browsers';
|
|
12
|
+
import { mergeDeepUndefined } from '../../../utils/mergeDeep';
|
|
13
|
+
var RECORDED_MIME_TYPE_BY_BROWSER = {
|
|
14
|
+
audio: {
|
|
15
|
+
others: 'audio/webm',
|
|
16
|
+
safari: 'audio/mp4;codecs=mp4a.40.2',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
export var POSSIBLE_TRANSCODING_MIME_TYPES = ['audio/wav', 'audio/mp3'];
|
|
20
|
+
export var DEFAULT_MEDIA_RECORDER_CONFIG = {
|
|
21
|
+
mimeType: isSafari()
|
|
22
|
+
? RECORDED_MIME_TYPE_BY_BROWSER.audio.safari
|
|
23
|
+
: RECORDED_MIME_TYPE_BY_BROWSER.audio.others,
|
|
24
|
+
};
|
|
25
|
+
export var DEFAULT_AUDIO_TRANSCODER_CONFIG = {
|
|
26
|
+
sampleRate: 16000,
|
|
27
|
+
targetMimeType: 'audio/mp3',
|
|
28
|
+
};
|
|
29
|
+
var disposeOfMediaStream = function (stream) {
|
|
30
|
+
if (!(stream === null || stream === void 0 ? void 0 : stream.active))
|
|
31
|
+
return;
|
|
32
|
+
stream.getTracks().forEach(function (track) {
|
|
33
|
+
track.stop();
|
|
34
|
+
stream.removeTrack(track);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var logError = function (e) { return e && console.error('[MEDIA RECORDER ERROR]', e); };
|
|
38
|
+
export var MediaRecordingState;
|
|
39
|
+
(function (MediaRecordingState) {
|
|
40
|
+
MediaRecordingState["PAUSED"] = "paused";
|
|
41
|
+
MediaRecordingState["RECORDING"] = "recording";
|
|
42
|
+
MediaRecordingState["STOPPED"] = "stopped";
|
|
43
|
+
})(MediaRecordingState || (MediaRecordingState = {}));
|
|
44
|
+
export var RecordingAttachmentType;
|
|
45
|
+
(function (RecordingAttachmentType) {
|
|
46
|
+
RecordingAttachmentType["VOICE_RECORDING"] = "voiceRecording";
|
|
47
|
+
})(RecordingAttachmentType || (RecordingAttachmentType = {}));
|
|
48
|
+
var MediaRecorderController = /** @class */ (function () {
|
|
49
|
+
function MediaRecorderController(_a) {
|
|
50
|
+
var _b = _a === void 0 ? {} : _a, config = _b.config, generateRecordingTitle = _b.generateRecordingTitle, t = _b.t;
|
|
51
|
+
var _this = this;
|
|
52
|
+
this.recordedChunkDurations = [];
|
|
53
|
+
this.recordedData = [];
|
|
54
|
+
this.recordingState = new BehaviorSubject(undefined);
|
|
55
|
+
this.recording = new BehaviorSubject(undefined);
|
|
56
|
+
this.error = new Subject();
|
|
57
|
+
this.notification = new Subject();
|
|
58
|
+
this.generateRecordingTitle = function (mimeType) {
|
|
59
|
+
if (_this.customGenerateRecordingTitle) {
|
|
60
|
+
return _this.customGenerateRecordingTitle(mimeType);
|
|
61
|
+
}
|
|
62
|
+
return "".concat(_this.mediaType, "_recording_").concat(new Date().toISOString(), ".").concat(getExtensionFromMimeType(mimeType)); // extension needed so that desktop Safari can play the asset
|
|
63
|
+
};
|
|
64
|
+
this.makeVoiceRecording = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
65
|
+
var mimeType, blob, file;
|
|
66
|
+
var _a, _b;
|
|
67
|
+
return __generator(this, function (_c) {
|
|
68
|
+
switch (_c.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
if (this.recordingUri)
|
|
71
|
+
URL.revokeObjectURL(this.recordingUri);
|
|
72
|
+
if (!this.recordedData.length)
|
|
73
|
+
return [2 /*return*/];
|
|
74
|
+
mimeType = this.mediaRecorderConfig.mimeType;
|
|
75
|
+
blob = new Blob(this.recordedData, { type: mimeType });
|
|
76
|
+
if (!mimeType.match('audio/webm')) return [3 /*break*/, 2];
|
|
77
|
+
return [4 /*yield*/, fixWebmDuration(blob, this.durationMs, {
|
|
78
|
+
logger: function () { return null; }, // prevents polluting the browser console
|
|
79
|
+
})];
|
|
80
|
+
case 1:
|
|
81
|
+
// The browser does not include duration metadata with the recorded blob
|
|
82
|
+
blob = _c.sent();
|
|
83
|
+
_c.label = 2;
|
|
84
|
+
case 2:
|
|
85
|
+
if (!!mimeType.match('audio/mp4')) return [3 /*break*/, 4];
|
|
86
|
+
return [4 /*yield*/, transcode(__assign({ blob: blob }, this.transcoderConfig))];
|
|
87
|
+
case 3:
|
|
88
|
+
blob = _c.sent();
|
|
89
|
+
_c.label = 4;
|
|
90
|
+
case 4:
|
|
91
|
+
if (!blob)
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
this.recordingUri = URL.createObjectURL(blob);
|
|
94
|
+
file = createFileFromBlobs({
|
|
95
|
+
blobsArray: [blob],
|
|
96
|
+
fileName: this.generateRecordingTitle(blob.type),
|
|
97
|
+
mimeType: blob.type,
|
|
98
|
+
});
|
|
99
|
+
return [2 /*return*/, {
|
|
100
|
+
$internal: {
|
|
101
|
+
file: file,
|
|
102
|
+
id: nanoid(),
|
|
103
|
+
},
|
|
104
|
+
asset_url: this.recordingUri,
|
|
105
|
+
duration: this.durationMs / 1000,
|
|
106
|
+
file_size: blob.size,
|
|
107
|
+
mime_type: blob.type,
|
|
108
|
+
title: file.name,
|
|
109
|
+
type: RecordingAttachmentType.VOICE_RECORDING,
|
|
110
|
+
waveform_data: resampleWaveformData((_b = (_a = this.amplitudeRecorder) === null || _a === void 0 ? void 0 : _a.amplitudes.value) !== null && _b !== void 0 ? _b : [], this.amplitudeRecorderConfig.sampleCount),
|
|
111
|
+
}];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); };
|
|
115
|
+
this.handleErrorEvent = function (e) {
|
|
116
|
+
var error = e.error;
|
|
117
|
+
logError(error);
|
|
118
|
+
_this.error.next(error);
|
|
119
|
+
_this.notification.next({
|
|
120
|
+
text: _this.t('An error has occurred during recording'),
|
|
121
|
+
type: 'error',
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
this.handleDataavailableEvent = function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
125
|
+
var recording, e_1;
|
|
126
|
+
var _a;
|
|
127
|
+
return __generator(this, function (_b) {
|
|
128
|
+
switch (_b.label) {
|
|
129
|
+
case 0:
|
|
130
|
+
if (!e.data.size)
|
|
131
|
+
return [2 /*return*/];
|
|
132
|
+
if (this.mediaType !== 'audio')
|
|
133
|
+
return [2 /*return*/];
|
|
134
|
+
_b.label = 1;
|
|
135
|
+
case 1:
|
|
136
|
+
_b.trys.push([1, 3, , 4]);
|
|
137
|
+
this.recordedData.push(e.data);
|
|
138
|
+
return [4 /*yield*/, this.makeVoiceRecording()];
|
|
139
|
+
case 2:
|
|
140
|
+
recording = _b.sent();
|
|
141
|
+
if (!recording)
|
|
142
|
+
return [2 /*return*/];
|
|
143
|
+
(_a = this.signalRecordingReady) === null || _a === void 0 ? void 0 : _a.call(this, recording);
|
|
144
|
+
this.recording.next(recording);
|
|
145
|
+
return [3 /*break*/, 4];
|
|
146
|
+
case 3:
|
|
147
|
+
e_1 = _b.sent();
|
|
148
|
+
logError(e_1);
|
|
149
|
+
this.error.next(e_1);
|
|
150
|
+
this.notification.next({
|
|
151
|
+
text: this.t('An error has occurred during the recording processing'),
|
|
152
|
+
type: 'error',
|
|
153
|
+
});
|
|
154
|
+
return [3 /*break*/, 4];
|
|
155
|
+
case 4: return [2 /*return*/];
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
}); };
|
|
159
|
+
this.resetRecordingState = function () {
|
|
160
|
+
_this.recordedData = [];
|
|
161
|
+
_this.recording.next(undefined);
|
|
162
|
+
_this.recordingState.next(undefined);
|
|
163
|
+
_this.recordedChunkDurations = [];
|
|
164
|
+
_this.startTime = undefined;
|
|
165
|
+
};
|
|
166
|
+
this.cleanUp = function () {
|
|
167
|
+
var _a;
|
|
168
|
+
_this.resetRecordingState();
|
|
169
|
+
if (_this.recordingUri)
|
|
170
|
+
URL.revokeObjectURL(_this.recordingUri);
|
|
171
|
+
(_a = _this.amplitudeRecorder) === null || _a === void 0 ? void 0 : _a.close();
|
|
172
|
+
if (_this.mediaRecorder) {
|
|
173
|
+
disposeOfMediaStream(_this.mediaRecorder.stream);
|
|
174
|
+
_this.mediaRecorder.removeEventListener('dataavailable', _this.handleDataavailableEvent);
|
|
175
|
+
_this.mediaRecorder.removeEventListener('error', _this.handleErrorEvent);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
this.start = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
179
|
+
var error, error, error, stream, error_1;
|
|
180
|
+
return __generator(this, function (_a) {
|
|
181
|
+
switch (_a.label) {
|
|
182
|
+
case 0:
|
|
183
|
+
if ([MediaRecordingState.RECORDING, MediaRecordingState.PAUSED].includes(this.recordingState.value)) {
|
|
184
|
+
error = new Error('Cannot start recording. Recording already in progress');
|
|
185
|
+
logError(error);
|
|
186
|
+
this.error.next(error);
|
|
187
|
+
return [2 /*return*/];
|
|
188
|
+
}
|
|
189
|
+
// account for requirement on iOS as per this bug report: https://bugs.webkit.org/show_bug.cgi?id=252303
|
|
190
|
+
if (!navigator.mediaDevices) {
|
|
191
|
+
error = new Error('Media recording is not supported');
|
|
192
|
+
logError(error);
|
|
193
|
+
this.error.next(error);
|
|
194
|
+
this.notification.next({ text: this.t('Error starting recording'), type: 'error' });
|
|
195
|
+
return [2 /*return*/];
|
|
196
|
+
}
|
|
197
|
+
if (this.mediaType === 'video') {
|
|
198
|
+
error = new Error("Video recording is not supported. Provided MIME type: ".concat(this.mediaRecorderConfig.mimeType));
|
|
199
|
+
logError(error);
|
|
200
|
+
this.error.next(error);
|
|
201
|
+
this.notification.next({ text: this.t('Error starting recording'), type: 'error' });
|
|
202
|
+
return [2 /*return*/];
|
|
203
|
+
}
|
|
204
|
+
if (!!this.permission.state.value) return [3 /*break*/, 2];
|
|
205
|
+
return [4 /*yield*/, this.permission.check()];
|
|
206
|
+
case 1:
|
|
207
|
+
_a.sent();
|
|
208
|
+
_a.label = 2;
|
|
209
|
+
case 2:
|
|
210
|
+
if (this.permission.state.value === 'denied') {
|
|
211
|
+
logError(new Error('Permission denied'));
|
|
212
|
+
return [2 /*return*/];
|
|
213
|
+
}
|
|
214
|
+
_a.label = 3;
|
|
215
|
+
case 3:
|
|
216
|
+
_a.trys.push([3, 5, , 6]);
|
|
217
|
+
return [4 /*yield*/, navigator.mediaDevices.getUserMedia({ audio: true })];
|
|
218
|
+
case 4:
|
|
219
|
+
stream = _a.sent();
|
|
220
|
+
this.mediaRecorder = new MediaRecorder(stream, this.mediaRecorderConfig);
|
|
221
|
+
this.mediaRecorder.addEventListener('dataavailable', this.handleDataavailableEvent);
|
|
222
|
+
this.mediaRecorder.addEventListener('error', this.handleErrorEvent);
|
|
223
|
+
this.startTime = new Date().getTime();
|
|
224
|
+
this.mediaRecorder.start();
|
|
225
|
+
if (this.mediaType === 'audio' && stream) {
|
|
226
|
+
this.amplitudeRecorder = new AmplitudeRecorder({
|
|
227
|
+
config: this.amplitudeRecorderConfig,
|
|
228
|
+
stream: stream,
|
|
229
|
+
});
|
|
230
|
+
this.amplitudeRecorder.start();
|
|
231
|
+
}
|
|
232
|
+
this.recordingState.next(MediaRecordingState.RECORDING);
|
|
233
|
+
return [3 /*break*/, 6];
|
|
234
|
+
case 5:
|
|
235
|
+
error_1 = _a.sent();
|
|
236
|
+
logError(error_1);
|
|
237
|
+
this.cancel();
|
|
238
|
+
this.error.next(error_1);
|
|
239
|
+
this.notification.next({ text: this.t('Error starting recording'), type: 'error' });
|
|
240
|
+
return [3 /*break*/, 6];
|
|
241
|
+
case 6: return [2 /*return*/];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
}); };
|
|
245
|
+
this.pause = function () {
|
|
246
|
+
var _a, _b;
|
|
247
|
+
if (_this.recordingState.value !== MediaRecordingState.RECORDING)
|
|
248
|
+
return;
|
|
249
|
+
if (_this.startTime) {
|
|
250
|
+
_this.recordedChunkDurations.push(new Date().getTime() - _this.startTime);
|
|
251
|
+
_this.startTime = undefined;
|
|
252
|
+
}
|
|
253
|
+
(_a = _this.mediaRecorder) === null || _a === void 0 ? void 0 : _a.pause();
|
|
254
|
+
(_b = _this.amplitudeRecorder) === null || _b === void 0 ? void 0 : _b.stop();
|
|
255
|
+
_this.recordingState.next(MediaRecordingState.PAUSED);
|
|
256
|
+
};
|
|
257
|
+
this.resume = function () {
|
|
258
|
+
var _a, _b;
|
|
259
|
+
if (_this.recordingState.value !== MediaRecordingState.PAUSED)
|
|
260
|
+
return;
|
|
261
|
+
_this.startTime = new Date().getTime();
|
|
262
|
+
(_a = _this.mediaRecorder) === null || _a === void 0 ? void 0 : _a.resume();
|
|
263
|
+
(_b = _this.amplitudeRecorder) === null || _b === void 0 ? void 0 : _b.start();
|
|
264
|
+
_this.recordingState.next(MediaRecordingState.RECORDING);
|
|
265
|
+
};
|
|
266
|
+
this.stop = function () {
|
|
267
|
+
var _a, _b, _c;
|
|
268
|
+
var recording = _this.recording.value;
|
|
269
|
+
if (recording)
|
|
270
|
+
return Promise.resolve(recording);
|
|
271
|
+
if (![MediaRecordingState.PAUSED, MediaRecordingState.RECORDING].includes((((_a = _this.mediaRecorder) === null || _a === void 0 ? void 0 : _a.state) || '')))
|
|
272
|
+
return Promise.resolve(undefined);
|
|
273
|
+
if (_this.startTime) {
|
|
274
|
+
_this.recordedChunkDurations.push(new Date().getTime() - _this.startTime);
|
|
275
|
+
_this.startTime = undefined;
|
|
276
|
+
}
|
|
277
|
+
var result = new Promise(function (res) {
|
|
278
|
+
_this.signalRecordingReady = res;
|
|
279
|
+
});
|
|
280
|
+
(_b = _this.mediaRecorder) === null || _b === void 0 ? void 0 : _b.stop();
|
|
281
|
+
(_c = _this.amplitudeRecorder) === null || _c === void 0 ? void 0 : _c.stop();
|
|
282
|
+
_this.recordingState.next(MediaRecordingState.STOPPED);
|
|
283
|
+
return result;
|
|
284
|
+
};
|
|
285
|
+
this.cancel = function () {
|
|
286
|
+
_this.stop();
|
|
287
|
+
_this.cleanUp();
|
|
288
|
+
};
|
|
289
|
+
this.t = t || defaultTranslatorFunction;
|
|
290
|
+
this.amplitudeRecorderConfig = mergeDeepUndefined(__assign({}, config === null || config === void 0 ? void 0 : config.amplitudeRecorderConfig), DEFAULT_AMPLITUDE_RECORDER_CONFIG);
|
|
291
|
+
this.mediaRecorderConfig = mergeDeepUndefined(__assign({}, config === null || config === void 0 ? void 0 : config.mediaRecorderConfig), DEFAULT_MEDIA_RECORDER_CONFIG);
|
|
292
|
+
this.transcoderConfig = mergeDeepUndefined(__assign({}, config === null || config === void 0 ? void 0 : config.transcoderConfig), DEFAULT_AUDIO_TRANSCODER_CONFIG);
|
|
293
|
+
if (!POSSIBLE_TRANSCODING_MIME_TYPES.includes(this.transcoderConfig.targetMimeType)) {
|
|
294
|
+
this.transcoderConfig.targetMimeType = DEFAULT_AUDIO_TRANSCODER_CONFIG.targetMimeType;
|
|
295
|
+
}
|
|
296
|
+
var mediaType = getRecordedMediaTypeFromMimeType(this.mediaRecorderConfig.mimeType);
|
|
297
|
+
if (!mediaType) {
|
|
298
|
+
throw new Error("Unsupported media type (supported audio or video only). Provided mimeType: ".concat(this.mediaRecorderConfig.mimeType));
|
|
299
|
+
}
|
|
300
|
+
this.mediaType = mediaType;
|
|
301
|
+
this.permission = new BrowserPermission({ mediaType: mediaType });
|
|
302
|
+
this.customGenerateRecordingTitle = generateRecordingTitle;
|
|
303
|
+
}
|
|
304
|
+
Object.defineProperty(MediaRecorderController.prototype, "durationMs", {
|
|
305
|
+
get: function () {
|
|
306
|
+
return this.recordedChunkDurations.reduce(function (acc, val) { return acc + val; }, 0);
|
|
307
|
+
},
|
|
308
|
+
enumerable: false,
|
|
309
|
+
configurable: true
|
|
310
|
+
});
|
|
311
|
+
return MediaRecorderController;
|
|
312
|
+
}());
|
|
313
|
+
export { MediaRecorderController };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/MediaRecorder/classes/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,YAAY,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/MediaRecorder/hooks/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { MessageInputContextValue } from '../../../context';
|
|
2
|
+
import { AudioRecorderConfig, MediaRecorderController, MediaRecordingState } from '../classes';
|
|
3
|
+
import type { LocalVoiceRecordingAttachment } from '../../MessageInput';
|
|
4
|
+
import type { DefaultStreamChatGenerics } from '../../../types';
|
|
5
|
+
export type CustomAudioRecordingConfig = Partial<AudioRecorderConfig>;
|
|
6
|
+
export type RecordingController = {
|
|
7
|
+
completeRecording: () => void;
|
|
8
|
+
permissionState?: PermissionState;
|
|
9
|
+
recorder?: MediaRecorderController;
|
|
10
|
+
recording?: LocalVoiceRecordingAttachment;
|
|
11
|
+
recordingState?: MediaRecordingState;
|
|
12
|
+
};
|
|
13
|
+
type UseMediaRecorderParams<StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics> = Pick<MessageInputContextValue<StreamChatGenerics>, 'asyncMessagesMultiSendEnabled' | 'handleSubmit' | 'uploadAttachment'> & {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
generateRecordingTitle?: (mimeType: string) => string;
|
|
16
|
+
recordingConfig?: CustomAudioRecordingConfig;
|
|
17
|
+
};
|
|
18
|
+
export declare const useMediaRecorder: <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics>({ asyncMessagesMultiSendEnabled, enabled, generateRecordingTitle, handleSubmit, recordingConfig, uploadAttachment, }: UseMediaRecorderParams<StreamChatGenerics>) => RecordingController;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=useMediaRecorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMediaRecorder.d.ts","sourceRoot":"","sources":["../../../../src/components/MediaRecorder/hooks/useMediaRecorder.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAyB,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAEhE,MAAM,MAAM,0BAA0B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAEtE,MAAM,MAAM,mBAAmB,GAAG;IAChC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,EAAE,uBAAuB,CAAC;IACnC,SAAS,CAAC,EAAE,6BAA6B,CAAC;IAC1C,cAAc,CAAC,EAAE,mBAAmB,CAAC;CACtC,CAAC;AAEF,KAAK,sBAAsB,CACzB,kBAAkB,SAAS,yBAAyB,GAAG,yBAAyB,IAC9E,IAAI,CACN,wBAAwB,CAAC,kBAAkB,CAAC,EAC5C,+BAA+B,GAAG,cAAc,GAAG,kBAAkB,CACtE,GAAG;IACF,OAAO,EAAE,OAAO,CAAC;IACjB,sBAAsB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IACtD,eAAe,CAAC,EAAE,0BAA0B,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,gBAAgB,0PASmB,mBA6D/C,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { __awaiter, __generator } from "tslib";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { useTranslationContext } from '../../../context';
|
|
4
|
+
import { MediaRecorderController } from '../classes';
|
|
5
|
+
export var useMediaRecorder = function (_a) {
|
|
6
|
+
var asyncMessagesMultiSendEnabled = _a.asyncMessagesMultiSendEnabled, enabled = _a.enabled, generateRecordingTitle = _a.generateRecordingTitle, handleSubmit = _a.handleSubmit, recordingConfig = _a.recordingConfig, uploadAttachment = _a.uploadAttachment;
|
|
7
|
+
var t = useTranslationContext('useMediaRecorder').t;
|
|
8
|
+
var _b = useState(), recording = _b[0], setRecording = _b[1];
|
|
9
|
+
var _c = useState(), recordingState = _c[0], setRecordingState = _c[1];
|
|
10
|
+
var _d = useState(), permissionState = _d[0], setPermissionState = _d[1];
|
|
11
|
+
var _e = useState(false), isScheduledForSubmit = _e[0], scheduleForSubmit = _e[1];
|
|
12
|
+
var recorder = useMemo(function () {
|
|
13
|
+
return enabled
|
|
14
|
+
? new MediaRecorderController({
|
|
15
|
+
config: recordingConfig !== null && recordingConfig !== void 0 ? recordingConfig : {},
|
|
16
|
+
generateRecordingTitle: generateRecordingTitle,
|
|
17
|
+
t: t,
|
|
18
|
+
})
|
|
19
|
+
: undefined;
|
|
20
|
+
}, [recordingConfig, enabled, generateRecordingTitle, t]);
|
|
21
|
+
var completeRecording = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
22
|
+
var recording;
|
|
23
|
+
return __generator(this, function (_a) {
|
|
24
|
+
switch (_a.label) {
|
|
25
|
+
case 0:
|
|
26
|
+
if (!recorder)
|
|
27
|
+
return [2 /*return*/];
|
|
28
|
+
return [4 /*yield*/, recorder.stop()];
|
|
29
|
+
case 1:
|
|
30
|
+
recording = _a.sent();
|
|
31
|
+
if (!recording)
|
|
32
|
+
return [2 /*return*/];
|
|
33
|
+
return [4 /*yield*/, uploadAttachment(recording)];
|
|
34
|
+
case 2:
|
|
35
|
+
_a.sent();
|
|
36
|
+
if (!asyncMessagesMultiSendEnabled) {
|
|
37
|
+
// FIXME: cannot call handleSubmit() directly as the function has stale reference to attachments
|
|
38
|
+
scheduleForSubmit(true);
|
|
39
|
+
}
|
|
40
|
+
recorder.cleanUp();
|
|
41
|
+
return [2 /*return*/];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}); }, [asyncMessagesMultiSendEnabled, recorder, uploadAttachment]);
|
|
45
|
+
useEffect(function () {
|
|
46
|
+
if (!isScheduledForSubmit)
|
|
47
|
+
return;
|
|
48
|
+
handleSubmit();
|
|
49
|
+
scheduleForSubmit(false);
|
|
50
|
+
}, [handleSubmit, isScheduledForSubmit]);
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
if (!recorder)
|
|
53
|
+
return;
|
|
54
|
+
recorder.permission.watch();
|
|
55
|
+
var recordingSubscription = recorder.recording.subscribe(setRecording);
|
|
56
|
+
var recordingStateSubscription = recorder.recordingState.subscribe(setRecordingState);
|
|
57
|
+
var permissionStateSubscription = recorder.permission.state.subscribe(setPermissionState);
|
|
58
|
+
return function () {
|
|
59
|
+
recorder.cancel();
|
|
60
|
+
recorder.permission.unwatch();
|
|
61
|
+
recordingSubscription.unsubscribe();
|
|
62
|
+
recordingStateSubscription.unsubscribe();
|
|
63
|
+
permissionStateSubscription.unsubscribe();
|
|
64
|
+
};
|
|
65
|
+
}, [recorder]);
|
|
66
|
+
return {
|
|
67
|
+
completeRecording: completeRecording,
|
|
68
|
+
permissionState: permissionState,
|
|
69
|
+
recorder: recorder,
|
|
70
|
+
recording: recording,
|
|
71
|
+
recordingState: recordingState,
|
|
72
|
+
};
|
|
73
|
+
};
|