-
-
Save stephenlb/7220068 to your computer and use it in GitHub Desktop.
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
<div | |
channel-name=notifications-channel | |
segregate-notifications-by-page=false | |
id=desktop-notifications-config | |
></div> | |
<div id=pubnub pub-key=demo sub-key=demo></div> | |
<script src=http://http://cdn.pubnub.com/pubnub-3.5.4.min.js></script> | |
<script | |
src=http://www.pubnub.com/static/html5-desktop-notification-broadcasting.js | |
></script> |
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
// | |
// User is Ready to Receive Desktop Notifications? | |
// | |
var allowed_desktop_notifications = PUBNUB.notify.ready(); |
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
// | |
// Request Permissions to Receive Desktop Notifications | |
// | |
PUBNUB.notify.enable(function(){ | |
if (PUBNUB.notify.ready) { | |
// User Accepted Permission | |
// Ready to receive Desktop Notifications! | |
} | |
else { | |
// User Denied Permission | |
// User will not receive notifications. | |
} | |
}); |
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
// | |
// Send Notification | |
// | |
PUBNUB.notify({ | |
image : 'http://cdn.pubnub.com/assets/pubnub-70x70.png', | |
title : 'PubNub Notification', | |
body : PUBNUB.$('broadcast-text').value || "empty message" | |
}); |
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
// | |
// Send Desktop Notifications using PHP | |
// | |
require_once('Pubnub.php'); | |
$pubnub = new Pubnub( $publish_key, $subscribe_key ); | |
$info = $pubnub->publish(array( | |
'channel' => 'notifications-channel', | |
'message' => array( | |
image => 'image.jpg', | |
title => 'Title Text', | |
body => 'Content Body Text' | |
) | |
)); |
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
// | |
// Send Desktop Notifications using Python | |
// | |
from pubnub import Pubnub | |
pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) | |
pubish_success = pubnub.publish({ | |
'channel' : 'notifications-channel', | |
'message' : { | |
'image' : "image.jpg", | |
'title' : "Title Text", | |
'body' : "Content Body Text" | |
} | |
}) |
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
// | |
// Send Desktop Notifications using Python | |
// | |
from pubnub import Pubnub | |
pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) | |
pubish_success = pubnub.publish({ | |
'channel' : 'notifications-channel', | |
'message' : { | |
'image' : "image.jpg", | |
'title' : "Title Text", | |
'body' : "Content Body Text" | |
} | |
}) |
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
// | |
// Send Desktop Notifications using Ruby | |
// | |
require 'Pubnub' | |
pubnub = Pubnub.new( publish_key, subscribe_key, secret_key, ssl_on ) | |
info = pubnub.publish({ | |
'channel' => 'notifications-channel', | |
'message' => { | |
image => 'image.jpg', | |
title => 'Title Text', | |
body => 'Content Body Text' | |
} | |
}) |
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
<p> | |
<button id=broadcast-enable class=broadcast-button> | |
Enable Desktop Notifications | |
</button> | |
<span id=broadcast-ready>Loading...</span> | |
</p><p> | |
<button id=broadcast-button class=broadcast-button> | |
Broadcast HTML5 Desktop Notification | |
</button> | |
<input id=broadcast-text value='Hello Everyone!' /> | |
</p> | |
<div | |
channel-name=notifications-channel | |
segregate-notifications-by-page=false | |
id=desktop-notifications-config | |
></div> | |
<div id=pubnub pub-key=demo sub-key=demo></div> | |
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script> | |
<script | |
src=http://www.pubnub.com/static/html5-desktop-notification-broadcasting.js | |
></script> | |
<script>(function(){ | |
function update_ready(enabled) { | |
var ready = PUBNUB.$('broadcast-ready'); | |
if (enabled) { | |
ready.innerHTML = 'Enabled'; | |
PUBNUB.attr( ready, 'class', 'broadcast-enabled' ); | |
} | |
else { | |
ready.innerHTML = 'Disabled'; | |
PUBNUB.attr( ready, 'class', 'broadcast-disabled' ); | |
} | |
} | |
update_ready(PUBNUB.notify.ready()); | |
PUBNUB.bind( | |
'mousedown,touchstart', | |
PUBNUB.$('broadcast-button'), | |
function() { | |
return PUBNUB.notify({ | |
image : 'http://cdn.pubnub.com/assets/pubnub-70x70.png', | |
title : 'PubNub Notification', | |
body : PUBNUB.$('broadcast-text').value || "empty message" | |
}); | |
} | |
); | |
PUBNUB.bind( | |
'mousedown,touchstart', | |
PUBNUB.$('broadcast-enable'), | |
function() { | |
PUBNUB.notify.enable(function(){ | |
update_ready(PUBNUB.notify.ready()); | |
}); | |
} | |
); | |
})();</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment