import { queenApi } from "queenjs";
import { connect, StringCodec, Empty, ErrorCode } from "nats.ws";
import { Controller } from "../core/controller";
import { useCtx } from "../ctx";
import { reactive } from "vue";

export class CmdSvcController extends Controller {
  
    state = reactive({
        list: [] as {f:string,m:string}[]
    })

    async onReady() {
      const {natsCtrl} = useCtx();
      const params = new URLSearchParams(decodeURIComponent(location.search));
      const guid = params.get("guid");

      const state = this.state;
      console.log("substring", `${guid}.cmdmsg`)
      natsCtrl.subscribe(`${guid}.cmdmsg`, (msg:any)=>{
        console.log("cmdMsg=>", msg);
        state.list.push(msg);
      }, {queue: "cmdsvc"})
    }
}