调整即时消息编码
This commit is contained in:
parent
c278217585
commit
52cfb14dae
@ -12,25 +12,31 @@ package ink.wgink.module.instantmessage.websocket.enums;
|
|||||||
*/
|
*/
|
||||||
public enum ClientSocketTypeEnum {
|
public enum ClientSocketTypeEnum {
|
||||||
|
|
||||||
REGISTER(100, "注册消息,body 为 RegisterBody 的 JSON 字符串"),
|
REGISTER(1000, "注册消息,body 为 RegisterBody 的 JSON 字符串"),
|
||||||
MESSAGE(101, "文本消息"),
|
|
||||||
GROUP_MESSAGE(102, "群发文本消息"),
|
MESSAGE(2001, "文本消息"),
|
||||||
SYSTEM_MESSAGE(103, "系统消息"),
|
GROUP_MESSAGE(2002, "群发文本消息"),
|
||||||
SYSTEM_GROUP_MESSAGE(104, "系统群发问呢消息"),
|
|
||||||
SYSTEM_TARGET_MESSAGE(105, "系统目标消息"),
|
SYSTEM_MESSAGE(3001, "系统消息"),
|
||||||
LAYIM_HREF_MESSAGE(106, "LAYIM 连接消息"),
|
SYSTEM_GROUP_MESSAGE(3002, "系统群发问呢消息"),
|
||||||
LAYIM_IMAGE_MESSAGE(107, "LAYIM 图片消息"),
|
SYSTEM_TARGET_MESSAGE(3003, "系统目标消息"),
|
||||||
LAYIM_FILE_MESSAGE(108, "LAYIM 文件消息"),
|
|
||||||
LAYIM_AUDIO_MESSAGE(109, "LAYIM 音频消息"),
|
LAYIM_HREF_MESSAGE(4001, "LAYIM 连接消息"),
|
||||||
LAYIM_VIDEO_MESSAGE(110, "LAYIM 视频消息"),
|
LAYIM_IMAGE_MESSAGE(4002, "LAYIM 图片消息"),
|
||||||
NOTICE(106, "通知"),
|
LAYIM_FILE_MESSAGE(4003, "LAYIM 文件消息"),
|
||||||
NOTICE_GROUP_MESSAGE(107, "群通知"),
|
LAYIM_AUDIO_MESSAGE(4004, "LAYIM 音频消息"),
|
||||||
NOTICE_TARGET_MESSAGE(108, "目标通知,用于APP打开特定页面"),
|
LAYIM_VIDEO_MESSAGE(4005, "LAYIM 视频消息"),
|
||||||
UPDATE_SERVICE_HANDLE_STATUS(501, "更新业务的处理状态"),
|
|
||||||
SEARCH_ONLINE_USER(600, "查询全部在线用户,body 为查询用户的 userId"),
|
NOTICE(5001, "通知"),
|
||||||
SEARCH_ONLINE_USER_FRIEND(601, "查询朋友在线用户,body 为查询用户的 userId"),
|
NOTICE_GROUP_MESSAGE(5002, "群通知"),
|
||||||
SEARCH_COUNT_NEED_TO_DEALT_WITH(602, "查询全部待办总数"),
|
NOTICE_TARGET_MESSAGE(5003, "目标通知,用于APP打开特定页面"),
|
||||||
SEND_STATUS(1100, "发送状态,body 为 BaseResult 的 JSON 字符串"),
|
UPDATE_SERVICE_HANDLE_STATUS(5004, "更新业务的处理状态"),
|
||||||
|
|
||||||
|
SEARCH_ONLINE_USER(6001, "查询全部在线用户,body 为查询用户的 userId"),
|
||||||
|
SEARCH_ONLINE_USER_FRIEND(6002, "查询朋友在线用户,body 为查询用户的 userId"),
|
||||||
|
SEARCH_COUNT_NEED_TO_DEALT_WITH(6003, "查询全部待办总数"),
|
||||||
|
|
||||||
|
SEND_STATUS(1100, "消息发送状态,body 为 BaseResult 的 JSON 字符串"),
|
||||||
SEND_STATUS_ONLINE(1101, "发送在线状态,body 为 在线用户的ID JSONArray 字符串"),
|
SEND_STATUS_ONLINE(1101, "发送在线状态,body 为 在线用户的ID JSONArray 字符串"),
|
||||||
SEND_STATUS_OFFLINE(1102, "发送离线状态,body 为 离线用户的ID JSONArray 字符串");
|
SEND_STATUS_OFFLINE(1102, "发送离线状态,body 为 离线用户的ID JSONArray 字符串");
|
||||||
|
|
||||||
|
@ -11,54 +11,30 @@ package ink.wgink.module.instantmessage.websocket.enums;
|
|||||||
* @Version: 1.0
|
* @Version: 1.0
|
||||||
*/
|
*/
|
||||||
public enum SendStatusEnum {
|
public enum SendStatusEnum {
|
||||||
/**
|
SUCCESS(200, "成功"),
|
||||||
* 成功
|
FAILED(400, "失败"),
|
||||||
*/
|
MESSAGE_ERROR(401, "消息错误"),
|
||||||
SUCCESS(200),
|
SESSION_ERROR(402, "会话错误"),
|
||||||
/**
|
CLIENT_SESSION_ERROR(403, "客户端会话错误"),
|
||||||
* 失败
|
TYPE_ERROR(405, "类型错误"),
|
||||||
*/
|
BODY_ERROR(406, "消息体错误"),
|
||||||
FAILED(300),
|
FROM_ERROR(407, "来源错误"),
|
||||||
/**
|
TO_ERROR(408, "接受用户错误");
|
||||||
* 消息错误
|
|
||||||
*/
|
|
||||||
MESSAGE_ERROR(400),
|
|
||||||
/**
|
|
||||||
* 会话错误
|
|
||||||
*/
|
|
||||||
SESSION_ERROR(402),
|
|
||||||
/**
|
|
||||||
* APP会话错误
|
|
||||||
*/
|
|
||||||
APP_SESSION_ERROR(403),
|
|
||||||
/**
|
|
||||||
* 用户会话错误
|
|
||||||
*/
|
|
||||||
USER_SESSION_ERROR(404),
|
|
||||||
/**
|
|
||||||
* 类型错误
|
|
||||||
*/
|
|
||||||
TYPE_ERROR(405),
|
|
||||||
/**
|
|
||||||
* 消息体错误
|
|
||||||
*/
|
|
||||||
BODY_ERROR(406),
|
|
||||||
/**
|
|
||||||
* 来源错误
|
|
||||||
*/
|
|
||||||
FROM_ERROR(407),
|
|
||||||
/**
|
|
||||||
* 接受用户错误
|
|
||||||
*/
|
|
||||||
TO_ERROR(408);
|
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
private String summary;
|
||||||
|
|
||||||
SendStatusEnum(int value) {
|
SendStatusEnum(int value, String summary) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.summary = summary;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getSummary() {
|
||||||
|
return summary == null ? "" : summary.trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,15 +6,16 @@
|
|||||||
<title>聊天测试</title>
|
<title>聊天测试</title>
|
||||||
<style>
|
<style>
|
||||||
.websocket-line {padding: 5px 0;}
|
.websocket-line {padding: 5px 0;}
|
||||||
.websocket-input {width: 244px; height: 21px; border: 1px solid silver;}
|
.websocket-input {width: 234px; height: 23px; border: 1px solid silver; padding: 0 5px;}
|
||||||
.websocket-container {width: 300px;}
|
.websocket-container {width: 295px;}
|
||||||
.websocket-history-box {height: 400px; border: 1px solid silver; overflow: auto;}
|
.websocket-history-box {height: 400px; border: 1px solid silver; overflow: auto;}
|
||||||
.websocket-box {padding: 5px 0; text-align: right;}
|
.websocket-box {padding: 5px 0; text-align: right;}
|
||||||
.message {display: inline-block; max-width: 195px; font-size: 13px; margin: 10px; padding: 5px; border-radius: 5px;}
|
.message {display: inline-block; max-width: 195px; font-size: 13px; margin: 10px; padding: 5px; border-radius: 5px;}
|
||||||
.receive-msg-box {}
|
.receive-msg-box {}
|
||||||
.receive-msg {background-color: #04b304; color: #FFFFFF;}
|
.receive-msg {background-color: #04b304; color: #FFFFFF;}
|
||||||
.send-msg-box {text-align: right;}
|
.send-msg-box {text-align: right;}
|
||||||
.send-msg {text-align: left; background-color: #c5c5c5; color: #000000;}
|
.send-msg {text-align: left; background-color: #c5c5c5; color: #000000; margin: 10px 10px 10px 0;}
|
||||||
|
.send-status {width: 20px; height: 20px; border-radius: 10px; background-color: red; display: inline-block;text-align: center; color: #FFF; vertical-align: middle;}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@ -26,32 +27,28 @@
|
|||||||
<option value="wss://">wss://</option>
|
<option value="wss://">wss://</option>
|
||||||
</select>
|
</select>
|
||||||
<span id="webSocketUrl" th:text="${webSocketUrl}"></span>
|
<span id="webSocketUrl" th:text="${webSocketUrl}"></span>
|
||||||
|
<input id="currentUserId" class="websocket-input" type="hidden" th:value="${currentUserId}"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="websocket-line">
|
<div class="websocket-line">
|
||||||
当前用户ID <input id="currentUserId" class="websocket-input" type="text" th:value="${currentUserId}" readonly style="width: 208px;"/>
|
接收用户ID <input id="toUserId" class="websocket-input" type="text" style="width: 198px;" placeholder="输入接收用户ID"/>
|
||||||
</div>
|
|
||||||
<div class="websocket-line">
|
|
||||||
接收用户ID <input id="toUserId" class="websocket-input" type="text" style="width: 208px;"/>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="websocket-line">
|
<div class="websocket-line">
|
||||||
<input id="clientName" class="websocket-input" type="text" placeholder="请输入客户端名称"/>
|
<input id="clientName" class="websocket-input" type="text" placeholder="请输入客户端名称"/>
|
||||||
<button id="loginBtn" onclick="login()">登录</button>
|
<button id="loginBtn" onclick="login()">登录</button>
|
||||||
<button id="closeBtn" style="display: none;">关闭</button>
|
<button id="closeBtn" style="display: none;" onclick="closeWebSocket()">关闭</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="websocket-line">
|
<div class="websocket-line" style="font-size: 12px;">
|
||||||
状态:<span id="loginStatus">未登录</span>
|
状态:<span id="loginStatus">未登录</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="websocketHistoryBox" class="websocket-history-box">
|
<div id="websocketHistoryBox" class="websocket-history-box">
|
||||||
<!--
|
|
||||||
<div class="receive-msg-box">
|
<div class="receive-msg-box">
|
||||||
<div class="message receive-msg">收到</div>
|
<div class="message receive-msg">收到</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="send-msg-box">
|
<div class="send-msg-box">
|
||||||
<div class="message send-msg">发送</div>
|
<span class="send-status" title="用户不存在">!</span> <div class="message send-msg">发送</div>
|
||||||
</div>
|
</div>
|
||||||
-->
|
|
||||||
</div>
|
</div>
|
||||||
<div class="websocket-box">
|
<div id="sendBox" class="websocket-box" style="display: none;">
|
||||||
<input type="text" id="message" class="websocket-input" placeholder="请输入发送内容"/>
|
<input type="text" id="message" class="websocket-input" placeholder="请输入发送内容"/>
|
||||||
<button id="login" onclick="send()">发送</button>
|
<button id="login" onclick="send()">发送</button>
|
||||||
</div>
|
</div>
|
||||||
@ -61,6 +58,20 @@
|
|||||||
<script type="text/javascript" src="assets/js/restajax.js"></script>
|
<script type="text/javascript" src="assets/js/restajax.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var websocket;
|
var websocket;
|
||||||
|
|
||||||
|
function register(sessionId) {
|
||||||
|
var registBody = {
|
||||||
|
id: new Date().getTime(),
|
||||||
|
type: 100,
|
||||||
|
from: $('#currentUserId').val(),
|
||||||
|
to: $('#currentUserId').val(),
|
||||||
|
body: {
|
||||||
|
sessionId: sessionId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
websocket.send(JSON.stringify(registBody));
|
||||||
|
}
|
||||||
|
|
||||||
function initWebSocket(sessionId) {
|
function initWebSocket(sessionId) {
|
||||||
if ('WebSocket' in window) {
|
if ('WebSocket' in window) {
|
||||||
websocket = new WebSocket($('#scheme').val() + $('#webSocketUrl').html());
|
websocket = new WebSocket($('#scheme').val() + $('#webSocketUrl').html());
|
||||||
@ -83,16 +94,19 @@
|
|||||||
websocket.onmessage = function (event) {
|
websocket.onmessage = function (event) {
|
||||||
var data = JSON.parse(event.data);
|
var data = JSON.parse(event.data);
|
||||||
// 注册
|
// 注册
|
||||||
if(data.type == 100) {
|
if(data.type === 100) {
|
||||||
var body = JSON.parse(data.body);
|
var body = JSON.parse(data.body);
|
||||||
if(body.code == 200) {
|
if(body.code === 200) {
|
||||||
$('#loginStatus').html('已连接');
|
$('#loginStatus').html('已连接');
|
||||||
} else {
|
} else {
|
||||||
$('#loginStatus').html(body.msg);
|
$('#loginStatus').html(body.msg);
|
||||||
}
|
}
|
||||||
} else if(data.type == 101) {
|
} else if(data.type === 101) {
|
||||||
var body = data.body;
|
var body = data.body;
|
||||||
$('#websocketHistoryBox').append('<div class="receive-msg-box"><div class="message receive-msg">'+ body +'</div></div>');
|
$('#websocketHistoryBox').append('<div class="receive-msg-box"><div class="message receive-msg">'+ body +'</div></div>');
|
||||||
|
} else if(data.type === 1100) {
|
||||||
|
var body = JSON.parse(data.body);
|
||||||
|
$('#'+ data.id).before('<span class="send-status" title="'+ body.msg +'">!</span> ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//连接关闭的回调方法
|
//连接关闭的回调方法
|
||||||
@ -105,19 +119,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(sessionId) {
|
|
||||||
var registBody = {
|
|
||||||
id: new Date().getTime(),
|
|
||||||
type: 100,
|
|
||||||
from: $('#currentUserId').val(),
|
|
||||||
to: $('#currentUserId').val(),
|
|
||||||
body: {
|
|
||||||
sessionId: sessionId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
websocket.send(JSON.stringify(registBody));
|
|
||||||
}
|
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
if(!$('#toUserId').val()) {
|
if(!$('#toUserId').val()) {
|
||||||
alert('请输入接收用户ID');
|
alert('请输入接收用户ID');
|
||||||
@ -133,6 +134,7 @@
|
|||||||
$('#closeBtn').show();
|
$('#closeBtn').show();
|
||||||
$('#clientName').attr('disabled', 'disabled');
|
$('#clientName').attr('disabled', 'disabled');
|
||||||
$('#toUserId').attr('disabled', 'disabled');
|
$('#toUserId').attr('disabled', 'disabled');
|
||||||
|
$('#sendBox').show();
|
||||||
initWebSocket(sessionId);
|
initWebSocket(sessionId);
|
||||||
}, function(code, data) {
|
}, function(code, data) {
|
||||||
alert(data.msg);
|
alert(data.msg);
|
||||||
@ -148,58 +150,30 @@
|
|||||||
alert('请输入内容');
|
alert('请输入内容');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var sendId = new Date().getTime();
|
||||||
var sendBody = {
|
var sendBody = {
|
||||||
id: new Date().getTime(),
|
id: sendId,
|
||||||
type: 101,
|
type: 101,
|
||||||
from: $('#currentUserId').val(),
|
from: $('#currentUserId').val(),
|
||||||
to: $('#toUserId').val(),
|
to: $('#toUserId').val(),
|
||||||
body: $('#message').val()
|
body: $('#message').val()
|
||||||
}
|
}
|
||||||
websocket.send(JSON.stringify(sendBody));
|
websocket.send(JSON.stringify(sendBody));
|
||||||
$('#websocketHistoryBox').append('<div class="send-msg-box"><div class="message send-msg">'+ $('#message').val() +'</div></div>');
|
$('#websocketHistoryBox').append('<div class="send-msg-box"><div id="'+ sendId +'" class="message send-msg">'+ $('#message').val() +'</div></div>');
|
||||||
$('#message').val('')
|
$('#message').val('');
|
||||||
|
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeWebSocket() {
|
||||||
|
websocket.close();
|
||||||
|
$('#loginBtn').show();
|
||||||
|
$('#closeBtn').hide();
|
||||||
|
$('#clientName').removeAttr('disabled');
|
||||||
|
$('#toUserId').removeAttr('disabled');
|
||||||
|
$('#sendBox').hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// //判断当前浏览器是否支持WebSocket
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //将消息显示在网页上
|
|
||||||
// function setMessageInnerHTML(innerHTML) {
|
|
||||||
// document.getElementById('message').innerHTML += innerHTML + '<br/>';
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //关闭连接
|
|
||||||
// function closeWebSocket() {
|
|
||||||
// websocket.close();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// var count = 0;
|
|
||||||
// //发送消息
|
|
||||||
// function send() {
|
|
||||||
// var message = document.getElementById('text').value;
|
|
||||||
// if (count == 0) {
|
|
||||||
// var registBody = {
|
|
||||||
// id: new Date().getTime(),
|
|
||||||
// type: 100,
|
|
||||||
// from: '1',
|
|
||||||
// to: '1',
|
|
||||||
// body: {
|
|
||||||
// sessionId: message
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// websocket.send(JSON.stringify(registBody));
|
|
||||||
// } else {
|
|
||||||
// var sendBody = {
|
|
||||||
// id: new Date().getTime(),
|
|
||||||
// type: 101,
|
|
||||||
// from: '1',
|
|
||||||
// to: '1',
|
|
||||||
// body: message
|
|
||||||
// }
|
|
||||||
// websocket.send(JSON.stringify(sendBody));
|
|
||||||
// }
|
|
||||||
// count++;
|
|
||||||
// }
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user