+
+ if(nextProps.match.params.externalUrl !== undefined &&
+ nextProps.match.params.externalUrl !== this.props.match.params.externalUrl &&
+ this.isValidExternalURL(nextProps.match.params.externalUrl)) {
+ this.props.onExternalUrlRequest(nextProps.match.params.externalUrl);
+ }
+ /* if the externalURL is not valid, we do not add any message as other proper
+ views will get that messages since the route will be this parameter.*/
+
+ if(this.props.externalRequestFound !== nextProps.externalRequestFound &&
+ nextProps.externalRequestFound !== undefined && nextProps.externalRequestFound.suggestion !== undefined) {
+ changeUrlAddress(nextProps.externalRequestFound.suggestion, nextProps.history);
+ }
+
+ if (nextProps.subscriptionEnabled) {
+ if (nextProps.subscriptionPayload !== this.props.subscriptionPayload &&
+ Object.keys(nextProps.subscriptionPayload).length > 0) {
+ var getWindowUrl = function (url) {
+ var split = url.split('/');
+ return split[0] + '//' + split[2];
+ };
+ window.parent.postMessage(
+ JSON.stringify(nextProps.subscriptionPayload),
+ getWindowUrl(document.referrer));
+ }
+ }
+ }
+
+ receiveMessage(event, $this) {
+ function isJson(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return false;
+ }
+ return true;
+ }
+ if(isJson(event.data)) {
+ let messageData = JSON.parse(event.data);
+ if(isJson(messageData.message)) {
+ $this.props.onExternalMessageRecieved(messageData.message);
+ }
+ }
+
+ }
+ componentDidMount() {
+ //TODO Move this logic to the component will receive props.
+ //Check if the event lister is available and if the subscription is
+ // enabled before registering for it
+ if(document.referrer) {
+ var $this = this;
+ window.addEventListener('message', function (e) {
+ $this.receiveMessage(e, $this);
+ }, false);
+ }
+
+ // fetch custom views
+ this.props.onFetchCustomViews();
+ }
+
+ componentWillUnmount() {
+ if(this.props.subscriptionEnabled) {
+ var $this = this;
+ window.removeEventListener('message', function (e) {
+ $this.receiveMessage(e, $this);
+ });
+ }