public call()

in src/rpc.ts [187:214]


  public call<T>(method: string, params: object, waitForReply: boolean = true): Promise<T> | void {
    const id = method === 'ready' ? magicReadyCallId : this.callCounter;
    const packet: IRPCMethod<any> = {
      type: 'method',
      serviceID: this.options.serviceId,
      id,
      params,
      method,
      discard: !waitForReply,
    };

    this.emit('sendMethod', packet);
    this.post(packet);

    if (!waitForReply) {
      return;
    }

    return new Promise((resolve, reject) => {
      this.calls[id] = (err, res) => {
        if (err) {
          reject(err);
        } else {
          resolve(res);
        }
      };
    });
  }