im ok
BIN
static/images/Arrow-Left.png
Normal file
|
After Width: | Height: | Size: 222 B |
BIN
static/images/Avatar-1.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
static/images/Avatar-2.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
static/images/Avatar-3.png
Normal file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
static/images/Avatar-4.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
BIN
static/images/Vector.png
Normal file
|
After Width: | Height: | Size: 714 B |
BIN
static/images/action.png
Normal file
|
After Width: | Height: | Size: 203 B |
BIN
static/images/audioImage/play.gif
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
static/images/audioImage/voice.png
Normal file
|
After Width: | Height: | Size: 300 B |
BIN
static/images/chat-active.png
Normal file
|
After Width: | Height: | Size: 573 B |
BIN
static/images/chat.png
Normal file
|
After Width: | Height: | Size: 802 B |
BIN
static/images/contacts-active.png
Normal file
|
After Width: | Height: | Size: 588 B |
BIN
static/images/contacts.png
Normal file
|
After Width: | Height: | Size: 830 B |
BIN
static/images/dingdan.png
Normal file
|
After Width: | Height: | Size: 840 B |
BIN
static/images/emoji.png
Normal file
|
After Width: | Height: | Size: 717 B |
BIN
static/images/failed.png
Normal file
|
After Width: | Height: | Size: 292 B |
BIN
static/images/file-content.png
Normal file
|
After Width: | Height: | Size: 808 B |
BIN
static/images/file-icon.png
Normal file
|
After Width: | Height: | Size: 372 B |
BIN
static/images/file.png
Normal file
|
After Width: | Height: | Size: 463 B |
BIN
static/images/goeasy.jpeg
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
static/images/green-dot.png
Normal file
|
After Width: | Height: | Size: 373 B |
BIN
static/images/group-icon.png
Normal file
|
After Width: | Height: | Size: 502 B |
BIN
static/images/group.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
static/images/im.gif
Normal file
|
After Width: | Height: | Size: 306 KiB |
BIN
static/images/jianpan.png
Normal file
|
After Width: | Height: | Size: 932 B |
BIN
static/images/loading.gif
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
static/images/mine-active.png
Normal file
|
After Width: | Height: | Size: 503 B |
BIN
static/images/mine.png
Normal file
|
After Width: | Height: | Size: 770 B |
BIN
static/images/more.png
Normal file
|
After Width: | Height: | Size: 664 B |
BIN
static/images/pending.gif
Normal file
|
After Width: | Height: | Size: 771 B |
BIN
static/images/record-appearance-icon.png
Normal file
|
After Width: | Height: | Size: 620 B |
BIN
static/images/recordImage/loading.gif
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
static/images/shipin.png
Normal file
|
After Width: | Height: | Size: 1009 B |
BIN
static/images/tupian.png
Normal file
|
After Width: | Height: | Size: 972 B |
BIN
static/images/uniapp.png
Normal file
|
After Width: | Height: | Size: 1.0 KiB |
BIN
static/images/videoImage/play.png
Normal file
|
After Width: | Height: | Size: 560 B |
BIN
static/images/wx.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
static/images/zidingyi.png
Normal file
|
After Width: | Height: | Size: 900 B |
33
static/lib/EmojiDecoder.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @Author: jack.lu
|
||||
* @Date: 2020/9/11
|
||||
* @Last Modified by: jack.lu
|
||||
* @Last Modified time: 2020/9/11 4:35 下午
|
||||
*/
|
||||
|
||||
class EmojiDecoder {
|
||||
emojiMap = null;
|
||||
url = "";
|
||||
patterns = [];
|
||||
metaChars = /[[\]{}()*+?.\\|^$\-,&#\s]/g;
|
||||
decode = this.decode;
|
||||
|
||||
constructor(url,emojiMap) {
|
||||
this.url = url || '';
|
||||
this.emojiMap = emojiMap || {};
|
||||
for (let i in this.emojiMap) {
|
||||
if (this.emojiMap.hasOwnProperty(i)){
|
||||
this.patterns.push('('+i.replace(this.metaChars, "\\$&")+')');
|
||||
}
|
||||
}
|
||||
console.log(this)
|
||||
}
|
||||
|
||||
decode (text) {
|
||||
return text.replace(new RegExp(this.patterns.join('|'),'g'), (match) => {
|
||||
return typeof this.emojiMap[match] != 'undefined' ? '<img height="20rpx" width="20rpx" src="'+this.url+this.emojiMap[match]+'" />' : match;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default EmojiDecoder
|
||||
2
static/lib/goeasy-im-1.5.1.js
Normal file
205
static/lib/imservice.js
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* @Author: jack.lu
|
||||
* @Date: 2020-4-21 10:10:20
|
||||
* @Last Modified by: jack.lu
|
||||
* @Last Modified time: 2020-4-21 15:01:41
|
||||
*/
|
||||
|
||||
import GoEasyIM from './goeasy-im-1.5.1';
|
||||
import restApi from './restapi';
|
||||
|
||||
function Friend(uuid, name, avatar) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
function Group(uuid, name, avatar) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
function CurrentUser(uuid, name, avatar) {
|
||||
this.uuid = uuid;
|
||||
this.name = name;
|
||||
this.avatar = avatar;
|
||||
}
|
||||
|
||||
function IMService(im) {
|
||||
this.im = im;
|
||||
//当前“我”
|
||||
this.currentUser = null;
|
||||
|
||||
//私聊消息记录,map格式,每个好友对应一个数组
|
||||
this.privateMessages = {};
|
||||
|
||||
//群聊消息记录,map格式,每个群对应一个数组
|
||||
this.groupMessages = {};
|
||||
|
||||
/*
|
||||
* 监听器们
|
||||
*
|
||||
* 可以在页面里,根据需求,重写以下监听器,
|
||||
* 便于当各种事件触发时,页面能够执行对应的响应
|
||||
*
|
||||
*/
|
||||
//收到一条私聊消息
|
||||
this.onNewPrivateMessageReceive = function (friendId, message) {};
|
||||
//收到一条群聊消息
|
||||
this.onNewGroupMessageReceive = function (groupId, message) {};
|
||||
}
|
||||
|
||||
//获取群成员
|
||||
IMService.prototype.getGroupMembers = function (groupId) {
|
||||
let members = restApi.findGroupMembers(groupId);
|
||||
let membersMap = {};
|
||||
members.map(item => {
|
||||
membersMap[item.uuid] = item
|
||||
});
|
||||
return membersMap;
|
||||
};
|
||||
|
||||
IMService.prototype.findGroupById = function (groupId) {
|
||||
let group = restApi.findGroupById(groupId);
|
||||
return new Group(group.uuid, group.name, group.avatar);
|
||||
};
|
||||
|
||||
IMService.prototype.getGroupMessages = function (groupId) {
|
||||
if (!this.groupMessages[groupId]) {
|
||||
this.groupMessages[groupId] = [];
|
||||
}
|
||||
return this.groupMessages[groupId]
|
||||
};
|
||||
|
||||
IMService.prototype.findFriendById = function (userId) {
|
||||
let user = restApi.findUserById(userId);
|
||||
return new Friend(user.uuid, user.name, user.avatar);
|
||||
};
|
||||
|
||||
IMService.prototype.getPrivateMessages = function (friendId) {
|
||||
if (!this.privateMessages[friendId]) {
|
||||
this.privateMessages[friendId] = [];
|
||||
}
|
||||
return this.privateMessages[friendId]
|
||||
};
|
||||
|
||||
//连接GoEasy
|
||||
IMService.prototype.connectIM = function (currentUser) {
|
||||
this.currentUser = currentUser;
|
||||
//初始化IM相关的监听器
|
||||
this.initialIMListeners();
|
||||
this.im.connect({
|
||||
id: this.currentUser.uuid,
|
||||
data: {
|
||||
avatar: this.currentUser.avatar,
|
||||
name: this.currentUser.name
|
||||
}
|
||||
}).then(() => {
|
||||
console.log('connect成功')
|
||||
}).catch(error => {
|
||||
console.log('connect失败,请确保网络正常,appkey和host正确,code:' + error.code + " content:" + error.content);
|
||||
});
|
||||
this.subscribeGroupMessage();
|
||||
};
|
||||
|
||||
IMService.prototype.subscribeGroupMessage = function () {
|
||||
let groups = restApi.findGroups(this.currentUser);
|
||||
let groupIds = groups.map(item => item.uuid);
|
||||
this.im.subscribeGroup(groupIds)
|
||||
.then(() => {
|
||||
console.log('订阅群消息成功')
|
||||
})
|
||||
.catch(error => {
|
||||
console.log('订阅群消息失败')
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
|
||||
//IM监听
|
||||
IMService.prototype.initialIMListeners = function () {
|
||||
this.im.on(GoEasyIM.EVENT.CONNECTED, () => {
|
||||
console.log('连接成功.')
|
||||
});
|
||||
|
||||
this.im.on(GoEasyIM.EVENT.DISCONNECTED, () => {
|
||||
console.log('连接断开.')
|
||||
});
|
||||
|
||||
this.im.on(GoEasyIM.EVENT.CONNECTING, (times) => {
|
||||
console.log('连接中', times);
|
||||
});
|
||||
|
||||
//监听私聊消息
|
||||
this.im.on(GoEasyIM.EVENT.PRIVATE_MESSAGE_RECEIVED, (message) => {
|
||||
//更新私聊消息记录
|
||||
let friendId;
|
||||
if (this.currentUser.uuid == message.senderId) {
|
||||
friendId = message.receiverId;
|
||||
} else {
|
||||
friendId = message.senderId;
|
||||
}
|
||||
let friendMessages = this.getPrivateMessages(friendId);
|
||||
friendMessages.push(message);
|
||||
//如果页面传入了相应的listener,执行listener
|
||||
this.onNewPrivateMessageReceive(friendId, message);
|
||||
});
|
||||
|
||||
//监听群聊消息
|
||||
this.im.on(GoEasyIM.EVENT.GROUP_MESSAGE_RECEIVED, (message) => {
|
||||
let groupId = message.groupId;
|
||||
|
||||
//更新群聊消息记录
|
||||
let groupMessages = this.getGroupMessages(groupId);
|
||||
groupMessages.push(message);
|
||||
|
||||
//如果页面传入了相应的listener,执行listener
|
||||
this.onNewGroupMessageReceive(groupId, message);
|
||||
})
|
||||
};
|
||||
|
||||
//加载单聊历史消息
|
||||
IMService.prototype.loadPrivateHistoryMessage = function (friendId, timeStamp) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.im.history({
|
||||
friendId: friendId,
|
||||
lastTimestamp: timeStamp
|
||||
}).then(result => {
|
||||
let history = result.content;
|
||||
let friendMessages = this.getPrivateMessages(friendId);
|
||||
for (let i = history.length - 1; i >=0; i--) {
|
||||
friendMessages.unshift(history[i])
|
||||
}
|
||||
resolve(friendMessages)
|
||||
}).catch(error => {
|
||||
if (error.code == 401) {
|
||||
console.log("您尚未开通历史消息,请登录GoEasy,查看应用详情里自助启用.");
|
||||
}
|
||||
reject(error)
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
//群聊历史消息
|
||||
IMService.prototype.loadGroupHistoryMessage = function (groupId, timeStamp) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.im.history({
|
||||
groupId: groupId,
|
||||
lastTimestamp: timeStamp
|
||||
}).then(result => {
|
||||
let history = result.content;
|
||||
let chatMessage = this.getGroupMessages(groupId);
|
||||
for (let i = history.length - 1; i >= 0; i--) {
|
||||
chatMessage.unshift(history[i]);
|
||||
}
|
||||
resolve(chatMessage)
|
||||
}).catch(error => {
|
||||
if (error.code == 401) {
|
||||
console.log("您尚未开通历史消息,请登录GoEasy,查看应用详情里自助启用.");
|
||||
}
|
||||
reject(error)
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
export default IMService;
|
||||
94
static/lib/restapi.js
Normal file
@@ -0,0 +1,94 @@
|
||||
//用户数据示例
|
||||
let users = [
|
||||
{
|
||||
"uuid": "08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a",
|
||||
"name": "Mattie",
|
||||
"password": "123",
|
||||
"avatar": '/static/images/Avatar-1.png'
|
||||
},
|
||||
{
|
||||
"uuid": "3bb179af-bcc5-4fe0-9dac-c05688484649",
|
||||
"name": "Wallace",
|
||||
"password": "123",
|
||||
"avatar": '/static/images/Avatar-2.png'
|
||||
},
|
||||
{
|
||||
"uuid": "fdee46b0-4b01-4590-bdba-6586d7617f95",
|
||||
"name": "Tracy",
|
||||
"password": "123",
|
||||
"avatar": '/static/images/Avatar-3.png'
|
||||
},
|
||||
{
|
||||
"uuid": "33c3693b-dbb0-4bc9-99c6-fa77b9eb763f",
|
||||
"name": "Juanita",
|
||||
"password": "123",
|
||||
"avatar": '/static/images/Avatar-4.png'
|
||||
}
|
||||
];
|
||||
|
||||
//群数据示例
|
||||
let groups = [
|
||||
{
|
||||
"uuid": "group-a42b-47b2-bb1e-15e0f5f9a19a",
|
||||
"name": "小程序交流群",
|
||||
"avatar" : '/static/images/wx.png',
|
||||
"userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', '3bb179af-bcc5-4fe0-9dac-c05688484649', 'fdee46b0-4b01-4590-bdba-6586d7617f95', '33c3693b-dbb0-4bc9-99c6-fa77b9eb763f']
|
||||
},
|
||||
{
|
||||
"uuid": "group-4b01-4590-bdba-6586d7617f95",
|
||||
"name": "UniApp交流群",
|
||||
"avatar" : '/static/images/uniapp.png',
|
||||
"userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', 'fdee46b0-4b01-4590-bdba-6586d7617f95', '33c3693b-dbb0-4bc9-99c6-fa77b9eb763f']
|
||||
},
|
||||
{
|
||||
"uuid": "group-dbb0-4bc9-99c6-fa77b9eb763f",
|
||||
"name": "GoEasy交流群",
|
||||
"avatar" : '/static/images/goeasy.jpeg',
|
||||
"userList": ['08c0a6ec-a42b-47b2-bb1e-15e0f5f9a19a', '3bb179af-bcc5-4fe0-9dac-c05688484649']
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
function RestApi() {
|
||||
|
||||
}
|
||||
|
||||
RestApi.prototype.findFriends = function (user) {
|
||||
var friendList = users.filter(v => v.uuid != user.uuid);
|
||||
return friendList;
|
||||
};
|
||||
|
||||
RestApi.prototype.findGroups = function (user) {
|
||||
var groupList = groups.filter(v => v.userList.find(id => id == user.uuid));
|
||||
return groupList;
|
||||
};
|
||||
|
||||
RestApi.prototype.findUser = function (username, password) {
|
||||
var user = users.find(user => (user.name == username && user.password == password))
|
||||
return user;
|
||||
};
|
||||
|
||||
RestApi.prototype.findGroupById = function (groupId) {
|
||||
var group = groups.find(group => (group.uuid == groupId));
|
||||
return group;
|
||||
};
|
||||
|
||||
|
||||
RestApi.prototype.findUserById = function (userId) {
|
||||
var user = users.find(user => (user.uuid == userId))
|
||||
return user;
|
||||
};
|
||||
|
||||
|
||||
RestApi.prototype.findGroupMembers = function (groupId) {
|
||||
let members = [];
|
||||
let group = groups.find(v => v.uuid == groupId);
|
||||
users.map(user => {
|
||||
if (group.userList.find(v => v == user.uuid)) {
|
||||
members.push(user)
|
||||
}
|
||||
});
|
||||
return members;
|
||||
};
|
||||
|
||||
export default new RestApi();
|
||||