UNPKG

facebook-conduit

Version:

A simple subscriber end-point for Facebook's Real-time Updates

37 lines (24 loc) 2.82 kB
/* (The MIT License) Copyright (c) 2011 Nolan Caudill Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* Conduit simply receives events on a particular callback and then republishes these events through an emitter. That's it. This stuff is already opinionated in things that don't matter too much. It's trivial to modify any consumers of this code to fix the decisions I've made. The first version of this software let you verify your own verify_tokens for both 'unsubscribe' and 'subscribe' separtely. I went ahead and decided to do this verification via HMAC with the callback URL and a secret you pass into Conduit. Then I had an fairly inflexible way to map figure out "event names" from the incoming callback. This violated a separation-of-concerns by making the callback URL map *directly* to what the event was, as it was just a base64-encoded, dash-separated represenation of the subscription info. This fit my app fine, but probably wasn't clear for everyone else. Also, when Neil added parameterized topics (e.g., geo, tags, etc), this proved my naive implemenation as hard-to-adapt. I've changed this by every callback URL be just a ID with no intrinsic importance and force the application that initiates subscriptions, to figure out what this means. Conduit doesn't need to know what this is -- it's just a conduit that just knows that the callback URL has a query parameter called 'sub' that it will publish a parsed Flickr push event to its emitter. Also, an oversight in the first version was Conduit automatically refreshing subscriptions even if the person hadn't logged in some time. If I haven't received a heartbeat for a user in 10 minutes and I get a subscription request for them, I don't refresh the subscription and unset the time last seen. */