Skip to content

Replacement for the now deprecated Google App Engine channels API. Uses Google Firebase to easily pass messages from a Python task queue to the frontend. One of very few public-facing repos.

License

LeadPages/firechannel

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

firechannel

An almost-dropin replacement for the GAE channels API using Firebase.

Usage

Setup

  1. pip install firechannel
  2. Include the firebase web init snippet in your app
  3. Include static/firechannel.js in your app

On the frontend

Given an implementation like

var channel = new goog.appengine.Channel("{{token}}");
var socket = channel.open();

socket.onmessage = function(data) { console.log(data); };

change the first line to

var channel = new Firechannel("{{token}}");

On the backend

Change your imports from

from google.appengine.api.channel import create_channel, send_message

to

from firechannel import create_channel, send_message

Inside Firebase

Add the following rule using your Firebase console:

{
  "rules": {
    ".read": false,
    ".write": false,
    "firechannels": {
      "$channelId": {
        ".read": "auth.uid == $channelId",
        ".write": false
      }
    }
  }
}

And that's about it.

Cleaning up old channels

You can call delete_channel after you're done sending messages on it. This will remove it from Firebase immediately.

If that's not feasible, you can set up an hourly (or daily) cron job and delete all channels that have last received a message some amount of time ago like this:

from firechannel import find_all_expired_channels, delete_channel

# All channels that have last received a message over a day ago
expired_channels = find_all_expired_channels(max_age=86400)
for channel_id in expired_channels:
  delete_channel(channel_id)

Testing

To run the tests, create a service account and point an env var called GOOGLE_APPLICATION_CREDENTIALS to it and another one called FIREBASE_PROJECT to the name of your project. Finally, run py.test.

GAE tests

To run the AppEngine tests, point an env var called APPENGINE_SDK_PATH to the base path of your GAE SDK and run py.test tests_appengine.

Authors

firechannel was authored at Leadpages. You can find out more about contributors here. We welcome contributions, and we're always looking for more engineering talent!

Contributing

Please read our contributor's guide.

About

Replacement for the now deprecated Google App Engine channels API. Uses Google Firebase to easily pass messages from a Python task queue to the frontend. One of very few public-facing repos.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published