Decrypt m.audio attachments
This commit is contained in:
parent
48340a2817
commit
4e01a4f692
1 changed files with 51 additions and 4 deletions
|
@ -21,28 +21,75 @@ import MFileBody from './MFileBody';
|
||||||
|
|
||||||
import MatrixClientPeg from '../../../MatrixClientPeg';
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
||||||
import sdk from '../../../index';
|
import sdk from '../../../index';
|
||||||
|
import { decryptFile } from '../../../utils/DecryptFile';
|
||||||
|
|
||||||
export default class MAudioBody extends React.Component {
|
export default class MAudioBody extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
playing: false
|
playing: false,
|
||||||
|
decryptedUrl: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onPlayToggle() {
|
onPlayToggle() {
|
||||||
this.setState({
|
this.setState({
|
||||||
playing: !this.state.playing
|
playing: !this.state.playing
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getContentUrl() {
|
||||||
|
var content = this.props.mxEvent.getContent();
|
||||||
|
if (content.file !== undefined) {
|
||||||
|
return this.state.decryptedUrl;
|
||||||
|
} else {
|
||||||
|
return MatrixClientPeg.get().mxcUrlToHttp(content.url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
var content = this.props.mxEvent.getContent();
|
||||||
|
if (content.file !== undefined && this.state.decryptedUrl === null) {
|
||||||
|
decryptFile(content.file).then((blob) => {
|
||||||
|
if (!this._unmounted) {
|
||||||
|
this.setState({
|
||||||
|
decryptedUrl: window.URL.createObjectURL(blob),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch((err) => {
|
||||||
|
console.warn("Unable to decrypt attachment: ", err)
|
||||||
|
// Set a placeholder image when we can't decrypt the image.
|
||||||
|
this.refs.image.src = "img/warning.svg";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this._unmounted = true;
|
||||||
|
if (this.state.decryptedUrl) {
|
||||||
|
window.URL.revokeObjectURL(this.state.decryptedUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
var content = this.props.mxEvent.getContent();
|
var content = this.props.mxEvent.getContent();
|
||||||
var cli = MatrixClientPeg.get();
|
|
||||||
|
if (content.file !== undefined && this.state.decryptedUrl === null) {
|
||||||
|
// Need to decrypt the attachment
|
||||||
|
// The attachment is decrypted in componentDidMount.
|
||||||
|
// For now add an img tag with a spinner.
|
||||||
|
return (
|
||||||
|
<span className="mx_MAudioBody">
|
||||||
|
<img src="img/spinner.gif" ref="image"
|
||||||
|
alt={content.body} />
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
var contentUrl = this._getContentUrl();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className="mx_MAudioBody">
|
<span className="mx_MAudioBody">
|
||||||
<audio src={cli.mxcUrlToHttp(content.url)} controls />
|
<audio src={contentUrl} controls />
|
||||||
<MFileBody {...this.props} />
|
<MFileBody {...this.props} />
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue