forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-console.html
More file actions
293 lines (254 loc) · 8.06 KB
/
dev-console.html
File metadata and controls
293 lines (254 loc) · 8.06 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
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
<div class="content">
<style>
#out {
float: left;
overflow: scroll;
overflow-x: hidden;
width: 440px;
background: #111;
color: #eee;
font-size: 12px;
font-family: m, mono;
line-height: 14px;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
-ms-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
-o-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
}
.out-copy {
position: absolute;
top: 0px;
left: 0px;
font-size: 7px;
line-height: 10px;
margin: 10px;
padding: 10px;
height: 380px;
width: 355px;
overflow: hidden;
border: 0;
}
#out, #channels-tests, #commands {
margin: 10px;
padding: 10px;
height: 480px;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
-ms-border-radius: 6px;
-o-border-radius: 6px;
border-radius: 6px;
}
#channels-tests {
float: left;
background: #ddd;
color: #444;
}
input {
width: 300px;
}
button {
cursor: pointer;
float: left;
width: 200px;
height: 40px;
margin: 10px;
}
.clear {
clear: both;
}
#stop {
font-size: 20px;
color: red;
font-family: b;
}
#send-message-subscription {
white-space: nowrap;
overflow: hidden;
width: 400px;
/*height: 24px;*/
background: #111;
color: #eee;
padding: 10px;
margin: 10px;
overflow: hidden;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
-ms-border-radius: 4px;
-o-border-radius: 4px;
border-radius: 4px;
-webkit-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
-ms-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
-o-box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
box-shadow: 0 0 5px rgba(0, 0, 0, 0.4);
}
#message {
width: 200px;
height: 90px;
padding: 4px;
margin: 0;
font-size: 12px;
line-height: 14px;
}
</style>
<h1>Dev Console</h1>
<div id=channels-tests>
<table>
<tr><td>origin</td> <td><input id=origin value=pubsub.pubnub.com /></td></tr>
{% if customer %}
<tr><td>pub-key</td> <td><input id=pub-key value={{customer.publish_key}} /></td></tr>
<tr><td>sub-key</td> <td><input id=sub-key value={{customer.subscribe_key}} /></td></tr>
{% else %}
<tr><td>pub-key</td> <td><input id=pub-key value=demo /></td></tr>
<tr><td>sub-key</td> <td><input id=sub-key value=demo /></td></tr>
{% endif %}
<tr><td>channel</td> <td><input id=channel value='my_channel' /></td></tr>
</table>
<button id=send-message-sub>Subscribe</button>
<button id=send-message-unsub disabled>UnSubscribe</button>
<div class=clear></div>
<div id=send-message-subscription>
<span style=color:#f00>NOT CONNECTED</span>
click "Subscribe" button
</div>
<div class=clear></div>
<input style=width:30px type="radio" id="literal" name="render" value="literal" checked>
Display message text literally
<br>
<input style=width:30px type="radio" id="asHtml" name="render" value="asHtml">
Render message text as HTML
<br>
<div class=clear></div>
<table>
<tr><td style=text-align:center>
<button id=send-message disabled>Send</button><br>
JSON Message
</td> <td><textarea id=message>{ "text":"hey" }</textarea></td></tr>
</table>
<div class=clear></div>
</div>
<div id=out style=position:relative></div>
<div class=clear></div>
<div id=pubnub pub-key=demo sub-key=demo ></div>
<script src=/static/jquery-1.5.min.js></script>
<script src=../../web/pubnub.min.js></script>
<script>(function(){
var p = PUBNUB
, paused = false
, out = p.$('out')
, running = false;
function log( msg, color ) {
if (paused) return;
var color = color || '';
// Convert the message into JSON text
var msgText = JSON.stringify(msg);
// Were we requested to convert tags to literal (displayable) text?
if (document.getElementById("literal").checked) {
// Yup. Arrange for HTML entities and tags not to be treated as such.
msgText = msgText.replace(/\&/g, "&").replace(/</g, "<");
}
out.innerHTML = ((log.l++)+'000').slice(0,4) +
": " +
'<span style=color:'+color+'>' +
msgText +
'</span>' +
"<br/>" +
out.innerHTML;
} log.l = 1;
(function(){
var channel = p.$('channel')
, message = p.$('message')
, subscription = p.$('send-message-subscription')
, connect_btn = p.$('send-message-sub')
, net;
function connect_now() {
var chan = channel.value;
subscription.innerHTML =
'<span style=color:#f09>CONNECTING TO: "' +
chan +
'"</span>';
p.attr( connect_btn, 'disabled', 'disabled' );
p.$('send-message').removeAttribute('disabled');
p.$('send-message-unsub').removeAttribute('disabled');
net = p.init({
publish_key : p.$('pub-key').value,
subscribe_key : p.$('sub-key').value,
origin : p.$('origin').value
});
net.subscribe({
connect : function() {
subscription.innerHTML =
'<span style=color:green>CONNECTED TO: "' +
chan +
'"</span>';
log(['CONNECTED TO:', chan], '#f09');
},
channel : chan,
callback : function(msg) {
log( msg, '#fa0' );
}
});
}
p.bind( 'click', connect_btn, connect_now );
function unsub() {
connect_btn.removeAttribute('disabled');
p.attr( p.$('send-message'), 'disabled', 'disabled' );
p.attr( p.$('send-message-unsub'), 'disabled', 'disabled' );
subscription.innerHTML =
'<span style=color:#f00>NOT CONNECTED</span>';
net.unsubscribe({channel : channel.value});
}
function sendmsg() {
log( ['PUBLISHING:', channel.value], 'green' );
net.publish({
channel : channel.value,
message : JSON.parse(message.value),
callback : function(info) {
log(["PUBLISHED:", info]);
}
});
}
p.bind( 'click', p.$('send-message-unsub'), unsub );
p.bind( 'click', p.$('send-message'), sendmsg );
// ----------------------------------------------------------------------
// Easy Copy Paste
// ----------------------------------------------------------------------
p.bind( 'click', out, function() {
paused = true;
var out_copy = p.create('textarea');
p.bind( 'blur', out_copy, function() {
try { out.removeChild(out_copy); } catch(e) {}
paused = false;
} );
p.attr( out_copy, 'class', 'out-copy' );
out.insertBefore( out_copy, out.firstChild );
setTimeout( function() {
out_copy.value = out.innerHTML
.replace( /<br>/g, '\n' )
.replace( /<[^>]+?>/g, '' );
out_copy.focus();
out_copy.select();
}, 10 );
} );
// ----------------------------------------------------------------------
// Load URL Params
// ----------------------------------------------------------------------
(function(){
var hchannel = (location.href.match(/channel=([\w\-]+)/)||[''])
.slice(-1)[0]
, horigin = (location.href.match(/origin=([\w\-\.]+)/)||[''])
.slice(-1)[0]
, hsubkey = (location.href.match(/sub=([\w\-]+)/)||[''])
.slice(-1)[0]
, hpubkey = (location.href.match(/pub=([\w\-]+)/)||[''])
.slice(-1)[0];
if (hchannel) p.$('channel').value = hchannel;
if (hsubkey) p.$('sub-key').value = hsubkey;
if (hpubkey) p.$('pub-key').value = hpubkey;
if (horigin) p.$('origin').value = horigin;
if (hchannel) connect_now();
})();
})();
})();</script>
</div>