function call()

in taverna-interaction-activity/src/main/resources/pmrpc.js [360:419]


  function call(config) {
    // check that number of retries is not -1, that is a special internal value
    if (config.retries && config.retries < 0) {
      throw new Exception("number of retries must be 0 or higher");
    }
    
    var destContexts = [];
    
    if (typeof config.destination === "undefined" || config.destination === null || config.destination === "workerParent") {
      destContexts = [{context : null, type : "workerParent"}];
    } else if (config.destination === "publish") {
      destContexts = findAllReachableContexts();
    } else if (config.destination instanceof Array) {
      for (var i=0; i<config.destination.length; i++) {
        if (config.destination[i] === "workerParent") {
          destContexts.push({context : null, type : "workerParent"});
        } else if (typeof config.destination[i].frames !== "undefined") {
          destContexts.push({context : config.destination[i], type : "window"});
        } else {
          destContexts.push({context : config.destination[i], type : "worker"});
        }
      }
    } else {
      if (typeof config.destination.frames !== "undefined") {
        destContexts.push({context : config.destination, type : "window"});
      } else {
        destContexts.push({context : config.destination, type : "worker"});
      }
    }
        
    for (var i=0; i<destContexts.length; i++) {
      var callObj = {
        destination : destContexts[i].context,
        destinationDomain : typeof config.destinationDomain === "undefined" ? ["*"] : (typeof config.destinationDomain === "string" ? [config.destinationDomain] : config.destinationDomain),
        publicProcedureName : config.publicProcedureName,
        onSuccess : typeof config.onSuccess !== "undefined" ? 
                      config.onSuccess : function (){},
        onError : typeof config.onError !== "undefined" ? 
                      config.onError : function (){},
        retries : typeof config.retries !== "undefined" ? config.retries : 5,
        timeout : typeof config.timeout !== "undefined" ? config.timeout : 500,
        status : "requestNotSent"
      };
      
      isNotification = typeof config.onError === "undefined" && typeof config.onSuccess === "undefined";
      params = (typeof config.params !== "undefined") ? config.params : [];
      callId = generateUUID();
      callQueue[callId] = callObj; 
      
      if (isNotification) {
        callObj.message = createJSONRpcRequestObject(
                    config.publicProcedureName, params);
      } else {
        callObj.message = createJSONRpcRequestObject(
                            config.publicProcedureName, params, callId);
      }
      
      waitAndSendRequest(callId);
    }
  }