Coder Social home page Coder Social logo

poxa's Introduction

Poxa Build Status

Open Pusher implementation compatible with Pusher libraries. It's designed to be used as a single registered app with id, secret and key defined on start.

How do I speak 'poxa'?

['poʃa] - Phonetic notation

[posha] : po ( potion ), sha ( shall )

Table of Contents

Table of Contents generated with DocToc

Features

  • Public channels;
  • Private channels;
  • Presence channels;
  • Client events;
  • SSL on websocket and REST API;
  • Simple console;
  • REST API
    • /users on presence channels
    • /channels/:channel_name (Partial support)
    • /channels (Partial support)

TODO

  • SockJS support;
  • Complete REST api;
  • Mimic pusher error codes;
  • Integration test using pusher-js or other client library;
  • Web hooks;
  • Specify types signature to functions and use dialyzer to check them on Travis;
  • Add 'Vacated' and 'Occupied' events to Console.

Typical usage

Poxa is a standalone elixir server implementation of the Pusher protocol.

You need Elixir 0.12.4 at least and Erlang R16B.

Clone this repository

Run

mix deps.get
mix compile

The default configuration is:

  • Port: 8080
  • App id: 'app_id'
  • App key: 'app_key'
  • App secret: 'secret'

You can run and configure these values using this command:

elixir --erl "-poxa port 9090 -poxa app_id '<<"12345">>' -poxa app_key '<<"key-12345">>' -poxa app_secret '<<"secret6789">>'" -S mix run --no-halt

Or you can setup a configuration file like this:

test.config

[{poxa, [{port, 8080},
         {app_id, <<"12345">>},
         {app_key, <<"key-12345">>},
         {app_secret, <<"secret6789">>}]}].

And run:

elixir --erl "-config test" -S mix run --no-halt

And if you want SSL, try something like this on your configuration file:

[{poxa, [{port, 8080},
         {app_id, <<"app_id">>},
         {app_key, <<"app_key">>},
         {app_secret, <<"secret">>},
         {ssl, [{port, 8443},
                {cacertfile, "priv/ssl/server-ca.crt"},
                {certfile, "priv/ssl/server.crt"},
                {keyfile, "priv/ssl/server.key"}]}]}].

Release

If you just want to run a release, follow these instructions:

First download dependencies and generate the release (or download it here)

MIX_ENV=prod mix do deps.get, relex.assemble

Then you can run it using your own Erlang binaries:

erl -env ERL_LIBS ./poxa/lib -boot ./poxa/releases/0.0.X/poxa

Your application

If you are using the pusher-gem:

Pusher.host   = 'localhost'
Pusher.port   = 8080

And pusher-js:

Pusher.host    = 'localhost'
Pusher.ws_port = 8080

Deploying on Heroku

Add the file Procfile:

web: elixir --erl "-poxa port $PORT" -S mix run --no-halt

Add the file .preferred_otp_version

OTP_R16B

Configure the buildpack using:

heroku config:set BUILDPACK_URL=https://github.com/goshakkk/heroku-buildpack-elixir.git

And finally enable websocket on Heroku (for now it's on Heroku Labs)

heroku labs:enable websockets

And this is it!

A working deploy is on http://poxa.herokuapp.com, with:

  • App key: "app_key"
  • App id: "app_id"
  • App secret: "secret"
  • Port: 80

Also a pusher example(https://github.com/pusher/pusher-presence-demo) is running using poxa at: http://poxa-presence-chat.herokuapp.com/

Console

A simple console is avaiable on index:

Console

You can see it in action on http://poxa.herokuapp.com using "app_key" and "secret" to connect. Now open the poxa-presence-chat and watch events happening!

Implementation

Poxa uses gproc extensively to register websocket connections as channels. So, when a client subscribes for channel 'example-channel', the websocket connection (which is a elixir process) is "tagged" as {pusher, example-channel}. When a pusher event is triggered on the 'example-channel', every websocket matching the tag receives the event.

Contributing

If you'd like to hack on Poxa, start by forking my repo on Github.

Dependencies can be fetched running:

MIX_ENV=dev mix deps.get

Compile:

mix compile

The test suite used is the ExUnit and meck to mock stuff. First download test dependencies:

MIX_ENV=test mix deps.get

Now you can run the tests:

mix test

Pull requests are greatly appreciated.

Pusher

Pusher is an excellent service and you should use it on production.

poxa's People

Contributors

edgurgel avatar fernandodev avatar

Watchers

Jason Katzer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.