50 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-08-26 16:48:17 +08:00
import { INetRequest } from "./Core/INetRequest";
import { NetConnector } from "./NetConnector";
export class NetManager {
static get IsConnected() { return this._connector && this._connector.IsConnected; }
static get HasInit() { return this._connector != null; }
private static _connector: NetConnector;
static Initialize(connector: NetConnector) {
this._connector = connector;
}
static ConnectAsync() {
this.CheckConnector();
return this._connector.ConnectAsync();
}
/**
*
*/
static Disconnect() {
this.CheckConnector();
this._connector.Disconnect();
}
/**
* Server,
* @param req
*/
static Send(req: INetRequest<any, any>) {
this.CheckConnector();
this._connector.Send(req);
}
/**
* Server,
* @param req
*/
static SendAsync(req: INetRequest<any, any>,mask:boolean) {
this.CheckConnector();
return this._connector.SendAsync(req,mask);
}
private static CheckConnector()
{
if (!this._connector) throw new Error("請先呼叫CasinoNetManager.Initialize()初始化connector");
}
}