Add event handlers and comments.

This commit is contained in:
Richard Lewis 2017-12-15 16:56:02 +00:00
parent 9f733ebc94
commit f2ad7be3f3

View file

@ -155,12 +155,15 @@ export default React.createClass({
}, },
componentWillMount() { componentWillMount() {
WidgetMessaging.startListening();
WidgetMessaging.addEndpoint(this.props.id, this.props.url);
window.addEventListener('message', this._onMessage, false);
this.setScalarToken(); this.setScalarToken();
}, },
componentDidMount() {
// Legacy Jitsi widget messaging -- TODO replace this with standard widget
// postMessaging API
window.addEventListener('message', this._onMessage, false);
},
/** /**
* Adds a scalar token to the widget URL, if required * Adds a scalar token to the widget URL, if required
* Component initialisation is only complete when this function has resolved * Component initialisation is only complete when this function has resolved
@ -234,6 +237,8 @@ export default React.createClass({
} }
}, },
// Legacy Jitsi widget messaging
// TODO -- This should be replaced with the new widget postMessaging API
_onMessage(event) { _onMessage(event) {
if (this.props.type !== 'jitsi') { if (this.props.type !== 'jitsi') {
return; return;
@ -268,14 +273,16 @@ export default React.createClass({
}, },
_onSnapshotClick(e) { _onSnapshotClick(e) {
const iframe = this.refs.appFrame; console.warn("Requesting widget snapshot");
domtoimage.toPng(iframe).then(function(dataUrl) { this.widgetMessaging.getScreenshot();
console.log("Image data URL:", dataUrl); // const iframe = this.refs.appFrame;
dis.dispatch({ // domtoimage.toPng(iframe).then(function(dataUrl) {
action: 'picture_snapshot', // console.log("Image data URL:", dataUrl);
file: dataURLtoBlob(dataUrl), // dis.dispatch({
}, true); // action: 'picture_snapshot',
}); // file: dataURLtoBlob(dataUrl),
// }, true);
// });
}, },
/* If user has permission to modify widgets, delete the widget, /* If user has permission to modify widgets, delete the widget,
@ -317,6 +324,10 @@ export default React.createClass({
* Called when widget iframe has finished loading * Called when widget iframe has finished loading
*/ */
_onLoaded() { _onLoaded() {
// console.warn("App frame", this.refs.appFrame.contentWindow);
this.widgetMessaging = new WidgetMessaging(this.refs.appFrame.contentWindow);
this.widgetMessaging.startListening();
this.widgetMessaging.addEndpoint(this.props.id, this.props.url);
this.setState({loading: false}); this.setState({loading: false});
}, },