WebsocketConstants.java 1.54 KB
package com.huaheng.mobilewms.websocket;

import com.huaheng.mobilewms.bean.Constant;
import com.huaheng.mobilewms.util.WMSUtils;

public class WebsocketConstants {

    //客户端发送心跳的最小间隔
    public final static int HEART_BEAT_CLIENT = 50000;
    //期望服务端发送心跳的间隔
    public final static int HEART_BEAT_SERVER = 50000;
    //上行消息地址
    public final static String UP_STRING_MESSAGE_DEST = "/app/websocket/message/string";
    public final static String UP_JSON_MESSAGE_DEST = "/app/websocket/message/json";
    public final static String UP_CONFIRM_MESSAGE_DEST = "/app/websocket/message/confirm";

    //建立websocket握手的http地址后缀
    public final static String URI_SUFFIX = "endpoint/websocket";

    //订阅广播消息话题地址
    public final static String SUBSCRIBE_TOPIC_MESSAGE = "/topic/message";
    //订阅用户消息话题地址
    public final static String SUBSCRIBE_USER_TOPIC_MESSAGE = "/user/topic/message";

    public final static String HEADER_MEG_ID = "msg-id";

    public static String getUri(){
        String httpNet = WMSUtils.getData(Constant.NETWORK);
        String uri = "";
//                .replaceFirst("http","ws");
        if(httpNet.startsWith("http")){
            uri = httpNet.replaceFirst("http", "ws");
        }
        if(httpNet.startsWith("https")){
            uri = httpNet.replaceFirst("https", "wss");
        }
        if(uri.endsWith("/")){
            return uri + URI_SUFFIX;
        }else{
            return uri + "/" + URI_SUFFIX;
        }
    }
}