ch_net_help.ts 667 B

12345678910111213141516171819202122
  1. import { ch } from "../ch";
  2. import { ch_net, game_protocol } from "../net/net";
  3. export default class NetMgr<gd extends game_protocol> {
  4. private _net: ch_net<gd> = null!;
  5. public get net(): Readonly<ch_net<gd>> {
  6. if (!this._net) throw new Error("Network not initialized");
  7. return this._net;
  8. }
  9. constructor() {
  10. this._net = ch.get_new_net<gd>();
  11. }
  12. public init(json: boolean = false) {
  13. this._net.init(ch.wsurl,
  14. {
  15. query: `token=${chsdk.getToken()}`,
  16. json: json,
  17. });
  18. }
  19. public connect(): Promise<string | null> {
  20. return this._net.connect();
  21. }
  22. }