Skip to content

Commit 4e1ffe4

Browse files
author
jlengstorf
committed
Added Pusher and set up testing for realtime posts.
1 parent 9fd5b5b commit 4e1ffe4

File tree

2 files changed

+485
-0
lines changed

2 files changed

+485
-0
lines changed

index.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,69 @@
55
echo $_GET['hub_challenge'];
66
exit;
77
}
8+
9+
if ($_SERVER['REQUEST_METHOD']==='POST') {
10+
// Instantiates Pusher PHP API
11+
// require 'lib/Pusher.php';
12+
13+
// $pusher = new Pusher('867d60a8d5de3996dd25', '7709ac1336e7968d1a61', '42771');
14+
// $pusher->trigger('selfies', 'new-selfie', array('selfie' => 'New selfie!'))
15+
16+
mail('[email protected]', 'Realtime POST', print_r($_POST, TRUE));
17+
}
18+
19+
?>
20+
<!doctype html>
21+
<html lang="en">
22+
23+
<head>
24+
25+
<meta charset="utf-8" />
26+
27+
<title></title>
28+
29+
</head>
30+
31+
<body>
32+
33+
<h1>Selfies!</h1>
34+
35+
<ul id="selfies">
36+
<li class="loading">No selfies yet&hellip; #sadface</li>
37+
</ul><!--/#selfies-->
38+
39+
<script src="http://js.pusher.com/2.0/pusher.min.js"></script>
40+
<script>
41+
42+
var pusher = new Pusher('867d60a8d5de3996dd25'),
43+
channel = pusher.subscribe('selfies'),
44+
selfies = document.getElementById('selfies');
45+
46+
channel.bind('new-selfie', function(data){
47+
48+
var selfie_count = selfies.childNodes.length;
49+
50+
// If the loading LI still exists, removes it
51+
if (selfie_count===1) {
52+
for (var i=0; i<selfies.childNodes.length; i++) {
53+
if (selfies.childNodes[i].className==="loading") {
54+
selfies.removeChild(selfies.childNodes[i]);
55+
}
56+
}
57+
}
58+
59+
// Creates a new LI with the selfie
60+
//TODO: Add selfie markup
61+
var li = document.createElement("li").appendChild(data.selfie);
62+
63+
ul.appendChild(li);
64+
65+
return;
66+
});
67+
68+
</script>
69+
70+
</body>
71+
72+
</html>
73+

0 commit comments

Comments
 (0)