OverviewFilesCommitsIssuesDocsReleasesPeers

keet-cli / keet-core-4.14.4-pretty / lib / core / tasks / pairing / response.js

31 lines · javascript ref:
const { Task: e } = require("../task")
module.exports = class extends e {
  constructor(e) {
    super(e)
    const i = this.description.joinRoomResponse
    ;((this._keyPair = i.keyPair),
      (this._response = i.response),
      (this._mailbox = i.mailbox),
      (this._core = null))
  }
  async _close() {
    this._core && (await this._core.close())
  }
  async _run() {
    if (
      ((this._core = this.store.get({ keyPair: this._keyPair })),
      await this._core.ready(),
      0 === this._core.length)
    ) {
      if ((await this.keet.internalVerifyOptimisticCore(this._core), this.closing)) return
      0 === this._core.length && (await this._core.append(this._response, { maxLength: 1 }))
    }
    ;(await this.keet.blindPeering.addCore(this._core, {
      target: this._mailbox,
      referrer: this._mailbox,
      priority: 1,
    }),
      await new Promise((e) => setTimeout(e, this.keet.internalPairingTimeout)))
  }
}