Repository navigation
Expand file tree
/
Copy pathprint.html
More file actions
54 lines (45 loc) · 1.41 KB
/
Copy pathprint.html
File metadata and controls
54 lines (45 loc) · 1.41 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
<!doctype html>
<html>
<head>
<title>PubNub Remote Control Printer</title>
</head><body>
<button id=print>Signal Remote Print</button>
<!-- PUBNUB SOURCE -->
<script src=../../web/pubnub.js></script>
<script>(function(){
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- GENERATE CHANNEL & SETUP
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
var channel = PUBNUB.uuid()
, pub_key = 'demo'
, sub_key = 'demo'
, pubnub = PUBNUB.init({ subscribe_key : sub_key, publish_key : pub_key });
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- OPEN RECEIVE SOCKET
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
function listen_for_print() {
pubnub.subscribe({
restore : true,
channel : channel,
message : receive
});
}
function signal_print() {
pubnub.publish({
channel : channel,
message : 'PRINT!'
});
}
function receive(message) {
window.print();
pubnub.unsubscribe({ channel : channel });
setTimeout( listen_for_print, 2500 );
}
listen_for_print();
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-- BIND TO SIGNAL PRINT BUTTON
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
pubnub.bind( 'mousedown,touchstart', pubnub.$('print'), signal_print );
})();</script>
</body>
</html>