package com.gyee.frame.controller.socket;


import com.gyee.frame.netty.websocket.WebSocketServer;
import com.gyee.frame.netty.websocket.util.SocketToolController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.websocket.EncodeException;
import java.io.IOException;

@Controller
@RequestMapping("/checkcenter")
public class CheckCenterController extends SocketToolController {

	@Resource
	private WebSocketServer webSocketServer;

	//页面请求,模板样例
	@GetMapping("/socket1")
	public ModelAndView socket() throws IOException {
		//ModelAndView modelAndView=new ModelAndView("socket/socket1");
		return goSocketPage("socket1","socket/socket1");
	}



	//推送数据接口
	@ResponseBody
	@GetMapping("/socket/push")
	public void pushToWeb(String pageNumber,String functionNumber,String keyid, String message) {
		try {
			webSocketServer.sendObject(message,pageNumber,functionNumber,keyid);
		} catch (IOException | EncodeException e) {
			e.printStackTrace();
		}
	}
} 
