forked from legastero/stanza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
170 lines (152 loc) · 4.5 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Stanza.io Demo</title>
<style>
html {
margin: 0px;
padding: 0px;
}
body {
font-family: 'Helvetica', 'Arial', sans-serif;
margin: 0px;
padding: 0px;
color: #224;
background-color: #fefefe;
}
#logTitle {
position: fixed;
font-size: 20px;
padding: 10px;
padding-left: 30px;
width: 100%;
background-color: #fafaff;
border-bottom: 1px solid #dedeee;
top: 0px;
margin: 0px;
height: 20px;
z-index: 10;
}
#log {
padding: 25px;
padding-top: 50px;
padding-bottom: 75px;
}
#log div {
padding: 10px;
padding-left: 25px;
padding-right: 25px;
z-index: 0;
}
#log h2 {
font-size: 16px;
position: relative;
left: -10px;
z-index: 0;
}
#log div:nth-child(2n+1) {
background-color: #efefff;
border-radius: 5px;
border: 1px solid #cfcfff;
}
#settings {
font-size: 14px;
position: fixed;
bottom: 0px;
width: 100%;
margin: 0px;
padding: 10px;
padding-left: 30px;
background-color: #efefef;
border-top: 1px solid #dedede;
}
#settings h1 {
font-size: 20px;
margin: 0px;
}
#settings label {
margin-right: 20px;
}
</style>
<script src="build/stanzaio.bundle.js"></script>
</head>
<body>
<h1 id="logTitle">Events & Data</h1>
<div id="log"></div>
<div id="settings">
<h1>Connection Settings</h1>
<form id="loginInfo">
<label>JID: <input id="jid" type="text" name="jid" value="stanzaio@lance.im"/></label>
<label>Password: <input id="password" type="password" name="password" /></label>
<label>WebSocket/BOSH URL: <input id="url" type="text" name="url" value="" /></label>
<input id="connect" type="submit" value="Connect" />
</form>
</div>
<script>
function log(name, data) {
var container = document.getElementById('log');
var logEntry = document.createElement('div'),
header = document.createElement('h2'),
entry = document.createElement('p'),
altEntry = document.createElement('p');
header.textContent = name;
logEntry.appendChild(header);
var code = document.createElement('code');
var codeData = document.createElement('pre');
if (typeof data === 'string') {
codeData.textContent = data;
} else {
if (name === 'connected' || name === 'disconnected') {
codeData.textContent = 'Client instance: ' + JSON.stringify(data.config, null, ' ');
} else {
codeData.textContent = JSON.stringify(data, null, ' ');
}
}
code.appendChild(codeData);
entry.appendChild(code);
logEntry.appendChild(entry);
container.appendChild(logEntry);
window.scrollTo(0, document.body.scrollHeight);
}
var client;
var loginInfo = document.getElementById('loginInfo');
loginInfo.onsubmit = function (e) {
if (e.preventDefault) e.preventDefault();
var jid = document.getElementById('jid').value;
var url = document.getElementById('url').value;
var wsURL, boshURL, transports = ['websocket', 'bosh'];
if (url.indexOf('http') === 0) {
boshURL = url;
transports = ['bosh'];
} else if (url.indexOf('ws') === 0) {
wsURL = url;
transports = ['websocket'];
}
client = XMPP.createClient({
jid: jid,
password: document.getElementById('password').value,
wsURL: wsURL,
boshURL: boshURL,
transports: transports
});
client.on('*', log);
client.on('session:started', function () {
client.enableCarbons(function (err) {
if (err) {
console.log('Server does not support carbons');
}
});
client.getRoster(function (err, resp) {
client.updateCaps();
client.sendPresence({
caps: client.disco.caps
});
});
});
client.connect();
return false;
};
</script>
</body>
</html>