import { _decorator } from 'cc';
import { JCMGO } from '../ThirdParty/JCMGO';
import { BuiltinMatchInfos } from './View/GameMatchView';

export class SocketPlayer extends JCMGO.SocketClient {
    constructor() {
        super()
        this.connect("wss://www.9527fun.cn/JCMiniGameOnline?gameId=跑步Demo2");
    }
    protected onLoad(): void {
        this.singlePersonRandomMatching({
            playerInfo: BuiltinMatchInfos.myPlayerInfo,
            matchRoomConfig: {
                type: window.gm.config.roomMatchType,
                syncFrameRate: window.gm.config.syncFrameRate,
                maxMatchingTime: window.gm.config.debugQuicklyStartGame ? 0 : window.gm.config.maxMatchingTime,
                maxMembers: window.gm.config.maxMembers,
            }
        });
    }
    protected onReload(): void {
        
    }
    protected onDestroy(): void {
        
    }
    protected onMiss(): void {
        
    }
    protected onRoomAddPlayer(e: JCMGO.BroadcastEvent<JCMGO.RoomAddPlayerBst>): void {
        window.gm.mode.handleEnterRoom(e.data);
    }
    protected onRoomRemovePlayer(e: JCMGO.BroadcastEvent<JCMGO.RoomRemovePlayerBst>): void {
        
    }
    protected onRoomEndMatching(e: JCMGO.BroadcastEvent<JCMGO.RoomEndMatchingBst>): void {
        window.gm.mode.handleMatchComplete(e.data);
    }
    protected onFrameSyncStart(e: JCMGO.BroadcastEvent<null>): void {
        window.gm.mode.handleFrameSyncStart();
    }
    protected onRecvFrame(e: JCMGO.BroadcastEvent<JCMGO.Frame>): void {
        window.gm.mode.handleRecvFrame(e.data);
    }
}
