Unfinished, non-working changes to try and handle URL changes gracefully

pull/21833/head
Richard Lewis 2017-10-27 13:47:51 +01:00
parent 1715206f62
commit 7662b5ac8f
1 changed files with 21 additions and 5 deletions

View File

@ -99,14 +99,27 @@ export default React.createClass({
}, },
componentWillMount: function() { componentWillMount: function() {
window.addEventListener('message', this._onMessage, false);
this.updateWidgetContent();
},
// Update widget content
updateWidgetContent() {
this.setScalarToken();
this.setState({
loading: true,
});
},
// Adds a scalar token to the widget URL, if required
setScalarToken() {
if (!this.isScalarUrl()) { if (!this.isScalarUrl()) {
return; return;
} }
// Fetch the token before loading the iframe as we need to mangle the URL // Fetch the token before loading the iframe as we need to mangle the URL
this.setState({ if(! this._scalarClient) {
loading: true, this._scalarClient = new ScalarAuthClient();
}); }
this._scalarClient = new ScalarAuthClient();
this._scalarClient.getScalarToken().done((token) => { this._scalarClient.getScalarToken().done((token) => {
// Append scalar_token as a query param // Append scalar_token as a query param
this._scalarClient.scalarToken = token; this._scalarClient.scalarToken = token;
@ -128,13 +141,16 @@ export default React.createClass({
loading: false, loading: false,
}); });
}); });
window.addEventListener('message', this._onMessage, false);
}, },
componentWillUnmount() { componentWillUnmount() {
window.removeEventListener('message', this._onMessage); window.removeEventListener('message', this._onMessage);
}, },
componentWillReceiveProps(nextProps) {
console.warn("Apptile", this.id, "got new props", this.url, nextProps.url);
},
_onMessage(event) { _onMessage(event) {
if (this.props.type !== 'jitsi') { if (this.props.type !== 'jitsi') {
return; return;