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
/
switch-users.html
98 lines (88 loc) · 2.19 KB
/
switch-users.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户切换</title>
</head>
<body>
<link rel="stylesheet" href="./res/rongcloud.css">
<a href="https://github.com/rongcloud/websdk-demo/blob/master/switch-users.html" class="get-source">获取源码</a>
<style>
pre{
vertical-align:top;
display:inline-block;
width:45%;
border-top:1px dotted #ccc;
padding:5px 0 0 10px;
line-height:1.5;
color:#333;
background:#f5f5f5;
margin-left:1em;
font-size:12px;
font-family:verdana;
}
</style>
<script src="//cdn.ronghub.com/RongIMLib-2.5.4.js"></script>
<script src="./init.js"></script>
<script>
function startSwitch(){
var appKey = "8w7jv4qb78a9y";
var token1 = "ZThhLI1Xa1BX5EMREAdArWSH6ouuI8NT/fNmMkzF+4IOKIoFvbsi6JnH8QmnSltLkCcsK8vOgKl3IZgfbxFiWg==";
var token2 = "4FGCL0oQ/E72nU4ivbui8uHR/ySxKaD1cAX2biXsYR6RsLYO9xAA4ooa+q3n42JnVTQyMAdFUiDsjFRDYZaQeg==";
var params = {
appKey : appKey,
token : token1
};
//登录第一个用户
init(params,{
getInstance : function(instance1){
instance1.getConversationList({
onSuccess: function(list) {
document.getElementById("user1").innerHTML = JSON.stringify(list,null,"\t");
instance1.logout();
setTimeout(function(){
initUser2();
},0);
},
onError: function(error) {}
}, null, 10);
},
getCurrentUser : function(userInfo){
userId = userInfo.userId;
alert("链接成功;user1 id=" + userInfo.userId);
},
receiveNewMessage : function(message){
}
});
function initUser2(){
params.token = token2;
init(params,{
getInstance : function(instance2){
instance2.getConversationList({
onSuccess: function(list2) {
document.getElementById("user2").innerHTML = JSON.stringify(list2,null,"\t");
},
onError: function(error) {}
}, null, 10);
},
getCurrentUser : function(userInfo){
userId = userInfo.userId;
alert("链接成功;user2 id=" + userInfo.userId);
},
receiveNewMessage : function(message){
}
});
}
}
</script>
<p></p>
<div class="show" id="show1">
<h3>用户切换</h3>
<button onclick="startSwitch()">开始切换</button>
<div id="result">
<pre id="user1"></pre>
<pre id="user2"></pre>
</div>
</div>
</body>
</html>