-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first simple Pusher Pipe node.js example
- Loading branch information
Showing
6 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
*.DS_Store | ||
php/config.php | ||
ruby/config.rb | ||
pusher_pipe/node/config.js | ||
pusher_pipe/node/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#Simple Pusher Pipe Example | ||
|
||
For more information on the Pusher Pipe see: | ||
<http://pusher.com/docs/pipe> | ||
|
||
## Technologies | ||
|
||
The Pusher Pipe only has a client library for Node.js at the moment. | ||
|
||
## Example | ||
|
||
### Node.js | ||
|
||
To run this example you must install the `pusher-pipe` node.js module. You can find the module here: | ||
http://search.npmjs.org/#/pusher-pipe | ||
|
||
And install using: | ||
|
||
npm pusher-pipe | ||
|
||
See the [Pusher Pipe QuickStart](http://pusher.com/docs/pipe_quickstart) for more information. | ||
|
||
The node example found in `node/src/` is based on the [Pusher Pipe QuickStart](http://pusher.com/docs/pipe_quickstart). It demonstrates how to: | ||
|
||
* Be notified of a socket connection on the server | ||
* trigger an event from the client on the `back_channel` | ||
* trigger an event from the server on the `back_channel` | ||
* subscribe to a channel and bind to an event on the client | ||
* trigger an event on a channel from the server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var PUSHER_CONFIG = { | ||
APP_ID: 'YOUR_APP_ID', | ||
APP_KEY: 'YOUR_APP_KEY', | ||
APP_SECRET: 'YOUR_APP_KEY' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<html> | ||
<head> | ||
<script type="text/javascript" src="http://js.pusherapp.com/1.10.0-pre/pusher.min.js"></script> | ||
<script src="http://code.jquery.com/jquery-1.7.min.js"></script> | ||
<script type="text/javascript"> | ||
Pusher.host = "ws.darling.pusher.com" | ||
Pusher.log = function(message) { | ||
log(message); | ||
}; | ||
var pusher = null; | ||
|
||
$(init); | ||
|
||
function init() { | ||
$("#send").click(sendEvent); | ||
|
||
createPusher(); | ||
}; | ||
|
||
function createPusher() { | ||
pusher = new Pusher('577f0d13ea03ad86c8d5'); | ||
|
||
var channel = pusher.subscribe('my-channel'); | ||
channel.bind('my_event', function(data) { | ||
log( JSON.stringify(data) ); | ||
}); | ||
} | ||
|
||
function sendEvent() { | ||
log("sending"); | ||
pusher.back_channel.trigger('eventFromBrowser', {some: 'data'}); | ||
pusher.back_channel.bind('acknowledge', function(data) { | ||
log('back_channel: ' + JSON.stringify(data)); | ||
}); | ||
} | ||
|
||
function log(msg) { | ||
$('#logs').prepend('<div>' + msg + '</div>'); | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<button id="send">Send Event</button> | ||
|
||
<h3>Logs</h3> | ||
<div id="logs"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var config = require('./config.js'); | ||
console.log(config); | ||
|
||
var sys = require('sys'); | ||
var Pipe = require('pusher-pipe'); | ||
|
||
var client = Pipe.createClient({ | ||
key: config.PUSHER_APP_KEY, | ||
secret: config.PUSHER_APP_SECRET, | ||
app_id: config.PUSHER_APP_ID, | ||
debug: true | ||
}); | ||
|
||
client.subscribe(['socket_message', 'socket_existence']); | ||
|
||
client.on('connected', function() { | ||
console.log('>>>>>>> connected event'); | ||
}); | ||
|
||
client.sockets.on('open', function(socketId) { | ||
console.log('>>>>>>> Connection by ' + socketId); | ||
}); | ||
|
||
client.connect(); | ||
|
||
client.sockets.on('event:eventFromBrowser', function(socket_id, data){ | ||
client.socket(socket_id).trigger('acknowledge', {message: 'back channel event'}); | ||
|
||
client.channel('my-channel').trigger('my_event', {message: 'standard channel event'}); | ||
}) |