public onMessage()

in src/XDM.ts [340:382]


    public onMessage(rpcMessage: IJsonRpcMessage): boolean {

        if (rpcMessage.instanceId) {
            // Find the object that handles this requestNeed to find implementation

            // Look in the channel registry first
            const registeredObject: any = this.getRegisteredObject(rpcMessage.instanceId, rpcMessage.instanceContext);
            if (!registeredObject) {
                // If not found return false to indicate that the message was not handled
                return false;
            }

            if (typeof registeredObject["then"] === "function") {
                (<Promise<any>>registeredObject).then((resolvedInstance) => {
                    this.invokeMethod(resolvedInstance, rpcMessage);
                }, (e) => {
                    this.error(rpcMessage, e);
                });
            }
            else {
                this.invokeMethod(registeredObject, rpcMessage);
            }
        }
        else {
            const promise = this.promises[rpcMessage.id];
            if (!promise) {
                // Message not handled by this channel.
                return false;
            }

            if (rpcMessage.error) {
                promise.reject(this._customDeserializeObject([rpcMessage.error], {})[0]);
            }
            else {
                promise.resolve(this._customDeserializeObject([rpcMessage.result], {})[0]);
            }

            delete this.promises[rpcMessage.id];
        }

        // Message handled by this channel
        return true;
    }