Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disconnect with keepalive #12

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ An Elixir client for [Ogmios](https://github.com/CardanoSolutions/ogmios).

> Ogmios is a lightweight bridge interface for a Cardano node. It offers a WebSockets API that enables local clients to speak Ouroboros' mini-protocols via JSON/RPC. - https://ogmios.dev/

It currently only partially supports the **Chain Synchronization** and **State Query** mini-protocols. See [Examples](#examples) section below for information on how to use it.
Mini-Protocols supported by this library:

- [x] Chain Synchronization
- [ ] State Query (partially supported)
- [ ] Mempool Monitoring
- [ ] Tx Submission


See [Examples](#examples) section below for information on how to use.

## Installing

Expand Down
6 changes: 5 additions & 1 deletion lib/xogmios/chain_sync.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ defmodule Xogmios.ChainSync do
@callback handle_block(map(), any()) ::
{:ok, :next_block, map()} | {:ok, map()} | {:ok, :close, map()}

# The keepalive option is used to maintain the connection active.
# This is important because proxies might close idle connections after a few seconds.
@keepalive_in_ms 5_000

def start_link(client, opts) do
{url, opts} = Keyword.pop(opts, :url)
initial_state = Keyword.merge(opts, handler: client)
:websocket_client.start_link(url, client, initial_state)
:websocket_client.start_link(url, client, initial_state, keepalive: @keepalive_in_ms)
end

defmacro __using__(_opts) do
Expand Down
Loading