Signalr implementation for Elixir
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
lib
test
.gitignore
LICENSE
README.md
mix.exs
mix.lock

README.md

Signalrex

Signalrex is a library writen in Elixir which will help you to interact with servers which implements SignalR. You can find more information in their web.

Signalrex only supports WebSockets as transport protocol using Enchufeweb.

Installation

If available in Hex, the package can be installed by adding signalrex to your list of dependencies in mix.exs:

def deps do
  [
    {:signalrex, "~> 0.1.0"}
  ]
end

Implementation

Define your Module, use Signalrex and implement the functions get_initial_message/0 (The first message that will be sent to the server) and process_message/2 (The function that will be called when a message arrived from the server)

defmodule Test do
  use Signalrex

  def get_initial_message() do
    %{"S" => 0, "M" => [], "C" => ""}
  end

  def process_message(data, state) do
    IO.inspect data
    {:ok, state}
  end
end

Start

Signalrex needs some mandatory arguments to work:

  • url: A string with the signalR server url.
  • negotiate_headers: A map with the additional headers of the negotiate request (it could be empty).
  • negotiate_query_params: A keyword list with the additional parameters of the negotiate request (it could be empty).
  • ws_opts: A map with the options for the websocket.
  • connect_query_params: A keyword list with the additional parameters of the websocket connection request.
  • base_ws_url: A string with the websocket server url.
  • start_headers: A map with the additional headers of the start request (it could be empty).
  • start_query_params: A keyword list with the additional parameters of the start request (it could be empty).

Example

args = %{
  url: "http://9.5.6.7:5555/signalr",
  negotiate_headers: %{},
  negotiate_query_params: ["my_auth": "asdfasdf", "connectionData": "[{\"id\":\"my_data\"}]"],
  ws_opts: %{conn_mode: :once},
  connect_query_params: ["my_auth": "asdfasdf", "connectionData": "[{\"id\":\"my_data\"}]"],
  base_ws_url: "ws://9.5.6.7:5555/signalr",
  start_headers: %{},
  start_query_params: ["my_auth": "asdfasdf", "connectionData": "[{\"id\":\"my_data\"}]"]
  }

After having your arguments, you only have to start your process:

{:ok, signalrex} = Test.start_link(args, [])

Sending data

Test.send(_your_signalrex_process_, _your_message_)

Docs

$ mix docs

Tests

Looking for a public SignalR server in order to publish test against it.