移动端聊天实现
This commit is contained in:
@@ -24,7 +24,10 @@ enum MessageCommand {
|
||||
|
||||
// //消息已读通知 1053
|
||||
MSG_READED_NOTIFY = 0x41D,
|
||||
|
||||
|
||||
// 消息已读回执,给原消息发送方 1054
|
||||
MSG_READED_RECEIPT=0x41E,
|
||||
|
||||
}
|
||||
|
||||
enum FriendShipCommand{
|
||||
|
||||
@@ -20,7 +20,7 @@ export default class HttpApi {
|
||||
let reqUrl = this.url + url;
|
||||
if(params != null){
|
||||
let paramStr = this.setQueryConfig(params)
|
||||
console.log(paramStr);
|
||||
// console.log(paramStr);
|
||||
reqUrl += paramStr;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export default class HttpApi {
|
||||
}).then(res =>{
|
||||
log.info(`==> [${request.method}] ${url} back:` + Beans.json(res));
|
||||
const resp = this.response2ApiResponse(res);
|
||||
console.log(res)
|
||||
// console.log(res)
|
||||
if(resp.isFailed()){
|
||||
return Promise.reject(resp);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ export default class HttpApi {
|
||||
/*IFTRUE_UNIAPP*/
|
||||
let rnfetch1 = Fetch.getFetchToolkit();
|
||||
return rnfetch1(url as string, request).then(response =>{
|
||||
console.log(response)
|
||||
// console.log(response)
|
||||
return response.json();
|
||||
}).then(res =>{
|
||||
log.info(`==> [${request.method}] ${url} back:` + Beans.json(res));
|
||||
|
||||
@@ -54,7 +54,7 @@ export interface IListener {
|
||||
onSocketCloseEvent(): void;//连接关闭事件
|
||||
onP2PMessage(e: any): void;//收到单聊消息事件
|
||||
onTestMessage(e: any): void;//收到消息事件 测试用
|
||||
// onOfflineMessage(data):void; // 拉取到离线消息事件
|
||||
onOfflineMessage(data):void; // 拉取到离线消息事件
|
||||
}
|
||||
|
||||
export class ImClient {
|
||||
@@ -188,6 +188,10 @@ export class ImClient {
|
||||
|
||||
public buildMessagePack(command: number, messagePack: any) {
|
||||
var jsonData = JSON.stringify(messagePack);
|
||||
|
||||
// console.log("=============buildMessagePack=========")
|
||||
// log.info(jsonData);
|
||||
|
||||
let bodyLen = getLen(jsonData);
|
||||
|
||||
let pack = new ByteBuffer(null, 0);
|
||||
@@ -331,6 +335,48 @@ export class ImClient {
|
||||
this.conn.send(p2pPack.pack(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 消息接收ack
|
||||
public sendP2PMessageReciveAck (rAck: any) {
|
||||
console.log("=============== sendP2PMessageReciveAck")
|
||||
console.log(rAck)
|
||||
rAck.toId = rAck.fromId;
|
||||
rAck.fromId = this.userId;
|
||||
|
||||
console.log(rAck)
|
||||
|
||||
let p2pPack_1107 = imClient.buildMessagePack(MessageCommand.MSG_RECIVE_ACK, rAck);
|
||||
rAck.conversationType=0
|
||||
let p2pPack_1106 = imClient.buildMessagePack(MessageCommand.MSG_READED, rAck);
|
||||
let p2pPack_1054 = imClient.buildMessagePack(MessageCommand.MSG_READED_RECEIPT, rAck);
|
||||
|
||||
|
||||
if (this.conn) {
|
||||
// console.log("=============== sendP2PMessageReciveAck 正式开始消息接收ack")
|
||||
|
||||
this.conn.send(p2pPack_1107.pack(false));
|
||||
this.conn.send(p2pPack_1106.pack(false));
|
||||
this.conn.send(p2pPack_1054.pack(false));
|
||||
}
|
||||
}
|
||||
|
||||
// 消息已读回执,给原消息发送方 1054
|
||||
public sendP2PMessageReadedReceipt (rAck: any) {
|
||||
console.log("=============== sendP2PMessageReadedRECEIPT")
|
||||
console.log(rAck)
|
||||
rAck.toId = rAck.fromId;
|
||||
rAck.fromId = this.userId;
|
||||
|
||||
console.log(rAck)
|
||||
|
||||
let p2pPack = imClient.buildMessagePack(MessageCommand.MSG_READED_RECEIPT, rAck);
|
||||
if (this.conn) {
|
||||
console.log("=============== sendP2PMessageReadedRECEIPT 正式开始发送已读回执")
|
||||
this.conn.send(p2pPack.pack(false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public getUserId() {
|
||||
return this.userId;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export default class Logger {
|
||||
static debug = true;
|
||||
static debug = false;
|
||||
|
||||
static info(message?: any, ...optionalParams: any[]): void {
|
||||
if(Logger.debug){
|
||||
|
||||
Reference in New Issue
Block a user