package com.gyee.wisdom.test;

import com.gyee.wisdom.common.data.timeseries.TsData;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.messaging.simp.stomp.*;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;


public class ClientStompSessionHandler extends StompSessionHandlerAdapter {

    public boolean connect = false;

    @Override
    public void handleFrame(StompHeaders headers, Object payload) {

        System.out.println("测试返回数据");
        Map<String, TsData> map = (Map<String, TsData>) payload;
        System.out.println(payload.toString());
        System.out.println(map);
    }

    @Override
    public void handleException(StompSession s, StompCommand c, StompHeaders h, byte[] p, Throwable ex) {
        System.out.println(ex.getMessage());
    }

    @Override
    public void handleTransportError(StompSession session, Throwable ex) {
        System.out.println(ex.getMessage());
    }

    @Override
    public void afterConnected(final StompSession session, StompHeaders connectedHeaders) {
        System.out.println("websocket连接成功");
        connect = true;
        session.subscribe("/topic/test", new ClientStompFrameHandler());

    }


}
