com.healthy.common.websocket.handler.PingJsonMessageHandler Maven / Gradle / Ivy
package com.healthy.common.websocket.handler;
import com.healthy.common.websocket.WebSocketMessageSender;
import com.healthy.common.websocket.message.JsonWebSocketMessage;
import com.healthy.common.websocket.message.PingJsonWebSocketMessage;
import com.healthy.common.websocket.message.PongJsonWebSocketMessage;
import com.healthy.common.websocket.message.WebSocketMessageTypeEnum;
import org.springframework.web.socket.WebSocketSession;
/**
* 心跳处理,接收到客户端的ping时,立刻回复一个pong
*
* @author xm.z
*/
public class PingJsonMessageHandler implements JsonMessageHandler {
@Override
public void handle(WebSocketSession session, PingJsonWebSocketMessage message) {
JsonWebSocketMessage pongJsonWebSocketMessage = new PongJsonWebSocketMessage();
WebSocketMessageSender.send(session, pongJsonWebSocketMessage);
}
@Override
public String type() {
return WebSocketMessageTypeEnum.PING.getValue();
}
@Override
public Class getMessageClass() {
return PingJsonWebSocketMessage.class;
}
}