An open API service indexing awesome lists of open source software.

https://github.com/aguxez/connector

SignalR client written in Elixir. [Usable but still WIP]
https://github.com/aguxez/connector

elixir signalr

Last synced: about 1 month ago
JSON representation

SignalR client written in Elixir. [Usable but still WIP]

Awesome Lists containing this project

README

          

# Connector - SignalR client for Elixir.

## Installation

Not available in Hex, use Github's.

```elixir
def deps do
[
{:connector, github: "aguxez/connector"}
]
end
```

## Usage
The process is pretty straight forward, you'll want to create a `start_link` function for your module and add it to your Supervision tree. `Connector.Interface.start_link/1` expects a map as the argument, it has required keys, example:

```elixir
# Let's suppose you're going to connect to Bittrex websocket API.
state = %{
base_url: "https://socket.bittrex.com/signalr",
ws_url: "wss://socket.bittrex.com/signalr",
transport: "webSockets",
negotiate_query: %{
connection_data: [%{name: "c2"}]
},
connect_query: %{
connection_data: [%{name: "c2"}]
},
start_query: %{
connection_data: [%{name: "c2"}]
},
mod: MyApp.Module
}
```
"webSockets" is the only transport supported for now.

`:mod` is the module that will implement the `handle_message/2` callback. In this case `MyApp.Module.handle_message(frame, text)` will be the the module handling data incoming from the websocket.

### Example
```elixir
defmodule MyApp.Module do
@moduledoc false

use Connector

def start_link do
# Bittrex websocket args
state = %{
base_url: "https://socket.bittrex.com/signalr",
ws_url: "wss://socket.bittrex.com/signalr",
transport: "webSockets",
negotiate_query: %{
connection_data: [%{name: "c2"}]
},
connect_query: %{
connection_data: [%{name: "c2"}]
},
start_query: %{
connection_data: [%{name: "c2"}]
},
mod: MyApp.Module
}

Connector.Interface.start_link(state)
end

def handle_message({:text, msg}, state) do
msg
|> Jason.decode!()
|> IO.inspect()

{:ok, state}
end
end
```

`handle_message/2` should return `{:ok, state}`