Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lynxzhang committed Aug 27, 2020
2 parents c17d544 + 023956b commit c304a4b
Show file tree
Hide file tree
Showing 23 changed files with 280 additions and 40 deletions.
211 changes: 211 additions & 0 deletions Android/tuikit/sampleCode/message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@

@Override
public void onRecvNewMessage(V2TIMMessage msg) {
int elemType = msg.getElemType();
if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_TEXT) {
// 文本消息
V2TIMTextElem v2TIMTextElem = msg.getTextElem();
String text = v2TIMTextElem.getText();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_CUSTOM) {
// 自定义消息
V2TIMCustomElem v2TIMCustomElem = msg.getCustomElem();
byte[] customData = v2TIMCustomElem.getData();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_IMAGE) {
// 图片消息
V2TIMImageElem v2TIMImageElem = msg.getImageElem();
// 一个图片消息会包含三种格式大小的图片,分别为原图、大图、微缩图(SDK 会在发送图片消息的时候自动生成微缩图、大图,客户不需要关心)
// 大图:是将原图等比压缩,压缩后宽、高中较小的一个等于720像素。
// 缩略图:是将原图等比压缩,压缩后宽、高中较小的一个等于198像素。
List<V2TIMImageElem.V2TIMImage> imageList = v2TIMImageElem.getImageList();
for (V2TIMImageElem.V2TIMImage v2TIMImage : imageList) {
// 图片 ID,内部标识,可用于外部缓存 key
String uuid = v2TIMImage.getUUID();
// 图片类型
int imageType = v2TIMImage.getType();
// 图片大小(字节)
int size = v2TIMImage.getSize();
// 图片宽度
int width = v2TIMImage.getWidth();
// 图片高度
int height = v2TIMImage.getHeight();
// 设置图片下载路径 imagePath,这里可以用 uuid 作为标识,避免重复下载
String imagePath = "/sdcard/im/image/" + "myUserID" + uuid;
File imageFile = new File(imagePath);
// 判断 imagePath 下有没有已经下载过的图片文件
if (!imageFile.exists()) {
// 下载图片
v2TIMImage.downloadImage(imagePath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
// 下载进度回调:已下载大小 v2ProgressInfo.getCurrentSize();总文件大小 v2ProgressInfo.getTotalSize()
}
@Override
public void onError(int code, String desc) {
// 下载失败
}
@Override
public void onSuccess() {
// 下载完成
}
});
} else {
// 图片已存在
}
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_SOUND) {
// 语音消息
V2TIMSoundElem v2TIMSoundElem = msg.getSoundElem();
// 语音 ID,内部标识,可用于外部缓存 key
String uuid = v2TIMSoundElem.getUUID();
// 语音文件大小
int dataSize = v2TIMSoundElem.getDataSize();
// 语音时长
int duration = v2TIMSoundElem.getDuration();
// 设置语音文件路径 soundPath,这里可以用 uuid 作为标识,避免重复下载
String soundPath = "/sdcard/im/sound/" + "myUserID" + uuid;
File imageFile = new File(soundPath);
// 判断 soundPath 下有没有已经下载过的语音文件
if (!imageFile.exists()) {
v2TIMSoundElem.downloadSound(soundPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
// 下载进度回调:已下载大小 v2ProgressInfo.getCurrentSize();总文件大小 v2ProgressInfo.getTotalSize()
}
@Override
public void onError(int code, String desc) {
// 下载失败
}
@Override
public void onSuccess() {
// 下载完成
}
});
} else {
// 文件已存在
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_VIDEO) {
// 视频消息
V2TIMVideoElem v2TIMVideoElem = msg.getVideoElem();
// 视频截图 ID,内部标识,可用于外部缓存 key
String snapshotUUID = v2TIMVideoElem.getSnapshotUUID();
// 视频截图文件大小
int snapshotSize = v2TIMVideoElem.getSnapshotSize();
// 视频截图宽
int snapshotWidth = v2TIMVideoElem.getSnapshotWidth();
// 视频截图高
int snapshotHeight = v2TIMVideoElem.getSnapshotHeight();
// 视频 ID,内部标识,可用于外部缓存 key
String videoUUID = v2TIMVideoElem.getVideoUUID();
// 视频文件大小
int videoSize = v2TIMVideoElem.getVideoSize();
// 视频时长
int duration = v2TIMVideoElem.getDuration();
// 设置视频截图文件路径,这里可以用 uuid 作为标识,避免重复下载
String snapshotPath = "/sdcard/im/snapshot/" + "myUserID" + snapshotUUID;
File snapshotFile = new File(snapshotPath);
if (!snapshotFile.exists()) {
v2TIMVideoElem.downloadSnapshot(snapshotPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
// 下载进度回调:已下载大小 v2ProgressInfo.getCurrentSize();总文件大小 v2ProgressInfo.getTotalSize()
}
@Override
public void onError(int code, String desc) {
// 下载失败
}
@Override
public void onSuccess() {
// 下载完成
}
});
} else {
// 文件已存在
}

// 设置视频文件路径,这里可以用 uuid 作为标识,避免重复下载
String videoPath = "/sdcard/im/video/" + "myUserID" + snapshotUUID;
File videoFile = new File(videoPath);
if (!snapshotFile.exists()) {
v2TIMVideoElem.downloadSnapshot(videoPath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
// 下载进度回调:已下载大小 v2ProgressInfo.getCurrentSize();总文件大小 v2ProgressInfo.getTotalSize()
}
@Override
public void onError(int code, String desc) {
// 下载失败
}
@Override
public void onSuccess() {
// 下载完成
}
});
} else {
// 文件已存在
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_FILE) {
// 文件消息
V2TIMFileElem v2TIMFileElem = msg.getFileElem();
// 文件 ID,内部标识,可用于外部缓存 key
String uuid = v2TIMFileElem.getUUID();
// 文件名称
String fileName = v2TIMFileElem.getFileName();
// 文件大小
int fileSize = v2TIMFileElem.getFileSize();
// 设置文件路径,这里可以用 uuid 作为标识,避免重复下载
String filePath = "/sdcard/im/file/" + "myUserID" + uuid;
File file = new File(filePath);
if (!file.exists()) {
v2TIMFileElem.downloadFile(filePath, new V2TIMDownloadCallback() {
@Override
public void onProgress(V2TIMElem.V2ProgressInfo progressInfo) {
// 下载进度回调:已下载大小 v2ProgressInfo.getCurrentSize();总文件大小 v2ProgressInfo.getTotalSize()
}
@Override
public void onError(int code, String desc) {
// 下载失败
}
@Override
public void onSuccess() {
// 下载完成
}
});
} else {
// 文件已存在
}
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_LOCATION) {
// 地理位置消息
V2TIMLocationElem v2TIMLocationElem = msg.getLocationElem();
// 地理位置信息描述
String desc = v2TIMLocationElem.getDesc();
// 经度
double longitude = v2TIMLocationElem.getLongitude();
// 纬度
double latitude = v2TIMLocationElem.getLatitude();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_FACE) {
// 表情消息
V2TIMFaceElem v2TIMFaceElem = msg.getFaceElem();
// 表情所在的位置
int index = v2TIMFaceElem.getIndex();
// 表情自定义数据
byte[] data = v2TIMFaceElem.getData();
} else if (elemType == V2TIMMessage.V2TIM_ELEM_TYPE_GROUP_TIPS) {
// 群 tips 消息
V2TIMGroupTipsElem v2TIMGroupTipsElem = msg.getGroupTipsElem();
// 所属群组
String groupId = v2TIMGroupTipsElem.getGroupID();
// 群Tips类型
int type = v2TIMGroupTipsElem.getType();
// 操作人资料
V2TIMGroupMemberInfo opMember = v2TIMGroupTipsElem.getOpMember();
// 被操作人资料
List<V2TIMGroupMemberInfo> memberList = v2TIMGroupTipsElem.getMemberList();
// 群信息变更详情
List<V2TIMGroupChangeInfo> groupChangeInfoList = v2TIMGroupTipsElem.getGroupChangeInfoList();
// 群成员变更信息
List<V2TIMGroupMemberChangeInfo> memberChangeInfoList v2TIMGroupTipsElem.getMemberChangeInfoList();
// 当前群在线人数
int memberCount = v2TIMGroupTipsElem.getMemberCount();
}
}

6 changes: 6 additions & 0 deletions H5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ Web Demo 使用 `Vue` + `Vuex` + `Element-UI` 开发,你可以参考该 Demo

**Features**

- SDK 版本更新至 2.7.6

#### 2020/7/3

**Features**

- SDK 版本更新至 2.7.5

**Changes**
Expand Down
2 changes: 1 addition & 1 deletion H5/dist/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=renderer content=webkit><meta name=force-rendering content=webkit><meta http-equiv=X-UA-Compatible content="IE=Edge,chrome=1"><title>TIMSDK demo</title><link rel=icon href=favicon.ico type=image/x-icon><link href=css/app.0e155d31.css rel=preload as=style><link href=css/chunk-vendors.c7922a7e.css rel=preload as=style><link href=js/app.2aa27d8d.js rel=preload as=script><link href=js/chunk-vendors.3a56c3a5.js rel=preload as=script><link href=css/chunk-vendors.c7922a7e.css rel=stylesheet><link href=css/app.0e155d31.css rel=stylesheet></head><body><div id=app></div><script src=./debug/GenerateTestUserSig.js></script><script src=./debug/lib-generate-test-usersig.min.js></script><script src=js/chunk-vendors.3a56c3a5.js></script><script src=js/app.2aa27d8d.js></script></body></html>
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=renderer content=webkit><meta name=force-rendering content=webkit><meta http-equiv=X-UA-Compatible content="IE=Edge,chrome=1"><title>TIMSDK demo</title><link rel=icon href=favicon.ico type=image/x-icon><link href=css/app.0e155d31.css rel=preload as=style><link href=css/chunk-vendors.c7922a7e.css rel=preload as=style><link href=js/app.258da725.js rel=preload as=script><link href=js/chunk-vendors.e6d6dd32.js rel=preload as=script><link href=css/chunk-vendors.c7922a7e.css rel=stylesheet><link href=css/app.0e155d31.css rel=stylesheet></head><body><div id=app></div><script src=./debug/GenerateTestUserSig.js></script><script src=./debug/lib-generate-test-usersig.min.js></script><script src=js/chunk-vendors.e6d6dd32.js></script><script src=js/app.258da725.js></script></body></html>
13 changes: 13 additions & 0 deletions H5/dist/js/chunk-vendors.e6d6dd32.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion H5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"cos-js-sdk-v5": "^0.5.22",
"element-ui": "^2.13.0",
"mta-h5-analysis": "^2.0.15",
"tim-js-sdk": "^2.7.5",
"tim-js-sdk": "^2.7.6",
"trtc-js-sdk": "^4.3.6",
"vue": "^2.6.11",
"vuex": "^3.1.2"
Expand Down
2 changes: 1 addition & 1 deletion H5/sdk/tim-js.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions WXMini/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@

## Change Log

#### 2020/7/31

**Feat Add**

- SDK 版本更新至 2.7.6

#### 2020/7/3

**Feat Add**
Expand Down
8 changes: 4 additions & 4 deletions WXMini/dist/wx/common/vendor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion WXMini/dist/wx/pages/chat/index.vue.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{{title}}
</view></view> <i-modal title="确认下载?" visible="{{modalVisible}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'0'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc input-wrapper">
进度{{percent}}%
</view></i-modal> <i-modal title="发送自定义消息" visible="{{customModalVisible}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'4'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc custom-wrapper"><input type="text" class="_input data-v-afeb3abc custom-input {{[focusedInput === 'data' ? 'input-focus' : '']}}" placeholder="输入数据" value="{{customData}}" bindinput="handleProxy" bindfocus="handleProxy" bindblur="handleProxy" data-eventid="{{'1'}}" data-comkey="{{$k}}" /> <input type="text" class="_input data-v-afeb3abc custom-input {{[focusedInput === 'desc' ? 'input-focus' : '']}}" placeholder="输入描述" value="{{customDescription}}" bindinput="handleProxy" bindfocus="handleProxy" bindblur="handleProxy" data-eventid="{{'2'}}" data-comkey="{{$k}}" /> <input type="text" class="_input data-v-afeb3abc custom-input {{[focusedInput === 'ext' ? 'input-focus' : '']}}" placeholder="输入其他" value="{{customExtension}}" bindinput="handleProxy" bindfocus="handleProxy" bindblur="handleProxy" data-eventid="{{'3'}}" data-comkey="{{$k}}" /></view></i-modal> <i-modal title="对IM demo的评分和评价" i-class="custom-modal" visible="{{rateModal}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'7'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc custom-wrapper"><i-rate bindchange="handleProxy" value="{{rate}}" data-eventid="{{'5'}}" data-comkey="{{$k}}" class="_i-rate data-v-afeb3abc"></i-rate> <input type="text" class="_input data-v-afeb3abc custom-input" placeholder="输入评价" value="{{customExtension}}" bindinput="handleProxy" data-eventid="{{'6'}}" data-comkey="{{$k}}" /></view></i-modal> <i-modal title="提示" i-class="custom-modal" visible="{{revokeModal}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'8'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc custom-wrapper">
</view></i-modal> <i-modal title="发送自定义消息" visible="{{customModalVisible}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'4'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc custom-wrapper"><input wx:if="{{customModalVisible}}" type="text" class="_input data-v-afeb3abc custom-input {{[focusedInput === 'data' ? 'input-focus' : '']}}" placeholder="输入数据" value="{{customData}}" bindinput="handleProxy" bindfocus="handleProxy" bindblur="handleProxy" data-eventid="{{'1'}}" data-comkey="{{$k}}" /> <input wx:if="{{customModalVisible}}" type="text" class="_input data-v-afeb3abc custom-input {{[focusedInput === 'desc' ? 'input-focus' : '']}}" placeholder="输入描述" value="{{customDescription}}" bindinput="handleProxy" bindfocus="handleProxy" bindblur="handleProxy" data-eventid="{{'2'}}" data-comkey="{{$k}}" /> <input wx:if="{{customModalVisible}}" type="text" class="_input data-v-afeb3abc custom-input {{[focusedInput === 'ext' ? 'input-focus' : '']}}" placeholder="输入其他" value="{{customExtension}}" bindinput="handleProxy" bindfocus="handleProxy" bindblur="handleProxy" data-eventid="{{'3'}}" data-comkey="{{$k}}" /></view></i-modal> <i-modal title="对IM demo的评分和评价" i-class="custom-modal" visible="{{rateModal}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'7'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc custom-wrapper"><i-rate bindchange="handleProxy" value="{{rate}}" data-eventid="{{'5'}}" data-comkey="{{$k}}" class="_i-rate data-v-afeb3abc"></i-rate> <input wx:if="{{rateModal}}" type="text" class="_input data-v-afeb3abc custom-input" placeholder="输入评价" value="{{customExtension}}" bindinput="handleProxy" data-eventid="{{'6'}}" data-comkey="{{$k}}" /></view></i-modal> <i-modal title="提示" i-class="custom-modal" visible="{{revokeModal}}" bindok="handleProxy" bindcancel="handleProxy" data-eventid="{{'8'}}" data-comkey="{{$k}}" class="_i-modal data-v-afeb3abc"><view class="_div data-v-afeb3abc custom-wrapper">
确定要撤回本消息吗?
</view></i-modal> <view id="list" bindtap="handleProxy" data-eventid="{{'18'}}" data-comkey="{{$k}}" class="_div data-v-afeb3abc"><view wx:key="message.ID" key="{{message.ID}}" id="{{message.ID}}" wx:for="{{currentMessageList}}" wx:for-index="index" wx:for-item="message" class="_li data-v-afeb3abc"><view class="_div data-v-afeb3abc notice" wx:if="{{message.type === 'TIMGroupTipElem' || message.type === 'TIMGroupSystemNoticeElem'}}"><view class="_div data-v-afeb3abc content"><label wx:key="message.ID + index1" key="{{message.ID + index1}}" wx:for="{{message.virtualDom}}" wx:for-index="index1" wx:for-item="div" class="_span data-v-afeb3abc"><label wx:if="{{div.name === 'groupTip' || 'system'}}" class="_span data-v-afeb3abc">{{div.text}}</label></label></view></view><view wx:elif="{{message.isRevoked}}" key="{{message.ID}}" class="_div data-v-afeb3abc"><view class="_div data-v-afeb3abc notice"><view class="_div data-v-afeb3abc content"><block wx:if="{{message.from === myInfo.userID}}">你撤回了一条消息</block><block wx:else>{{message.from}}撤回了一条消息</block></view> <block wx:if="{{message.from === myInfo.userID}}"><view wx:if="{{(currentTime - message.time < 120) && message.type === 'TIMTextElem'}}" bindtap="handleProxy" class="_div data-v-afeb3abc re-edit" data-eventid="{{'9_'+index}}" data-comkey="{{$k}}">重新编辑</view></block></view></view><view wx:else class="_div data-v-afeb3abc {{(message.flow === 'out') ? 'item-right' : 'item-left'}}"><view class="_div data-v-afeb3abc content"><view class="_div data-v-afeb3abc name"><block wx:if="{{currentConversation.type === 'C2C'}}"><block wx:if="{{message.flow === 'in'}}">
{{currentConversation.userProfile.nick || currentConversation.userProfile.userID}}
Expand Down
2 changes: 1 addition & 1 deletion WXMini/dist/wx/pages/chat/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion WXMini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"cos-wx-sdk-v5": "^0.7.3",
"dayjs": "^1.8.17",
"mpvue": "^2.0.0",
"tim-wx-sdk": "^2.7.5",
"tim-wx-sdk": "^2.7.6",
"vuex": "^3.1.1"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion WXMini/sdk/tim-wx.js

Large diffs are not rendered by default.

Loading

0 comments on commit c304a4b

Please sign in to comment.