聊天
This commit is contained in:
@@ -61,9 +61,8 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<Message> {
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext ctx, Message msg) throws Exception {
|
||||
logger.info("***********************收到消息:{}", msg);
|
||||
logger.info("***********************收到消息:{}", msg);
|
||||
logger.info("***********************收到消息:{}", msg);
|
||||
// logger.info("***********************收到消息:{}", msg);
|
||||
// logger.info("***********************收到消息:{}", msg);
|
||||
|
||||
Integer command = msg.getMessageHeader().getCommand();
|
||||
|
||||
@@ -149,6 +148,9 @@ public class NettyServerHandler extends SimpleChannelInboundHandler<Message> {
|
||||
ctx.channel().attr(AttributeKey.valueOf(Constants.ReadTime)).set(System.currentTimeMillis());
|
||||
}else if(command == MessageCommand.MSG_P2P.getCommand()
|
||||
|| command == GroupEventCommand.MSG_GROUP.getCommand()){
|
||||
logger.info("***********************收到单聊或者群聊消息:{}", msg);
|
||||
|
||||
|
||||
try {
|
||||
String toId = "";
|
||||
CheckSendMessageReq req = new CheckSendMessageReq();
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export default class config{
|
||||
static getBaseApiUrl(){
|
||||
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:8989' :'http://www.shudong.xyz/shudong_api/';
|
||||
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:8989' :'http://192.168.1.117:8989';
|
||||
}
|
||||
static getImApiUrl(){
|
||||
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:28000/v1' :'http://www.shudong.xyz/shudong_api/';
|
||||
return process.env.NODE_ENV === 'development' ? 'http://192.168.1.117:28000/v1' :'http://192.168.1.117:28000/v1';
|
||||
}
|
||||
static getImAppId(){
|
||||
return 10000;
|
||||
|
||||
@@ -265,12 +265,14 @@ export default {
|
||||
}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
http.request({
|
||||
url:url+'&pageNum='+(queryParams.refreshing ? 1 : queryParams.pageNum) +'&pageSize=' +queryParams.pageSize,
|
||||
url: url + '&pageNum=' + (queryParams.refreshing ? 1 : queryParams.pageNum) +
|
||||
'&pageSize=' + queryParams.pageSize,
|
||||
success: res => {
|
||||
if (res.data.code == 200) {
|
||||
let list = [];
|
||||
let data = res.data.rows;
|
||||
if (queryParams.refreshing&&res.data.rows == ''||queryParams.refreshing&&res.data.rows.length==0) {
|
||||
if (queryParams.refreshing && res.data.rows == '' || queryParams
|
||||
.refreshing && res.data.rows.length == 0) {
|
||||
queryParams.status = 'noMore'
|
||||
resolve({
|
||||
queryParams: queryParams,
|
||||
@@ -325,16 +327,24 @@ export default {
|
||||
console.log(resbody)
|
||||
var pushType = resbody.pushType //推送类型
|
||||
if (pushType == 'MSG') {
|
||||
/*
|
||||
if(resbody.msgContent.msgType=='TRTC_VOICE_START'||resbody.msgContent.msgType=='TRTC_VIDEO_START'){
|
||||
//音视频开始拦截
|
||||
return
|
||||
}
|
||||
var userId=resbody.fromInfo.userId
|
||||
*/
|
||||
var userId = resbody.userId
|
||||
var windowType = 'SINGLE'
|
||||
/*
|
||||
if(resbody.groupInfo.userId){
|
||||
userId=resbody.groupInfo.userId
|
||||
windowType='GROUP'
|
||||
}
|
||||
*/
|
||||
const _userId = uni.getStorageSync("userId")
|
||||
|
||||
debugger
|
||||
|
||||
this.pushInMsg({
|
||||
type: resbody.msgContent.msgType == 'ALERT' ? 3 : 1, //显示类型 1左侧 2右侧 3中间
|
||||
msgContent: resbody.msgContent.content, //msg内容
|
||||
@@ -343,12 +353,13 @@ export default {
|
||||
time: resbody.createTime, //时间
|
||||
fromInfo: resbody.fromInfo, //来源信息
|
||||
groupInfo: resbody.groupInfo, //群信息
|
||||
userId: userId,//talktoId
|
||||
userId: _userId, //talktoId
|
||||
personId: resbody.fromInfo.userId,
|
||||
msgId: resbody.msgId, //消息Id
|
||||
disturb: resbody.msgContent.disturb, //是否静默消息
|
||||
top: resbody.msgContent.top //是否置顶
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
if (pushType == 'NOTICE') { //红点通知等
|
||||
@@ -444,25 +455,36 @@ export default {
|
||||
if (msgType == 'TRTC_VIDEO_END') {
|
||||
msgTypeLabel = '[视频通话]'
|
||||
}
|
||||
console.log(userId)
|
||||
debugger
|
||||
store.dispatch('createChatObj', {
|
||||
userId: userId,
|
||||
windowType: windowType,
|
||||
}).then(res => {
|
||||
debugger
|
||||
var localData = res.data
|
||||
store.dispatch('getchatDatalist');
|
||||
store.dispatch('getChatList');
|
||||
var chatWindowData = store.state.chatDatalist[userId].list
|
||||
var chatListInfo = store.state.chatlist[userId]
|
||||
// 找到数组中对象属性值一样的对象并返回
|
||||
function arrfindobject({arr,object,key}){
|
||||
function arrfindobject({
|
||||
arr,
|
||||
object,
|
||||
key
|
||||
}) {
|
||||
var result = arr.find(item => {
|
||||
return item[key] == object[key]
|
||||
});
|
||||
return result
|
||||
}
|
||||
var same=arrfindobject({arr:chatWindowData,object:{
|
||||
var same = arrfindobject({
|
||||
arr: chatWindowData,
|
||||
object: {
|
||||
msgId: msgId
|
||||
},key:'msgId'})
|
||||
},
|
||||
key: 'msgId'
|
||||
})
|
||||
if (same) {
|
||||
return
|
||||
}
|
||||
@@ -646,6 +668,40 @@ export default {
|
||||
type: 3
|
||||
};
|
||||
var msgSendType = 'wating';
|
||||
|
||||
//开始发送消息
|
||||
store.dispatch('sendMsg', {
|
||||
userId: userId,
|
||||
data: msgOnlie
|
||||
});
|
||||
|
||||
// TODO
|
||||
// 发送完成之后设置消息状态
|
||||
|
||||
// msgSendType = 'error';
|
||||
msgOffline.sendtype = msgSendType;
|
||||
msgOffline.msgId = "1231"
|
||||
msgNotSend.content = msgOnlie.content;
|
||||
msgList.content = msgOnlie.content;
|
||||
|
||||
chatWindowData.push(msgOffline);
|
||||
if (msgSendType == 'error') {
|
||||
chatWindowData.push(msgNotSend);
|
||||
}
|
||||
store.dispatch('updateChatById', {
|
||||
userId: userId,
|
||||
data: chatWindowData
|
||||
});
|
||||
store.dispatch('updateChatListInfoById', {
|
||||
userId: userId,
|
||||
data: msgList
|
||||
});
|
||||
store.dispatch('tabBarpull');
|
||||
store.dispatch('updateChatDataState', userId);
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
http.request({
|
||||
url: url,
|
||||
method: 'POST',
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import config from "@/common/config.js"
|
||||
let timer = null
|
||||
let retimer = null
|
||||
|
||||
import store from '../store'
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
|
||||
@@ -30,15 +30,35 @@ export default {
|
||||
},
|
||||
onTestMessage: (e) => {
|
||||
console.log("onTestMessage :" + e);
|
||||
store.dispatch('onP2PMessage',e)
|
||||
},
|
||||
onP2PMessage: (e) => {
|
||||
console.log("onP2PMessage :" + e);
|
||||
e = JSON.parse(e)
|
||||
e.pushType="TEXT"
|
||||
e.data.pushType="MSG"
|
||||
e.data.msgContent={
|
||||
msgType:"UNKOWN",
|
||||
content:e.data.messageBody,
|
||||
disturb:false,
|
||||
top:false,
|
||||
}
|
||||
|
||||
e.data.windowType="SINGLE"
|
||||
e.data.createTime=e.data.messageTime;
|
||||
e.data.fromInfo={
|
||||
userId:e.data.fromId
|
||||
};
|
||||
e.data.groupInfo={};
|
||||
e.data.msgId=e.data.messageId;
|
||||
|
||||
debugger
|
||||
uni.$emit('onP2PMessage', e.data);
|
||||
store.dispatch('onP2PMessage',e.data)
|
||||
},
|
||||
onLogin: (uid) => {
|
||||
console.log("用户" + uid + "登陆sdk成功");
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -54,6 +74,7 @@ export default {
|
||||
|
||||
console.log(lim)
|
||||
|
||||
// 防止多次建立ws链接,貌似还没有生效,需要检查
|
||||
if (this.socketTask != null) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name" : "微聊",
|
||||
"appid" : "__UNI__CA19A2D",
|
||||
"description" : "考拉Team微聊",
|
||||
"name" : "IM",
|
||||
"appid" : "__UNI__1A208D0",
|
||||
"description" : "HS-IM",
|
||||
"versionName" : "1.2.1",
|
||||
"versionCode" : 121,
|
||||
"developer" : {
|
||||
|
||||
@@ -9,9 +9,10 @@ const store = new Vuex.Store({
|
||||
|
||||
|
||||
import * as sdk from "@/common/imSdk/lim-sdk.js";
|
||||
|
||||
import lim from "@/common/imSdk/sdk-bridge.js";
|
||||
|
||||
const _im=lim.lim.im
|
||||
|
||||
// #ifdef VUE3
|
||||
import { createStore } from 'vuex'
|
||||
const store = createStore({
|
||||
@@ -52,6 +53,21 @@ import { createStore } from 'vuex'
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
onP2PMessage(context,data){
|
||||
console.log("========================store 收到信息")
|
||||
console.log("========================store 收到信息")
|
||||
console.log("========================store 收到信息")
|
||||
console.error(data)
|
||||
publicFc.getPush(data)
|
||||
|
||||
},
|
||||
sendMsg(context,data){
|
||||
console.log("========================")
|
||||
console.log("========================")
|
||||
console.log("========================")
|
||||
console.error(data)
|
||||
_im.sendP2PMessage(_im.createP2PTextMessage(data.userId,data.data.content))
|
||||
},
|
||||
updateChatDataState(context,data){
|
||||
context.state.chatDataState++
|
||||
context.state.chatDataUserId=data
|
||||
@@ -118,15 +134,19 @@ import { createStore } from 'vuex'
|
||||
context.commit('update_ChatList',data)
|
||||
},
|
||||
updateChatListInfoById(context,data) {//修改聊天记录
|
||||
console.log("修改聊天记录 2")
|
||||
var getKey=data.userId
|
||||
var retdata=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||
retdata[getKey]=data.data
|
||||
uni.setStorageSync(context.state.userInfo.userId+'_'+'chatlistData', JSON.stringify(retdata));
|
||||
},
|
||||
createChatObj(context,data){
|
||||
|
||||
console.log("修改聊天记录 3")
|
||||
console.log("context.state.userInfo.userId:",context.state.userInfo.userId)
|
||||
console.log("data.userId:",data.userId)
|
||||
var userId=data.userId
|
||||
var windowType=data.windowType
|
||||
debugger
|
||||
//初始化聊天记录
|
||||
var data2=publicFc.getKeyObjectStorage(context.state.userInfo.userId+'_'+'chatlistData')
|
||||
if(!data2[userId]){
|
||||
@@ -145,7 +165,7 @@ import { createStore } from 'vuex'
|
||||
// console.warn(res)
|
||||
// })
|
||||
|
||||
lim.lim.im.getSingleUserInfo(userId).then((res)=>{
|
||||
_im.getSingleUserInfo(userId).then((res)=>{
|
||||
console.log(res.data)
|
||||
console.log(res.data)
|
||||
console.log(res.data)
|
||||
@@ -155,7 +175,7 @@ import { createStore } from 'vuex'
|
||||
data1[userId]={
|
||||
fromInfo:{
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.portrait,
|
||||
portrait: detail.photo,
|
||||
userId: detail.userId,
|
||||
userType:detail.userType
|
||||
},
|
||||
@@ -169,7 +189,7 @@ import { createStore } from 'vuex'
|
||||
userId: detail.userId,
|
||||
personId: context.state.userInfo.userId,
|
||||
nickName: detail.nickName,
|
||||
portrait: detail.portrait,
|
||||
portrait: detail.photo,
|
||||
content: '',
|
||||
time: publicFc.getNewDate('format',true),
|
||||
num: 0,
|
||||
|
||||
@@ -174,7 +174,7 @@
|
||||
onLoad(e) {
|
||||
|
||||
// // 监听接收聊天信息
|
||||
uni.$on('onP2PMessage', this.onMessage)
|
||||
// uni.$on('onP2PMessage', this.onMessage)
|
||||
|
||||
this.talkTo = e;
|
||||
// 根据Id
|
||||
@@ -263,27 +263,6 @@
|
||||
},
|
||||
methods: {
|
||||
onMessage(message) {
|
||||
console.log('[聊天页] 监听接收聊天信息', message);
|
||||
if (message.fromId != this.talkTo.userId) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[聊天页] 监听接收聊天信息', message);
|
||||
|
||||
this.$fc.getPush(data);
|
||||
|
||||
// var messageBody = message
|
||||
|
||||
// let msg = {
|
||||
// userId: message.fromId,
|
||||
// avatar: "/static/images/userpic.png",
|
||||
// data: messageBody.messageBody == '' ? '空消息' : messageBody.messageBody,
|
||||
// nickname: message.fromId,
|
||||
// type: "text",
|
||||
// createTime: message.messageTime / 1000,
|
||||
// isRemove: false
|
||||
// }
|
||||
// this.list.push(msg)
|
||||
|
||||
},
|
||||
addMsg(e) {
|
||||
|
||||
@@ -35,26 +35,26 @@
|
||||
var list=[
|
||||
{
|
||||
name:"测试18200702230",
|
||||
avatar:"item.portrait",
|
||||
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||
userId:"18200702230",
|
||||
userType:"item.userType",
|
||||
chatNo:"item.chatNo"
|
||||
},
|
||||
{
|
||||
name:"测试18200000000",
|
||||
avatar:"item.portrait",
|
||||
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||
userId:"18200000000",
|
||||
userType:"item.userType",
|
||||
chatNo:"item.chatNo"
|
||||
},{
|
||||
name:"测试18200000001",
|
||||
avatar:"item.portrait",
|
||||
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||
userId:"18200000001",
|
||||
userType:"item.userType",
|
||||
chatNo:"item.chatNo"
|
||||
},{
|
||||
name:"测试lld3",
|
||||
avatar:"item.portrait",
|
||||
avatar:"https://shudong2022.oss-cn-hangzhou.aliyuncs.com/common/user/logo.png",
|
||||
userId:"lld3",
|
||||
userType:"item.userType",
|
||||
chatNo:"item.chatNo"
|
||||
|
||||
@@ -154,6 +154,7 @@ export class ImClient {
|
||||
let bodyLen = byteBuffer[1];//解析bodylen
|
||||
let unpack = bytebuf.vstring(null, bodyLen).unpack();//解析出字符串
|
||||
let msgBody = unpack[2];
|
||||
console.log("sdk收到服务端数据 command:" + command)
|
||||
console.log("sdk收到服务端数据:" + msgBody)
|
||||
|
||||
if (command === MessageCommand.MSG_P2P) {
|
||||
|
||||
Reference in New Issue
Block a user