提交 | 用户 | age
|
a6a76f
|
1 |
package com.yc.sdk.WebSocketMessage.entity; |
F |
2 |
|
|
3 |
import javax.websocket.Session; |
|
4 |
|
f10e31
|
5 |
import com.alibaba.fastjson.JSON; |
a6a76f
|
6 |
import com.yc.action.grid.GridUtils; |
F |
7 |
import com.yc.im.action.WebSocketIMServer; |
|
8 |
|
6990b5
|
9 |
import lombok.Getter; |
J |
10 |
import lombok.Setter; |
a6a76f
|
11 |
|
6990b5
|
12 |
@Setter |
J |
13 |
@Getter |
|
14 |
public class WsMessageUserEntity extends WsUserEntity { |
a6a76f
|
15 |
transient Session session; |
F |
16 |
|
6990b5
|
17 |
public WsMessageUserEntity(String userCode,Integer dbId,String sessionId,String userFromType,Session session) { |
J |
18 |
this.dbId = dbId; |
|
19 |
this.userCode = userCode; |
|
20 |
this.userFromType = userFromType; |
|
21 |
this.sessionId = sessionId; |
|
22 |
this.session = session; |
|
23 |
} |
|
24 |
|
f959ba
|
25 |
public void sendMessage(MessageInfo message){ |
a6a76f
|
26 |
|
F |
27 |
if (!this.session.isOpen()){ |
|
28 |
return; |
|
29 |
} |
|
30 |
synchronized (this.session) { |
f959ba
|
31 |
CallBackMessage info = new CallBackMessage(); |
F |
32 |
//message.setMsgDateTime(new SimpleDateFormat(DateUtil.dateFormatStr,Locale.getDefault()).format(new Date())); |
a6a76f
|
33 |
message.setDbId(this.getDbId()); |
bace30
|
34 |
info.setInfo(message); |
a6a76f
|
35 |
try { |
f10e31
|
36 |
this.session.getBasicRemote().sendText(JSON.toJSONString(info));//用异步发送 |
F |
37 |
} catch (Exception e) { |
|
38 |
e.printStackTrace(); |
|
39 |
WebSocketIMServer.printError(e,this.session); |
|
40 |
} |
|
41 |
} |
|
42 |
} |
|
43 |
public void sendMessageV2(Object message){ |
|
44 |
|
|
45 |
if (!this.session.isOpen()){ |
|
46 |
return; |
|
47 |
} |
|
48 |
synchronized (this.session) { |
|
49 |
CallBackMessage info = new CallBackMessage(); |
|
50 |
info.setInfo(message); |
|
51 |
try { |
|
52 |
this.session.getBasicRemote().sendText(JSON.toJSONString(info));//用异步发送 |
a6a76f
|
53 |
} catch (Exception e) { |
F |
54 |
e.printStackTrace(); |
|
55 |
WebSocketIMServer.printError(e,this.session); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
|
59 |
} |