package com.yc.sdk.WebSocketMessage.entity;
|
|
import javax.websocket.Session;
|
|
import com.alibaba.fastjson.JSON;
|
import com.yc.action.grid.GridUtils;
|
import com.yc.im.action.WebSocketIMServer;
|
|
import lombok.Getter;
|
import lombok.Setter;
|
|
@Setter
|
@Getter
|
public class WsMessageUserEntity extends WsUserEntity {
|
transient Session session;
|
|
public WsMessageUserEntity(String userCode,Integer dbId,String sessionId,String userFromType,Session session) {
|
this.dbId = dbId;
|
this.userCode = userCode;
|
this.userFromType = userFromType;
|
this.sessionId = sessionId;
|
this.session = session;
|
}
|
|
public void sendMessage(MessageInfo message){
|
|
if (!this.session.isOpen()){
|
return;
|
}
|
synchronized (this.session) {
|
CallBackMessage info = new CallBackMessage();
|
//message.setMsgDateTime(new SimpleDateFormat(DateUtil.dateFormatStr,Locale.getDefault()).format(new Date()));
|
message.setDbId(this.getDbId());
|
info.setInfo(message);
|
try {
|
this.session.getBasicRemote().sendText(JSON.toJSONString(info));//用异步发送
|
} catch (Exception e) {
|
e.printStackTrace();
|
WebSocketIMServer.printError(e,this.session);
|
}
|
}
|
}
|
public void sendMessageV2(Object message){
|
|
if (!this.session.isOpen()){
|
return;
|
}
|
synchronized (this.session) {
|
CallBackMessage info = new CallBackMessage();
|
info.setInfo(message);
|
try {
|
this.session.getBasicRemote().sendText(JSON.toJSONString(info));//用异步发送
|
} catch (Exception e) {
|
e.printStackTrace();
|
WebSocketIMServer.printError(e,this.session);
|
}
|
}
|
}
|
}
|