private async _start()

in tools/awps-tunnel/client/src/providers/ConnectionBasedDataFether.tsx [44:119]


  private async _start() {
    const newConnection = this._connection = await this._createConnection();
    const apiSpec = await loadApiSpec();
    this.model = { ...this.model, apiSpec };
    this.setData(this.model);

    newConnection.on("updateLogs", (logs) => {
      this.model = { ...this.model, logs: [...this.model.logs, ...logs] };
      this.setData(this.model);
    });

    newConnection.on("reportLiveTraceUrl", (url) => {
      this.model = { ...this.model, liveTraceUrl: url };
      this.setData(this.model);
    });

    newConnection.on("reportServiceEndpoint", (url) => {
      this.model = { ...this.model, endpoint: url };
      this.setData(this.model);
    });
    newConnection.on("reportLocalServerUrl", (url) => {
      this.model = { ...this.model, upstreamServerUrl: url };
      this.setData(this.model);
    });
    newConnection.on("reportStatusChange", (status) => {
      this.model = { ...this.model, tunnelConnectionStatus: status };
      this.setData(this.model);
    });
    newConnection.on("reportBuiltinUpstreamServerStarted", (status) => {
      this.model = { ...this.model, builtinUpstreamServerStarted: status };
      this.setData(this.model);
    });
    newConnection.on("reportTunnelToLocalServerStatus", (status) => {
      this.model = { ...this.model, tunnelServerStatus: status };
      this.setData(this.model);
    });

    newConnection.on("reportServiceConfiguration", (config) => {
      this.model = { ...this.model, serviceConfiguration: config };
      this.setData(this.model);
    });

    newConnection.on("addTraffic", (item) => {
      const currentItems = [item, ...this.model.trafficHistory];
      this.model = { ...this.model, trafficHistory: currentItems };
      this.setData(this.model);
    });

    newConnection.on("updateTraffic", (item) => {
      let currentItems = this.model.trafficHistory.map((i) => {
        if (i.id === item.id) {
          return item;
        }
        return i;
      });
      this.model = { ...this.model, trafficHistory: currentItems };
      this.setData(this.model);
    });

    newConnection.on("clearTraffic", () => {
      this.model = { ...this.model, trafficHistory: [] };
      this.setData(this.model);
    });
    await this._startConnection(newConnection);
    // add a tcs for connection started
    this._connectionStartedTcs.resolve();
    const serverModel = await this._invoke(newConnection, "getCurrentModel");
    this.model = {
      ...this.model,
      logs: serverModel.logs,
      trafficHistory: serverModel.trafficHistory,
      ...serverModel.state,
      ready: true,
    };
    this.setData(this.model);
  }