merge devel

This commit is contained in:
or-else
2023-04-14 19:34:27 -07:00
28 changed files with 185 additions and 114 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+7
View File
@@ -1648,6 +1648,13 @@
"missing": false, "missing": false,
"obsolete": false "obsolete": false
}, },
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
},
"pin_message": { "pin_message": {
"translation": "", "translation": "",
"defaultMessage": "Pin", "defaultMessage": "Pin",
+7
View File
@@ -1648,6 +1648,13 @@
"missing": false, "missing": false,
"obsolete": false "obsolete": false
}, },
"failed_to_init_audio": {
"translation": "Failed to initialize audio recording",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": false,
"obsolete": false
},
"pin_message": { "pin_message": {
"translation": "Pin", "translation": "Pin",
"defaultMessage": "Pin", "defaultMessage": "Pin",
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+4
View File
@@ -291,6 +291,10 @@
"defaultMessage": "Invalid ID", "defaultMessage": "Invalid ID",
"description": "Error message" "description": "Error message"
}, },
"failed_to_init_audio": {
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available"
},
"file_attachment_too_large": { "file_attachment_too_large": {
"defaultMessage": "The file size {size} exceeds the {limit} limit.", "defaultMessage": "The file size {size} exceeds the {limit} limit.",
"description": "Error message when attachment is too large" "description": "Error message when attachment is too large"
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+7
View File
@@ -1661,5 +1661,12 @@
"description": "Menu item [Unpin] for un-pinning the message.", "description": "Menu item [Unpin] for un-pinning the message.",
"missing": true, "missing": true,
"obsolete": false "obsolete": false
},
"failed_to_init_audio": {
"translation": "",
"defaultMessage": "Failed to initialize audio recording",
"description": "Error message when audio is not available",
"missing": true,
"obsolete": false
} }
} }
+2 -1
View File
@@ -431,7 +431,7 @@ class TinodeWeb extends React.Component {
}).then(token => { }).then(token => {
if (token) { if (token) {
return token; return token;
} else { } else if (typeof Notification != 'undefined') {
// Try to request permissions. // Try to request permissions.
return Notification.requestPermission().then(permission => { return Notification.requestPermission().then(permission => {
if (permission === 'granted') { if (permission === 'granted') {
@@ -450,6 +450,7 @@ class TinodeWeb extends React.Component {
} }
}); });
} }
throw new Error("Notifications are not supported");
}); });
} }
+6 -5
View File
@@ -70,7 +70,7 @@ class AudioPlayer extends React.PureComponent {
componentWillUnmount() { componentWillUnmount() {
if (this.audioPlayer) { if (this.audioPlayer) {
this.audioPlayer.oncanplay = null; this.audioPlayer.onloadedmetadata = null;
this.audioPlayer.ontimeupdate = null; this.audioPlayer.ontimeupdate = null;
this.audioPlayer.onended = null; this.audioPlayer.onended = null;
this.audioPlayer.pause(); this.audioPlayer.pause();
@@ -94,7 +94,7 @@ class AudioPlayer extends React.PureComponent {
initAudio() { initAudio() {
this.audioPlayer = new Audio(this.props.src); this.audioPlayer = new Audio(this.props.src);
this.audioPlayer.oncanplay = _ => this.setState({canPlay: true}); this.audioPlayer.onloadedmetadata = _ => this.setState({canPlay: true});
this.audioPlayer.ontimeupdate = _ => this.setState({ this.audioPlayer.ontimeupdate = _ => this.setState({
currentTime: secondsToTime(this.audioPlayer.currentTime, this.state.longMin) currentTime: secondsToTime(this.audioPlayer.currentTime, this.state.longMin)
}); });
@@ -149,7 +149,7 @@ class AudioPlayer extends React.PureComponent {
this.canvasContext.strokeStyle = BAR_COLOR_DARK; this.canvasContext.strokeStyle = BAR_COLOR_DARK;
for (let i = 0; i < this.viewBuffer.length; i++) { for (let i = 0; i < this.viewBuffer.length; i++) {
let x = 1 + i * (LINE_WIDTH + SPACING) + LINE_WIDTH * 0.5; let x = 1 + i * (LINE_WIDTH + SPACING) + LINE_WIDTH * 0.5;
let y = this.viewBuffer[i] * height * 0.9; let y = Math.max(this.viewBuffer[i] * height * 0.9, 1);
const color = x < thumbAt ? BAR_COLOR_DARK : BAR_COLOR; const color = x < thumbAt ? BAR_COLOR_DARK : BAR_COLOR;
if (this.canvasContext.strokeStyle != color) { if (this.canvasContext.strokeStyle != color) {
@@ -159,7 +159,7 @@ class AudioPlayer extends React.PureComponent {
} }
this.canvasContext.moveTo(x, (height - y) * 0.5); this.canvasContext.moveTo(x, (height - y) * 0.5);
this.canvasContext.lineTo(x, height * 0.5 + y * 0.5); this.canvasContext.lineTo(x, (height + y) * 0.5);
} }
// Actually draw the bars on canvas. // Actually draw the bars on canvas.
this.canvasContext.stroke(); this.canvasContext.stroke();
@@ -216,10 +216,11 @@ class AudioPlayer extends React.PureComponent {
if (!this.state.canPlay) { if (!this.state.canPlay) {
return; return;
} }
if (this.state.playing) { if (this.state.playing) {
this.audioPlayer.pause(); this.audioPlayer.pause();
this.setState({playing: false}); this.setState({playing: false});
} else { } else if (this.audioPlayer.readyState >= 2) {
this.audioPlayer.play(); this.audioPlayer.play();
this.setState({playing: true}, this.visualize); this.setState({playing: true}, this.visualize);
} }
+39 -8
View File
@@ -31,8 +31,11 @@ const VISUALIZATION_BARS = 96;
// Maximum number of samples per bar. // Maximum number of samples per bar.
const MAX_SAMPLES_PER_BAR = 10; const MAX_SAMPLES_PER_BAR = 10;
// Recording format. // Default recording format (FF, Chrome except on iOS).
const AUDIO_MIME_TYPE = 'audio/webm'; const DEFAULT_AUDIO_MIME_TYPE = 'audio/webm';
// Safari supports only mp4 as audio recording format.
const SAFARI_AUDIO_MIME_TYPE = 'audio/mp4';
const AUDIO_MIME_TYPES = [DEFAULT_AUDIO_MIME_TYPE, SAFARI_AUDIO_MIME_TYPE, ''];
const messages = defineMessages({ const messages = defineMessages({
icon_title_delete: { icon_title_delete: {
@@ -55,6 +58,11 @@ const messages = defineMessages({
defaultMessage: 'Send message', defaultMessage: 'Send message',
description: 'Icon tool tip for sending a message' description: 'Icon tool tip for sending a message'
}, },
failed_to_init_audio: {
id: 'failed_to_init_audio',
defaultMessage: 'Failed to initialize audio recording',
description: 'Error message when audio is not available'
}
}); });
class AudioRecorder extends React.PureComponent { class AudioRecorder extends React.PureComponent {
@@ -188,10 +196,10 @@ class AudioRecorder extends React.PureComponent {
this.canvasContext.beginPath(); this.canvasContext.beginPath();
for (let i = 0; i < this.viewBuffer.length; i++) { for (let i = 0; i < this.viewBuffer.length; i++) {
let x = i * (LINE_WIDTH + SPACING) - dx; let x = i * (LINE_WIDTH + SPACING) - dx;
let y = Math.min(this.viewBuffer[i] / BAR_SCALE, 0.9) * height; let y = Math.max(Math.min(this.viewBuffer[i] / BAR_SCALE, 0.9) * height, 1);
this.canvasContext.moveTo(x, (height - y) * 0.5); this.canvasContext.moveTo(x, (height - y) * 0.5);
this.canvasContext.lineTo(x, height * 0.5 + y * 0.5); this.canvasContext.lineTo(x, (height + y) * 0.5);
} }
// Actually draw the bars on canvas. // Actually draw the bars on canvas.
this.canvasContext.stroke(); this.canvasContext.stroke();
@@ -261,11 +269,29 @@ class AudioRecorder extends React.PureComponent {
initMediaRecording(stream) { initMediaRecording(stream) {
this.stream = stream; this.stream = stream;
this.mediaRecorder = new MediaRecorder(stream, {mimeType: AUDIO_MIME_TYPE, audioBitsPerSecond: 24_000}); AUDIO_MIME_TYPES.some(mimeType => {
if (MediaRecorder.isTypeSupported(mimeType)) {
this.mediaRecorder = new MediaRecorder(stream, {mimeType: mimeType, audioBitsPerSecond: 24_000});
return true;
}
return false;
});
if (!this.mediaRecorder) {
console.warn('MediaRecorder failed to initialize: no supported audio formats');
this.props.onError(this.props.intl.formatMessage(messages.failed_to_init_audio));
return;
}
// The following code is needed for visualization. // The following code is needed for visualization.
this.audioContext = new AudioContext(); this.audioContext = new AudioContext();
this.audioInput = this.audioContext.createMediaStreamSource(stream); this.audioInput = this.audioContext.createMediaStreamSource(stream);
if (!this.audioInput) {
console.warn('createMediaStreamSource returned null: audio input unavailable');
this.props.onError(this.props.intl.formatMessage(messages.failed_to_init_audio));
return;
}
this.analyser = this.audioContext.createAnalyser(); this.analyser = this.audioContext.createAnalyser();
this.analyser.fftSize = BUFFER_SIZE; this.analyser.fftSize = BUFFER_SIZE;
this.audioInput.connect(this.analyser); this.audioInput.connect(this.analyser);
@@ -305,11 +331,14 @@ class AudioRecorder extends React.PureComponent {
} }
// Obtain data in a form sutable for sending or playing back. // Obtain data in a form sutable for sending or playing back.
// If duration is valid, apply fix for Chrome's WebM duration bug.
getRecording(mimeType) { getRecording(mimeType) {
mimeType = mimeType || AUDIO_MIME_TYPE; mimeType = mimeType || DEFAULT_AUDIO_MIME_TYPE;
let blob = new Blob(this.audioChunks, {type: mimeType}); let blob = new Blob(this.audioChunks, {type: mimeType});
return fixWebmDuration(blob, mimeType) // If duration is valid, apply fix for Chrome's WebM duration bug.
const result = mimeType == DEFAULT_AUDIO_MIME_TYPE ?
fixWebmDuration(blob, mimeType) :
Promise.resolve(blob);
return result
.then(fixedBlob => { blob = fixedBlob; return fixedBlob.arrayBuffer(); }) .then(fixedBlob => { blob = fixedBlob; return fixedBlob.arrayBuffer(); })
.then(arrayBuff => this.audioContext.decodeAudioData(arrayBuff)) .then(arrayBuff => this.audioContext.decodeAudioData(arrayBuff))
.then(decoded => this.createPreview(decoded)) .then(decoded => this.createPreview(decoded))
@@ -347,7 +376,9 @@ class AudioRecorder extends React.PureComponent {
} }
cleanUp() { cleanUp() {
if (this.audioInput) {
this.audioInput.disconnect(); this.audioInput.disconnect();
}
this.stream.getTracks().forEach(track => track.stop()); this.stream.getTracks().forEach(track => track.stop());
} }
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+7 -6
View File
@@ -7657,7 +7657,7 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
}).then(token => { }).then(token => {
if (token) { if (token) {
return token; return token;
} else { } else if (typeof Notification != 'undefined') {
return Notification.requestPermission().then(permission => { return Notification.requestPermission().then(permission => {
if (permission === 'granted') { if (permission === 'granted') {
return (0,firebase_messaging__WEBPACK_IMPORTED_MODULE_3__.getToken)(fcm, { return (0,firebase_messaging__WEBPACK_IMPORTED_MODULE_3__.getToken)(fcm, {
@@ -7675,6 +7675,7 @@ class TinodeWeb extends (react__WEBPACK_IMPORTED_MODULE_0___default().Component)
} }
}); });
} }
throw new Error("Notifications are not supported");
}); });
} }
handleResize() { handleResize() {
@@ -9637,7 +9638,7 @@ class AudioPlayer extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComp
} }
componentWillUnmount() { componentWillUnmount() {
if (this.audioPlayer) { if (this.audioPlayer) {
this.audioPlayer.oncanplay = null; this.audioPlayer.onloadedmetadata = null;
this.audioPlayer.ontimeupdate = null; this.audioPlayer.ontimeupdate = null;
this.audioPlayer.onended = null; this.audioPlayer.onended = null;
this.audioPlayer.pause(); this.audioPlayer.pause();
@@ -9660,7 +9661,7 @@ class AudioPlayer extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComp
} }
initAudio() { initAudio() {
this.audioPlayer = new Audio(this.props.src); this.audioPlayer = new Audio(this.props.src);
this.audioPlayer.oncanplay = _ => this.setState({ this.audioPlayer.onloadedmetadata = _ => this.setState({
canPlay: true canPlay: true
}); });
this.audioPlayer.ontimeupdate = _ => this.setState({ this.audioPlayer.ontimeupdate = _ => this.setState({
@@ -9703,7 +9704,7 @@ class AudioPlayer extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComp
this.canvasContext.strokeStyle = BAR_COLOR_DARK; this.canvasContext.strokeStyle = BAR_COLOR_DARK;
for (let i = 0; i < this.viewBuffer.length; i++) { for (let i = 0; i < this.viewBuffer.length; i++) {
let x = 1 + i * (LINE_WIDTH + SPACING) + LINE_WIDTH * 0.5; let x = 1 + i * (LINE_WIDTH + SPACING) + LINE_WIDTH * 0.5;
let y = this.viewBuffer[i] * height * 0.9; let y = Math.max(this.viewBuffer[i] * height * 0.9, 1);
const color = x < thumbAt ? BAR_COLOR_DARK : BAR_COLOR; const color = x < thumbAt ? BAR_COLOR_DARK : BAR_COLOR;
if (this.canvasContext.strokeStyle != color) { if (this.canvasContext.strokeStyle != color) {
this.canvasContext.stroke(); this.canvasContext.stroke();
@@ -9711,7 +9712,7 @@ class AudioPlayer extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComp
this.canvasContext.strokeStyle = color; this.canvasContext.strokeStyle = color;
} }
this.canvasContext.moveTo(x, (height - y) * 0.5); this.canvasContext.moveTo(x, (height - y) * 0.5);
this.canvasContext.lineTo(x, height * 0.5 + y * 0.5); this.canvasContext.lineTo(x, (height + y) * 0.5);
} }
this.canvasContext.stroke(); this.canvasContext.stroke();
if (this.props.duration) { if (this.props.duration) {
@@ -9762,7 +9763,7 @@ class AudioPlayer extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComp
this.setState({ this.setState({
playing: false playing: false
}); });
} else { } else if (this.audioPlayer.readyState >= 2) {
this.audioPlayer.play(); this.audioPlayer.play();
this.setState({ this.setState({
playing: true playing: true
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+34 -6
View File
@@ -37,7 +37,9 @@ const BAR_COLOR = '#BBBD';
const BAR_SCALE = 64.0; const BAR_SCALE = 64.0;
const VISUALIZATION_BARS = 96; const VISUALIZATION_BARS = 96;
const MAX_SAMPLES_PER_BAR = 10; const MAX_SAMPLES_PER_BAR = 10;
const AUDIO_MIME_TYPE = 'audio/webm'; const DEFAULT_AUDIO_MIME_TYPE = 'audio/webm';
const SAFARI_AUDIO_MIME_TYPE = 'audio/mp4';
const AUDIO_MIME_TYPES = [DEFAULT_AUDIO_MIME_TYPE, SAFARI_AUDIO_MIME_TYPE, ''];
const messages = (0,react_intl__WEBPACK_IMPORTED_MODULE_1__.defineMessages)({ const messages = (0,react_intl__WEBPACK_IMPORTED_MODULE_1__.defineMessages)({
icon_title_delete: { icon_title_delete: {
id: "icon_title_delete", id: "icon_title_delete",
@@ -66,6 +68,13 @@ const messages = (0,react_intl__WEBPACK_IMPORTED_MODULE_1__.defineMessages)({
"type": 0, "type": 0,
"value": "Send message" "value": "Send message"
}] }]
},
failed_to_init_audio: {
id: "failed_to_init_audio",
defaultMessage: [{
"type": 0,
"value": "Failed to initialize audio recording"
}]
} }
}); });
class AudioRecorder extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComponent) { class AudioRecorder extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureComponent) {
@@ -170,9 +179,9 @@ class AudioRecorder extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureCo
this.canvasContext.beginPath(); this.canvasContext.beginPath();
for (let i = 0; i < this.viewBuffer.length; i++) { for (let i = 0; i < this.viewBuffer.length; i++) {
let x = i * (LINE_WIDTH + SPACING) - dx; let x = i * (LINE_WIDTH + SPACING) - dx;
let y = Math.min(this.viewBuffer[i] / BAR_SCALE, 0.9) * height; let y = Math.max(Math.min(this.viewBuffer[i] / BAR_SCALE, 0.9) * height, 1);
this.canvasContext.moveTo(x, (height - y) * 0.5); this.canvasContext.moveTo(x, (height - y) * 0.5);
this.canvasContext.lineTo(x, height * 0.5 + y * 0.5); this.canvasContext.lineTo(x, (height + y) * 0.5);
} }
this.canvasContext.stroke(); this.canvasContext.stroke();
const now = new Date().getTime(); const now = new Date().getTime();
@@ -237,12 +246,28 @@ class AudioRecorder extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureCo
} }
initMediaRecording(stream) { initMediaRecording(stream) {
this.stream = stream; this.stream = stream;
AUDIO_MIME_TYPES.some(mimeType => {
if (MediaRecorder.isTypeSupported(mimeType)) {
this.mediaRecorder = new MediaRecorder(stream, { this.mediaRecorder = new MediaRecorder(stream, {
mimeType: AUDIO_MIME_TYPE, mimeType: mimeType,
audioBitsPerSecond: 24_000 audioBitsPerSecond: 24_000
}); });
return true;
}
return false;
});
if (!this.mediaRecorder) {
console.warn('MediaRecorder failed to initialize: no supported audio formats');
this.props.onError(this.props.intl.formatMessage(messages.failed_to_init_audio));
return;
}
this.audioContext = new AudioContext(); this.audioContext = new AudioContext();
this.audioInput = this.audioContext.createMediaStreamSource(stream); this.audioInput = this.audioContext.createMediaStreamSource(stream);
if (!this.audioInput) {
console.warn('createMediaStreamSource returned null: audio input unavailable');
this.props.onError(this.props.intl.formatMessage(messages.failed_to_init_audio));
return;
}
this.analyser = this.audioContext.createAnalyser(); this.analyser = this.audioContext.createAnalyser();
this.analyser.fftSize = BUFFER_SIZE; this.analyser.fftSize = BUFFER_SIZE;
this.audioInput.connect(this.analyser); this.audioInput.connect(this.analyser);
@@ -275,11 +300,12 @@ class AudioRecorder extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureCo
this.recordingTimestamp = this.startedOn; this.recordingTimestamp = this.startedOn;
} }
getRecording(mimeType) { getRecording(mimeType) {
mimeType = mimeType || AUDIO_MIME_TYPE; mimeType = mimeType || DEFAULT_AUDIO_MIME_TYPE;
let blob = new Blob(this.audioChunks, { let blob = new Blob(this.audioChunks, {
type: mimeType type: mimeType
}); });
return webm_duration_fix__WEBPACK_IMPORTED_MODULE_3___default()(blob, mimeType).then(fixedBlob => { const result = mimeType == DEFAULT_AUDIO_MIME_TYPE ? webm_duration_fix__WEBPACK_IMPORTED_MODULE_3___default()(blob, mimeType) : Promise.resolve(blob);
return result.then(fixedBlob => {
blob = fixedBlob; blob = fixedBlob;
return fixedBlob.arrayBuffer(); return fixedBlob.arrayBuffer();
}).then(arrayBuff => this.audioContext.decodeAudioData(arrayBuff)).then(decoded => this.createPreview(decoded)).then(preview => ({ }).then(arrayBuff => this.audioContext.decodeAudioData(arrayBuff)).then(decoded => this.createPreview(decoded)).then(preview => ({
@@ -311,7 +337,9 @@ class AudioRecorder extends (react__WEBPACK_IMPORTED_MODULE_0___default().PureCo
return buffer; return buffer;
} }
cleanUp() { cleanUp() {
if (this.audioInput) {
this.audioInput.disconnect(); this.audioInput.disconnect();
}
this.stream.getTracks().forEach(track => track.stop()); this.stream.getTracks().forEach(track => track.stop());
} }
render() { render() {
File diff suppressed because one or more lines are too long
+14 -72
View File
@@ -410,7 +410,6 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ "EXPIRE_PROMISES_TIMEOUT": () => (/* binding */ EXPIRE_PROMISES_TIMEOUT), /* harmony export */ "EXPIRE_PROMISES_TIMEOUT": () => (/* binding */ EXPIRE_PROMISES_TIMEOUT),
/* harmony export */ "LIBRARY": () => (/* binding */ LIBRARY), /* harmony export */ "LIBRARY": () => (/* binding */ LIBRARY),
/* harmony export */ "LOCAL_SEQID": () => (/* binding */ LOCAL_SEQID), /* harmony export */ "LOCAL_SEQID": () => (/* binding */ LOCAL_SEQID),
/* harmony export */ "MAX_PINNED_COUNT": () => (/* binding */ MAX_PINNED_COUNT),
/* harmony export */ "MESSAGE_STATUS_FAILED": () => (/* binding */ MESSAGE_STATUS_FAILED), /* harmony export */ "MESSAGE_STATUS_FAILED": () => (/* binding */ MESSAGE_STATUS_FAILED),
/* harmony export */ "MESSAGE_STATUS_FATAL": () => (/* binding */ MESSAGE_STATUS_FATAL), /* harmony export */ "MESSAGE_STATUS_FATAL": () => (/* binding */ MESSAGE_STATUS_FATAL),
/* harmony export */ "MESSAGE_STATUS_NONE": () => (/* binding */ MESSAGE_STATUS_NONE), /* harmony export */ "MESSAGE_STATUS_NONE": () => (/* binding */ MESSAGE_STATUS_NONE),
@@ -464,7 +463,6 @@ const EXPIRE_PROMISES_PERIOD = 1000;
const RECV_TIMEOUT = 100; const RECV_TIMEOUT = 100;
const DEFAULT_MESSAGES_PAGE = 24; const DEFAULT_MESSAGES_PAGE = 24;
const DEL_CHAR = '\u2421'; const DEL_CHAR = '\u2421';
const MAX_PINNED_COUNT = 5;
/***/ }), /***/ }),
@@ -1308,7 +1306,7 @@ function _serializeMessage(dst, msg) {
} }
var _topic_fields = { var _topic_fields = {
writable: true, writable: true,
value: ['created', 'updated', 'deleted', 'touched', 'read', 'recv', 'seq', 'clear', 'defacs', 'creds', 'public', 'trusted', 'private', '_aux', '_deleted'] value: ['created', 'updated', 'deleted', 'read', 'recv', 'seq', 'clear', 'defacs', 'creds', 'public', 'trusted', 'private', 'touched', '_deleted']
}; };
/***/ }), /***/ }),
@@ -3030,6 +3028,11 @@ __webpack_require__.r(__webpack_exports__);
let XHRProvider; let XHRProvider;
function addURLParam(relUrl, key, value) {
const url = new URL(relUrl, window.location.origin);
url.searchParams.append(key, value);
return url.toString().substring(window.location.origin.length);
}
class LargeFileHelper { class LargeFileHelper {
constructor(tinode, version) { constructor(tinode, version) {
this._tinode = tinode; this._tinode = tinode;
@@ -3160,6 +3163,7 @@ class LargeFileHelper {
const instance = this; const instance = this;
const xhr = new XHRProvider(); const xhr = new XHRProvider();
this.xhr.push(xhr); this.xhr.push(xhr);
relativeUrl = addURLParam(relativeUrl, 'asatt', '1');
xhr.open('GET', relativeUrl, true); xhr.open('GET', relativeUrl, true);
xhr.setRequestHeader('X-Tinode-APIKey', this._apiKey); xhr.setRequestHeader('X-Tinode-APIKey', this._apiKey);
xhr.setRequestHeader('X-Tinode-Auth', 'Token ' + this._authToken.token); xhr.setRequestHeader('X-Tinode-Auth', 'Token ' + this._authToken.token);
@@ -3323,10 +3327,6 @@ class MetaGetBuilder {
} }
return this; return this;
} }
withAux() {
this.what['aux'] = true;
return this;
}
withDel(since, limit) { withDel(since, limit) {
if (since || limit) { if (since || limit) {
this.what['del'] = { this.what['del'] = {
@@ -3345,7 +3345,7 @@ class MetaGetBuilder {
build() { build() {
const what = []; const what = [];
let params = {}; let params = {};
['data', 'sub', 'desc', 'tags', 'cred', 'aux', 'del'].forEach(key => { ['data', 'sub', 'desc', 'tags', 'cred', 'del'].forEach(key => {
if (this.what.hasOwnProperty(key)) { if (this.what.hasOwnProperty(key)) {
what.push(key); what.push(key);
if (Object.getOwnPropertyNames(this.what[key]).length > 0) { if (Object.getOwnPropertyNames(this.what[key]).length > 0) {
@@ -3425,7 +3425,6 @@ class Topic {
this._recvNotificationTimer = null; this._recvNotificationTimer = null;
this._tags = []; this._tags = [];
this._credentials = []; this._credentials = [];
this._aux = {};
this._messageVersions = {}; this._messageVersions = {};
this._messages = new _cbuffer_js__WEBPACK_IMPORTED_MODULE_1__["default"]((a, b) => { this._messages = new _cbuffer_js__WEBPACK_IMPORTED_MODULE_1__["default"]((a, b) => {
return a.seq - b.seq; return a.seq - b.seq;
@@ -3445,7 +3444,6 @@ class Topic {
this.onSubsUpdated = callbacks.onSubsUpdated; this.onSubsUpdated = callbacks.onSubsUpdated;
this.onTagsUpdated = callbacks.onTagsUpdated; this.onTagsUpdated = callbacks.onTagsUpdated;
this.onCredsUpdated = callbacks.onCredsUpdated; this.onCredsUpdated = callbacks.onCredsUpdated;
this.onAuxUpdated = callbacks.onAuxUpdated;
this.onDeleteTopic = callbacks.onDeleteTopic; this.onDeleteTopic = callbacks.onDeleteTopic;
this.onAllMessagesReceived = callbacks.onAllMessagesReceived; this.onAllMessagesReceived = callbacks.onAllMessagesReceived;
} }
@@ -3690,9 +3688,6 @@ class Topic {
if (params.cred) { if (params.cred) {
this._processMetaCreds([params.cred], true); this._processMetaCreds([params.cred], true);
} }
if (params.aux) {
this._processMetaAux(params.aux);
}
return ctrl; return ctrl;
}); });
} }
@@ -3726,38 +3721,6 @@ class Topic {
} }
}); });
} }
pinMessage(seq, pin) {
let pinned = this.aux('pins');
if (!Array.isArray(pinned)) {
pinned = [];
}
let changed = false;
if (pin) {
if (!pinned.includes(seq)) {
changed = true;
if (pinned.length == _config_js__WEBPACK_IMPORTED_MODULE_3__.MAX_PINNED_COUNT) {
pinned.shift();
}
pinned.push(seq);
}
} else {
if (pinned.includes(seq)) {
changed = true;
pinned = pinned.filter(id => id != seq);
if (pinned.length == 0) {
pinned = _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR;
}
}
}
if (changed) {
return this.setMeta({
aux: {
pins: pinned
}
});
}
return Promise.resolve();
}
delMessages(ranges, hard) { delMessages(ranges, hard) {
if (!this._attached) { if (!this._attached) {
return Promise.reject(new Error("Cannot delete messages in inactive topic")); return Promise.reject(new Error("Cannot delete messages in inactive topic"));
@@ -3987,9 +3950,6 @@ class Topic {
tags() { tags() {
return this._tags.slice(0); return this._tags.slice(0);
} }
aux(key) {
return this._aux[key];
}
subscriber(uid) { subscriber(uid) {
return this._users[uid]; return this._users[uid];
} }
@@ -4290,9 +4250,6 @@ class Topic {
if (meta.cred) { if (meta.cred) {
this._processMetaCreds(meta.cred); this._processMetaCreds(meta.cred);
} }
if (meta.aux) {
this._processMetaAux(meta.aux);
}
if (this.onMeta) { if (this.onMeta) {
this.onMeta(meta); this.onMeta(meta);
} }
@@ -4320,9 +4277,6 @@ class Topic {
this.getMeta(this.startMetaQuery().withLaterOneSub(pres.src).build()); this.getMeta(this.startMetaQuery().withLaterOneSub(pres.src).build());
} }
break; break;
case 'aux':
this.getMeta(this.startMetaQuery().withAux().build());
break;
case 'acs': case 'acs':
uid = pres.src || this._tinode.getCurrentUserID(); uid = pres.src || this._tinode.getCurrentUserID();
user = this._users[uid]; user = this._users[uid];
@@ -4437,31 +4391,22 @@ class Topic {
} }
} }
_processMetaTags(tags) { _processMetaTags(tags) {
if (tags == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR || tags.length == 1 && tags[0] == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR) { if (tags.length == 1 && tags[0] == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR) {
tags = []; tags = [];
} }
this._tags = tags; this._tags = tags;
this._tinode._db.updTopic(this);
if (this.onTagsUpdated) { if (this.onTagsUpdated) {
this.onTagsUpdated(tags); this.onTagsUpdated(tags);
} }
} }
_processMetaCreds(creds) {} _processMetaCreds(creds) {}
_processMetaAux(aux) {
aux = !aux || aux == _config_js__WEBPACK_IMPORTED_MODULE_3__.DEL_CHAR ? {} : aux;
this._aux = (0,_utils_js__WEBPACK_IMPORTED_MODULE_6__.mergeObj)(this._aux, aux);
this._tinode._db.updTopic(this);
if (this.onAuxUpdated) {
this.onAuxUpdated(this._aux);
}
}
_processDelMessages(clear, delseq) { _processDelMessages(clear, delseq) {
this._maxDel = Math.max(clear, this._maxDel); this._maxDel = Math.max(clear, this._maxDel);
this.clear = Math.max(clear, this.clear); this.clear = Math.max(clear, this.clear);
const topic = this; const topic = this;
let count = 0; let count = 0;
if (Array.isArray(delseq)) { if (Array.isArray(delseq)) {
delseq.forEach(range => { delseq.forEach(function (range) {
if (!range.hi) { if (!range.hi) {
count++; count++;
topic.flushMessage(range.low); topic.flushMessage(range.low);
@@ -4983,7 +4928,7 @@ function normalizeArray(arr) {
} }
} }
} }
out.sort().filter((item, pos, ary) => { out.sort().filter(function (item, pos, ary) {
return !pos || item != ary[pos - 1]; return !pos || item != ary[pos - 1];
}); });
} }
@@ -5005,7 +4950,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "PACKAGE_VERSION": () => (/* binding */ PACKAGE_VERSION) /* harmony export */ "PACKAGE_VERSION": () => (/* binding */ PACKAGE_VERSION)
/* harmony export */ }); /* harmony export */ });
const PACKAGE_VERSION = "0.23.0-rc1"; const PACKAGE_VERSION = "0.22.3";
/***/ }) /***/ })
@@ -5725,9 +5670,6 @@ class Tinode {
if (setParams.tags) { if (setParams.tags) {
pkt.sub.set.tags = setParams.tags; pkt.sub.set.tags = setParams.tags;
} }
if (setParams.aux) {
pkt.sub.set.aux = setParams.aux;
}
} }
return _classPrivateMethodGet(this, _send, _send2).call(this, pkt, pkt.sub.id); return _classPrivateMethodGet(this, _send, _send2).call(this, pkt, pkt.sub.id);
} }
@@ -5842,7 +5784,7 @@ class Tinode {
const pkt = _classPrivateMethodGet(this, _initPacket, _initPacket2).call(this, 'set', topic); const pkt = _classPrivateMethodGet(this, _initPacket, _initPacket2).call(this, 'set', topic);
const what = []; const what = [];
if (params) { if (params) {
['desc', 'sub', 'tags', 'cred', 'aux'].forEach(key => { ['desc', 'sub', 'tags', 'cred', 'ephemeral'].forEach(function (key) {
if (params.hasOwnProperty(key)) { if (params.hasOwnProperty(key)) {
what.push(key); what.push(key);
pkt.set[key] = params[key]; pkt.set[key] = params[key];
@@ -6268,7 +6210,7 @@ function _initPacket2(type, topic) {
'desc': {}, 'desc': {},
'sub': {}, 'sub': {},
'tags': [], 'tags': [],
'aux': {} 'ephemeral': {}
} }
}; };
case 'del': case 'del':
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long