Skip to content

Instantly share code, notes, and snippets.

@stephenlb
Forked from ToeJamson/1.js
Created October 29, 2013 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenlb/7220068 to your computer and use it in GitHub Desktop.
Save stephenlb/7220068 to your computer and use it in GitHub Desktop.
<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>
//
// User is Ready to Receive Desktop Notifications?
//
var allowed_desktop_notifications = PUBNUB.notify.ready();
//
// 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.
}
});
//
// Send Notification
//
PUBNUB.notify({
image : 'http://cdn.pubnub.com/assets/pubnub-70x70.png',
title : 'PubNub Notification',
body : PUBNUB.$('broadcast-text').value || "empty message"
});
//
// 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'
)
));
//
// 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"
}
})
//
// 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"
}
})
//
// 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'
}
})
<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