responseOtherSide()

in lib/connection.ts [218:247]


  responseOtherSide(id: string, result?: any, success = true) {
    if (result instanceof Error) {
      // Error could be non-serializable, so we copy properties manually
      result = [...Object.keys(result), 'message'].reduce((acc, it) => {
        acc[it] = result[it];
        return acc;
      }, {} as {[k: string]: any});
    }

    const doPost = () =>
      this.postMessage(
        {
          callId: id,
          type: TYPE_RESPONSE,
          success,
          result
        },
        '*'
      );

    try {
      doPost();
    } catch (err) {
      console.error('Failed to post response, recovering...', err); // eslint-disable-line no-console
      if (err instanceof DOMException) {
        result = JSON.parse(JSON.stringify(result));
        doPost();
      }
    }
  }