package com.lovecoding.websocket;


import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint("/game")
@Component
public class GameController {

    @OnOpen
    public void onOpen(Session session){
        System.out.println( "新增用户" );
        GameTools.add(session);

        System.out.println( "当前共有用户： " + GameTools.get().size() );

    }

    @OnMessage
    public void onMsg( String msg, Session session ){

    }

    @OnError
    public void onError( Throwable throwable  ){
        System.out.println( "发生异常" );
        System.out.println( throwable.getMessage() );
    }

    @OnClose
    public void onClose( Session session ){
        System.out.println( "用户掉线了" );
        GameTools.del(session);
    }

}
