| 12345678910111213141516171819202122 |
- import { ch } from "../ch";
- import { ch_net, game_protocol } from "../net/net";
- export default class NetMgr<gd extends game_protocol> {
- private _net: ch_net<gd> = null!;
- public get net(): Readonly<ch_net<gd>> {
- if (!this._net) throw new Error("Network not initialized");
- return this._net;
- }
- constructor() {
- this._net = ch.get_new_net<gd>();
- }
- public init(json: boolean = false) {
- this._net.init(ch.wsurl,
- {
- query: `token=${chsdk.getToken()}`,
- json: json,
- });
- }
- public connect(): Promise<string | null> {
- return this._net.connect();
- }
- }
|