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]
- Host: GitHub
- URL: https://github.com/aguxez/connector
- Owner: aguxez
- Created: 2018-04-27T03:10:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-24T18:48:44.000Z (almost 8 years ago)
- Last Synced: 2025-01-26T17:37:16.314Z (over 1 year ago)
- Topics: elixir, signalr
- Language: Elixir
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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}`