Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pusher real-time updates. #1

Merged
merged 2 commits into from Dec 9, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 18 additions & 1 deletion calendar.js
@@ -1,7 +1,10 @@
$(document).ready(function() {

// Mozilla demo server (flushed every day)
var server = "https://kinto.dev.mozaws.net/v1";

// Pusher app key
var pusher_key = "01a9feaaf9ebb120d1a6";

// Simplest credentials ever.
var authorization = "Basic " + btoa("public:notsecret");

Expand All @@ -11,6 +14,12 @@ $(document).ready(function() {
// Local store in IndexedDB.
var store = kinto.collection("kinto_demo_calendar");

// Live changes.
var pusher = new Pusher(pusher_key, {
encrypted: true
});


//
// Initialize fullCalendar
//
Expand Down Expand Up @@ -162,4 +171,12 @@ $(document).ready(function() {
throw err;
});
}

// This is the default bucket id for the ``public:notsecret`` user on kinto.dev
var channelName = '94b660c6-68f3-83c4-97fa-8e8ac4715204-kinto_demo_calendar-record';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum. I prefer this way actually : https://github.com/leplatrem/cliquet-pusher/blob/master/demo/map.js#L102-L115

If you don't (which I would understand since concise code is cool), then put it into a top variable, and use it to build the channel name. Same for collection id actually :)

var channel = pusher.subscribe(channelName);
channel.bind_all(function() {
syncServer();
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) that'd work indeed


});
1 change: 1 addition & 0 deletions index.html
Expand Up @@ -8,6 +8,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.2/moment.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.0/fullcalendar.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.0/fullcalendar.js"></script>
<script src="https://js.pusher.com/3.0/pusher.min.js"></script>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you can use //js.pusher.com instead ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work yes.

<link rel="stylesheet" href="style.css" />
</head>
<body>
Expand Down