This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 495
/
connect-check.html
181 lines (156 loc) · 4.4 KB
/
connect-check.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>connect,receive message</title>
</head>
<body>
<link rel="stylesheet" href="./res/rongcloud.css">
<a href="https://github.com/rongcloud/websdk-demo/blob/master/connect-check.html" class="get-source">获取源码</a>
<style>
body{
font-size:80%;
}
.panel span{
display:inline-block;
width:60px;
}
.show{
width:98%;
display:inline-block;
overflow:hidden;
border:1px solid #ccc;
}
.show h3{
text-indent:10px;
}
.show pre{
border-top:1px dotted #ccc;
padding:5px 0 0 10px;
line-height:1.5;
color:#333;
background:#f5f5f5;
}
.show pre:nth-child(2n){
background:#ccc;
}
#joinChatRoom{
display: none;
background:#000;
color:#fff;
}
</style>
<script>
function showResult(id,message){
var dom = document.getElementById(id);
console.log(message.content.content)
// dom.innerHTML += '<pre>' + message.senderUserId + ": " + RongIMLib.RongIMEmoji.emojiToHTML(message.content.content + "") + '</pre>';
dom.innerHTML += '<pre>' + JSON.stringify(message,null,"\t") + '</pre>';
//JSON.stringify(message,null,"\t")
}
</script>
<script src="js/message-output.js"></script>
<script src="//cdn.ronghub.com/RongIMLib-2.5.4.js"></script>
<script src="//cdn.ronghub.com/RongEmoji-2.2.5.min.js"></script>
<script src="./init.js"></script>
<script>
//注册自定义消息
function registerMessage(type,propertys){
var messageName = type; // 消息名称。
var objectName = "s:" + type; // 消息内置名称,请按照此格式命名 *:* 。
var mesasgeTag = new RongIMLib.MessageTag(true,true); //true true 保存且计数,false false 不保存不计数。
RongIMClient.registerMessageType(messageName, objectName, mesasgeTag, propertys);
}
function startInit(user,targetId){
var params = {
appKey : getValue("appKey"),
token : getValue("token"),
navi : getValue("navi")
};
var userId = "";
var callbacks = {
getInstance : function(instance){
RongIMLib.RongIMEmoji.init();
//instance.sendMessage
//注册 PersonMessage
var propertys = ["name","age","gender"]; // 消息类中的属性名。
registerMessage("PersonMessage",propertys);
//注册 ProductMessage
var propertys = ["price","title","desc","images"]; // 消息类中的属性名。
registerMessage("ProductMessage",propertys);
},
getCurrentUser : function(userInfo){
console.log(userInfo.userId);
userId = userInfo.userId;
alert("链接成功;userid=" + userInfo.userId);
document.titie = ("链接成功;userid=" + userInfo.userId);
//加入聊天室
joinChatRoom();
},
receiveNewMessage : function(message){
//判断是否有 @ 自己的消息
console.log(message);
var mentionedInfo = message.content.mentionedInfo || {};
var ids = mentionedInfo.userIdList || [];
for(var i=0; i < ids.length; i++){
if( ids[i] == userId){
alert("有人 @ 了你!");
}
}
showResult("show1",message);
messageOutput(message);
}
};
init(params,callbacks);
}
function getValue(id){
return document.getElementById(id).value;
}
function joinChatRoom(){
var chatRoomId = getValue("chatRoomId");
// chatRoomId = chatRoomId.replace(/(^\s*)|(\s*$)/g, " ");
if(chatRoomId == ""){
alert("请输入聊天室 id!");
return false;
}
var IM = RongIMClient.getInstance();
IM.joinChatRoom(chatRoomId, 50, {
onSuccess: function() {
alert("加入聊天室 " + chatRoomId + " 成功");
},
onError: function(error) {
alert("加入聊天室失败");
}
});
}
</script>
<h1>链接测试、消息接收 (含自定义消息)</h1>
<div class="panel" id="panel">
<p>
<span>appkey</span>
<input type="text" id="appKey" size="20" value="8w7jv4qb78a9y">
</p>
<p>
<span>token</span>
<input type="text" id="token" size="110" value="ZThhLI1Xa1BX5EMREAdArWSH6ouuI8NT/fNmMkzF+4IOKIoFvbsi6JnH8QmnSltLkCcsK8vOgKl3IZgfbxFiWg==">
</p>
<p>
<span>navi</span>
<input type="text" id="navi" size="50" value=""> <b>此配置项仅针对私有部署,公有云请置空,格式为 10.10.10.10:8080 </b>
</p>
<p>
<span>聊天室 id</span>
<input type="text" id="chatRoomId" size="20" value="">
<b><input type="button" id="joinChatRoom" onclick="joinChatRoom()" value="加入聊天室"> </b>
</p>
<p>
<span> </span>
<input type="button" onclick="startInit()" value="初始化链接">
</p>
</div>
<p></p>
<div class="show" id="show1">
<h3>消息接收结果(新消息在最下)</h3>
</div>
</body>
</html>