import { Service } from "../../framework/base/Service" ; import { GameEventInterface } from "../../framework/base/GameEventInterface" ; import { IMessage } from "../../framework/net/Message" ; import { MainCmd , SUB_CMD_SYS } from "../protocol/CmdNetID" ; description export class CommonService extends Service implements GameEventInterface { protected static _instance : CommonService = null ; public static get instance ( ) { return this . _instance || ( this . _instance = new CommonService ( ) ) ; } description protected sendHeartbeat ( ) { if ( this . heartbeat ) { this . send ( new this . heartbeat ( ) ) ; } else { cc . error ( "请先设置心跳解析类型" ) ; } } description protected getMaxHeartbeatTimeOut ( ) { return super . getMaxHeartbeatTimeOut ( ) ; } protected getHeartbeatInterval ( ) { return super . getHeartbeatInterval ( ) ; } description protected onHeartbeatTimeOut ( ) { super . onHeartbeatTimeOut ( ) ; cc . warn ( `心跳超时，您已经断开网络` ) ; } description protected isHeartBeat ( data ) { return data . mainCmd == MainCmd . CMD_SYS && data . subCmd == SUB_CMD_SYS . CMD_SYS_HEART_ACK ; } onEnterBackground ( ) { } onEnterForgeground ( inBackgroundTime ) { } }