-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.html
234 lines (171 loc) · 7.78 KB
/
test.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!--
SDK Debug page
Small Vanilla JS app for testing and logging the functionality of the SDK.
Uses as few dependencies as possible, for both speed and to use as examples in the docs.
-->
<html>
<head>
<title>Skrumble JS SDK</title>
<script>
window.SkrumbleLoadPath = "dist/";
</script>
<script src="./dist/skrumble.min.js"></script>
<script src="https://cdn.jsdelivr.net/emojione/2.2.7/lib/js/emojione.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/emojione/2.2.7/assets/css/emojione.min.css"/>
<script>
var current_user;
var config = {
client_id: "f38y8",
client_secret:"|--F?N|wS91LPld!DfO+mQ*3%S-#I3R0-wS7hs-B",
api_hostname: "sk-staging.skrumble.com",
auth_hostname: "auth-staging.skrumble.com",
user_agent: "my-app"
}
document.addEventListener("DOMContentLoaded", function(evt) {
Skrumble.APISocket.config({
client_id: config.client_id,
client_secret: config.client_secret,
api_hostname: config.api_hostname,
auth_hostname: config.auth_hostname
});
});
function onLoginSubmit(evt) {
evt.preventDefault();
login(evt.target.elements.email.value, evt.target.elements.password.value)
}
function login(email, password) {
Skrumble.APISocket
.login({
email: email,
password: password
})
.then(skrumble_connected)
.catch((err) => {
console.error(err);
});
}
function skrumble_connected(curUser) {
current_user = curUser;
console.log("Login successful", curUser);
// Display user data
var user_debug = "<strong>Current user</strong><br />";
for (var i = 0; i < Object.keys(curUser).length; i++) {
user_debug += Object.keys(curUser)[i] + ": " + curUser[Object.keys(curUser)[i]] + "<br />";
}
document.getElementById('user_debug').innerHTML = user_debug;
// Listen and log socket message types
Skrumble.APISocket.on("user", function() { console.log("User event", arguments); });
Skrumble.APISocket.on("teamuser", function() { console.log("TeamUser event", arguments); });
Skrumble.APISocket.on("team", function() { console.log("Team event", arguments); });
Skrumble.APISocket.on("conference", function() { console.log("Conference event", arguments); });
// Get and display a list of chats
Skrumble.Chat.getAll({ limit: 100000 }).then(function(chats) {
var chat_debug = "<strong>Chats</strong><br />";
chats.map(function(chat) {
var other_user
if (chat.type == "private") {
other_user = chat.users.find((user) => {
return (user.id != current_user.id);
});
if (other_user) {
chat_debug += other_user.first_name + "<em> (" + chat.id + ")</em>";
} else {
debugger;
}
} else {
chat_debug += emojione.shortnameToUnicode(chat.name) + "<em> (" + chat.id + ")</em>";
}
chat_debug += "<button onClick='getChat(\"" + chat.id + "\")'>get chat log</button>";
if (chat.type == "private") {
chat_debug += "<button onClick='startCall(\"" + other_user.id + "\")'>call user</button>";
} else {
chat_debug += "<button onClick='startCall(\"room" + chat.id + "\")'>call group</button>";
}
chat_debug += "<br />"
});
document.getElementById("chats_debug").innerHTML = chat_debug;
});
}
// Logs and outputs the current chat, parses emoji
function setCurrentChat(Chat) {
window.curChat = Chat;
document.getElementById("chatinfo_debug").innerHTML = emojione.shortnameToUnicode(Chat.toHTML());
document.getElementById("chat_msg_debug").disabled = false
document.getElementById("chat_msg_debug").focus();
}
// Loads a chat by ID, displays it, and allows sending a message
function getChat(id) {
document.getElementById("chatinfo_debug").innerHTML = "Loading...";
Skrumble.Chat.get({
id: id,
load_messages: true,
message_limit: 500
}).then(function(Chat) {
setCurrentChat(Chat);
document.getElementById("sendmsg_form").addEventListener("submit", sendMessage);
Chat.on('updated', function(evt, chat) {
console.log("updated", Chat.name);
setCurrentChat(chat);
})
Chat.on('message', function(evt, chat, message) {
console.log("new chat msg", evt, message, chat);
setCurrentChat(chat);
});
});
}
// Send a message to the chat selected by getChat
function sendMessage(e) {
e.preventDefault();
curChat
.sendMessage(document.getElementById("chat_msg_debug").value)
.then(function(message) {
document.getElementById("chat_msg_debug").value = ""
});
return false;
}
</script>
<style>
.sendmsg {
position: fixed;
bottom: 0px;
left: 0;
width: 100%;
height: 50px;
background: #FFF;
margin: 0;
z-index: 1000;
padding: 10px;
}
</style>
</head>
<body style="padding-bottom: 70px">
<div
class="login_info"
style="display: block; position: fixed; top: 0; right: 0; border: 1px #333; padding: 30px 50px 20px; background: #CCC;">
<form
onSubmit="onLoginSubmit(event);">
<input
type="text"
placeholder="email"
name="email"
/>
<input
type="password"
placeholder="password"
name="password"
/>
<button
type="submit">
Login
</button>
</form>
</div>
<div id="user_debug"></div>
<div id="chats_debug"></div>
<div id="chatinfo_debug" style="border: 1px solid #F00; font: 10px/15px 'Menlo';"></div>
<form id="sendmsg_form" class="sendmsg" style="" autocomplete="off">
<input type="text" id="chat_msg_debug" tabindex="0" disabled="true" />
<button type="submit">Send</button>
</form>
</body>
</html>