Giter Club home page Giter Club logo

philae's Introduction

Philae

Land a Elixir app onto a MeteorJs App

Connect to a Meteor app and subscribe to collections

There is still some wierdness in the DDP module w/ the Client API but for now you can implement a simple client like so

defmodule PlayerVoter do
  use GenServer

  def start_link do
    GenServer.start_link(__MODULE__, [], [])
  end

  def init([]) do
    {:ok, client_pid } = Philae.DDP.connect("ws://localhost:3000/websocket", __MODULE__, self)
    {collection, id} = Philae.DDP.subscribe(client_pid, "players")
    {:ok, %{client_pid: client_pid, subscription_id: id, collection: collection}}
  end

  def added(pid, message) do
    GenServer.call(pid, {:added, message})
  end

  def handle_call({:added, message}, _from, state) do
    IO.puts "We got here and got"
    IO.inspect message
    {:reply, :ok, state}
  end
end

An Example of calling PlayerVoter from IEx

iex(1)> PlayerVoter.start_link
In: {"server_id":"0"}
I dont know what to with
%{"server_id" => "0"}
Out: {"version":"1","support":["1","pre2","pre1"],"msg":"connect"}
In: {"msg":"connected","session":"5StuZbjGzfaQ8wADT"}
I dont know what to with
%{"msg" => "connected", "session" => "5StuZbjGzfaQ8wADT"}
{:ok, #PID<0.169.0>}
Out: {"name":"players","msg":"sub","id":"17703351-03a6-4e0b-ae03-509ce5ede83f"}
In: {"msg":"added","collection":"players","id":"EDwgtEt6weAn7hXXa","fields":{"name":"Ada Lovelace","score":55}}
We got here and got
%{"collection" => "players",
  "fields" => %{"name" => "Ada Lovelace", "score" => 55},
  "id" => "EDwgtEt6weAn7hXXa", "msg" => "added"}
In: {"msg":"added","collection":"players","id":"4J7BzXDpupHHFyhC8","fields":{"name":"Grace Hopper","score":75}}
We got here and got
%{"collection" => "players",
  "fields" => %{"name" => "Grace Hopper", "score" => 75},
  "id" => "4J7BzXDpupHHFyhC8", "msg" => "added"}
In: {"msg":"added","collection":"players","id":"jbeTgrLuctE5tFjKd","fields":{"name":"Marie Curie","score":40}}
We got here and got
%{"collection" => "players",
  "fields" => %{"name" => "Marie Curie", "score" => 40},
  "id" => "jbeTgrLuctE5tFjKd", "msg" => "added"}
In: {"msg":"added","collection":"players","id":"S8kC3ze7T8DpxLdM3","fields":{"name":"Carl Friedrich Gauss","score":60}}
We got here and got
%{"collection" => "players",
  "fields" => %{"name" => "Carl Friedrich Gauss", "score" => 60},
  "id" => "S8kC3ze7T8DpxLdM3", "msg" => "added"}
In: {"msg":"added","collection":"players","id":"AC96Gf6YhaWt74dTR","fields":{"name":"Nikola Tesla","score":65}}
We got here and got
%{"collection" => "players",
  "fields" => %{"name" => "Nikola Tesla", "score" => 65},
  "id" => "AC96Gf6YhaWt74dTR", "msg" => "added"}
In: {"msg":"added","collection":"players","id":"Ya2LCwnNyFxWraDfD","fields":{"name":"Claude Shannon","score":25}}
We got here and got
%{"collection" => "players",
  "fields" => %{"name" => "Claude Shannon", "score" => 25},
  "id" => "Ya2LCwnNyFxWraDfD", "msg" => "added"}
In: {"msg":"ready","subs":["17703351-03a6-4e0b-ae03-509ce5ede83f"]}
I dont know what to with
%{"msg" => "ready", "subs" => ["17703351-03a6-4e0b-ae03-509ce5ede83f"]}
In: {"msg":"ping"}
Out: {"msg":"pong"}
iex(2)>

TODO

  • Subscribe to collections
  • Respond appropriately to Ping and Pong heartbeats
  • Call callback functions on module passed in for incoming messages
  • Send RPC messages via "method" message
  • Implement default behavior for Handler Module callbacks
  • Make logging optional for DDPHandler behavior
  • Implement unsub message
  • Implement Agent for keeping track of subscriptions
  • Add inline @doc documentation
  • Write some tests!!!

philae's People

Contributors

st23am avatar

Stargazers

 avatar Wasif Hasan Baig avatar Sunny Gonnabathula avatar Fernando Mumbach avatar Grégory Horion avatar Ludovic Le Roy avatar Elie Steinbock avatar Marek Suscak avatar Lei Yang avatar Francisco Gutierrez avatar  avatar  avatar Christopher Galtenberg avatar Valentin Vichnal avatar Potter Dai avatar Ben Peachey avatar Thomas avatar Henry S avatar Alan deLevie avatar  avatar Eksperimental avatar Miguel avatar

Watchers

 avatar James Cloos avatar Tim Mecklem avatar Ludovic Le Roy avatar

philae's Issues

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.