-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathecho_client.dart
More file actions
77 lines (65 loc) · 2.14 KB
/
echo_client.dart
File metadata and controls
77 lines (65 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// main.dart
// Copyright (C) 2019 xiaominfc(武汉鸣鸾信息科技有限公司) <xiaominfc@gmail.com>
//
// Distributed under terms of the MIT license.
//
import 'src/security.dart';
import 'src/client.dart';
import './pb/IM.BaseDefine.pb.dart';
test(IMClient imClient){
imClient.updateSignInfo("测试签名1").then((result){
print(result);
});
imClient.requestAllGroupVersion().then((result){
print(result);
});
imClient.requestGroupInfoByIds([4]).then((result){
print(result);
});
imClient.requestContacts(0).then((result){
print(result);
});
imClient.requestSessions(0).then((sessions){
//print('sessions');
//print(sessions);
});
test_send_group_msg(imClient);
test_load_history_msgs(imClient);
}
test_send_group_msg(IMClient imClient){
imClient.sendGroupTextMsg("测试发送群消息",4).then((result){
});
}
test_load_history_msgs(IMClient imClient) {
imClient.loadSingleChatMsgs(2,0,10).then((result){
//print(result);
});
}
main() {
var server_url = "http://ngrok.haitou.cc:43880/msg_server";
TTSecurity security = TTSecurity.DefaultSecurity();
//print(security.decryptText('IvQMKe8arYYCZaGJe3c3hVNuYCc5/XPgGxa3GAAjh6zI1DcbHjSMHEkoO0xiqPwHQsaGdXAbAz40WnyMGQayQQ=='));
IMClient imClient = new IMClient().init('xiaominfc', '123456',server_url);
imClient.requesetMsgSever().then((serverInfo){
imClient.doLogin(serverInfo['priorIP'], int.parse(serverInfo['port'])).then((result){
if(result.result) {
print("login ok!");
test(imClient);
}else {
print("login failed!");
}
});
imClient.registerNewMsgHandler((data){
var msg = security.decryptText(new String.fromCharCodes(data.msgData));
imClient.sureReadMsg(data);
print("handle msg:" + msg);
if(data.msgType == MsgType.MSG_TYPE_GROUP_TEXT) {
print("handle group chat msg:" + msg);
}else {
print("handle single chat msg:" + msg);
imClient.sendTextMsg("echo:" + msg , data.fromUserId);
}
});
});
}