XDMChannelManager.prototype._handleMessageReceived = function()

in Extensions/Optimizely/Src/UIContribution/lib/VSS.SDK.js [617:651]


        XDMChannelManager.prototype._handleMessageReceived = function (event) {
            // get channel and dispatch to it
            var i, len, channel;
            var rpcMessage;
            if (typeof event.data === "string") {
                try {
                    rpcMessage = JSON.parse(event.data);
                }
                catch (error) {
                    // The message is not a valid JSON string. Not one of our events.
                }
            }
            if (rpcMessage) {
                var handled = false;
                var channelOwner;
                for (i = 0, len = this._channels.length; i < len; i++) {
                    channel = this._channels[i];
                    if (channel.owns(event.source, event.origin, rpcMessage)) {
                        // keep a reference to the channel owner found. 
                        channelOwner = channel;
                        handled = channel.onMessage(rpcMessage, event.origin) || handled;
                    }
                }
                if (!!channelOwner && !handled) {
                    if (window.console) {
                        console.error("No handler found on any channel for message: " + JSON.stringify(rpcMessage));
                    }
                    // for instance based proxies, send an error on the channel owning the message to resolve any control creation promises
                    // on the host frame. 
                    if (rpcMessage.instanceId) {
                        channelOwner.error(rpcMessage, "The registered object " + rpcMessage.instanceId + " could not be found.");
                    }
                }
            }
        };