{"id":32173169,"url":"https://github.com/treebee/realtime-client-elixir","last_synced_at":"2026-02-23T05:01:43.679Z","repository":{"id":57541098,"uuid":"378944695","full_name":"treebee/realtime-client-elixir","owner":"treebee","description":"An Elixir client for the Realtime (https://github.com/supabase/realtime) Server","archived":false,"fork":false,"pushed_at":"2021-09-10T07:56:15.000Z","size":21,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-10-21T18:51:28.332Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/treebee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-21T13:44:29.000Z","updated_at":"2024-02-07T22:27:54.000Z","dependencies_parsed_at":"2022-09-17T23:00:57.301Z","dependency_job_id":null,"html_url":"https://github.com/treebee/realtime-client-elixir","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/treebee/realtime-client-elixir","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treebee%2Frealtime-client-elixir","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treebee%2Frealtime-client-elixir/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treebee%2Frealtime-client-elixir/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treebee%2Frealtime-client-elixir/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treebee","download_url":"https://codeload.github.com/treebee/realtime-client-elixir/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treebee%2Frealtime-client-elixir/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29738083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-23T04:51:08.365Z","status":"ssl_error","status_checked_at":"2026-02-23T04:49:15.865Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-21T18:50:16.055Z","updated_at":"2026-02-23T05:01:43.667Z","avatar_url":"https://github.com/treebee.png","language":"Elixir","readme":"[![.github/workflows/ci.yml](https://github.com/treebee/realtime-client-elixir/actions/workflows/ci.yml/badge.svg)](https://github.com/treebee/realtime-client-elixir/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/treebee/realtime-client-elixir/badge.svg?branch=main)](https://coveralls.io/github/treebee/realtime-client-elixir?branch=main)\n\n# RealtimeClient\n\nClient for connecting to [realtime](https://github.com/supabase/realtime).\nIt's mostly a wrapper around [phoenix_client](https://github.com/mobileoverlord/phoenix_client).\n\n## Installation\n\nIf [available in Hex](https://hex.pm/docs/publish), the package can be installed\nby adding `realtime_client` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:realtime_client, \"~\u003e 0.1.0\"}\n  ]\nend\n```\n\n## Getting Started\n\nFirst you have to create a client Socket:\n\n```elixir\noptions = [\n  url: \"ws://realtime-server:4000/socket/websocket\",\n]\n{:ok, socket} = RealtimeClient.socket(options)\n```\n\nOnce you have a connected socket, you can subscribe to topics:\n\n```elixir\n{:ok, channel} = RealtimeClient.subscribe(socket, \"realtime:*\")\n```\n\nYou can also subscribe to a specific channel (row level changes):\n\n```elixir\n{:ok, channel} = RealtimeClient.subscribe(socket, \"realtime:public:users:id=eq.42\")\n```\n\nConsuming events is done with `handle_info` callbacks:\n\n```elixir\nalias PhoenixClient.Message\n\n# handle `INSERT` events\ndef handle_info(%Message{event: \"INSERT\", payload: %{\"record\" =\u003e record}} = msg, state) do\n    # do something with record\n    {:noreply, state}\nend\n\n# handle `DELETE` events\ndef handle_info(%Message{event: \"DELETE\", payload: %{\"record\" =\u003e record}} = msg, state) do\n    IO.inspect(record, label: \"DELETE\")\n    {:noreply, state}\nend\n\n# match all cases not handled above\ndef handle_info(%Message{} = msg, state) do\n    {:noreply, state}\nend\n```\n\n## Configuration\n\n```elixir\nconfig :realtime_client,\n  endpoint: \"ws://localhost:4000/socket/websocket\"\n  apikey: \"some-JWT\" # when using secure channels\n```\n\n## Using a single Socket\n\nIf you don't need to create multiple client Sockets (e.g. one per user session) but only need one for your application, you can also\nstart one as part of your supervision tree:\n\n```elixir\n  # application.ex\n  ...\n\n  def start(_type, _args) do\n    children = [\n      RealtimeAppWeb.Telemetry,\n      {Phoenix.PubSub, name: RealtimeApp.PubSub},\n      RealtimeAppWeb.Endpoint,\n\n      # Add RealtimeClient to start the client Socket\n      RealtimeClient,\n      {RealtimeApp.Worker, \"realtime:*\"} # Example worker, see below\n    ]\n\n    opts = [strategy: :one_for_one, name: RealtimeApp.Supervisor]\n    Supervisor.start_link(children, opts)\n  end\n```\n\n### Example Worker\n\n```elixir\ndefmodule RealtimeApp.Worker do\n  use GenServer\n\n  alias PhoenixClient.Message\n\n  def init(topic) do\n    subscribe(topic)\n    {:ok, %{}}\n  end\n\n  def start_link(topic) do\n    GenServer.start_link(__MODULE__, topic)\n  end\n\n  def subscribe(topic) do\n    send(self(), {:subscribe, topic})\n  end\n\n  def handle_info({:subscribe, topic}, state) do\n    case RealtimeClient.subscribe(topic) do\n      {:error, _error} -\u003e\n        Process.send_after(self(), {:subscribe, topic}, 300)\n        {:noreply, state}\n\n      {:ok, channel} -\u003e\n        {:noreply, Map.put(state, :channel, channel)}\n    end\n  end\n\n  def handle_info(%Message{event: \"INSERT\", payload: %{\"record\" =\u003e record}}, state) do\n    IO.inspect(record, label: \"record\")\n    {:noreply, state}\n  end\nend\n\n```\n\n## Running Tests\n\nThere's a docker compose setup in `./docker` that can be used for development and\ntesting.\n\n```bash\nmake start \u0026\u0026 sleep 5\nmake test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreebee%2Frealtime-client-elixir","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreebee%2Frealtime-client-elixir","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreebee%2Frealtime-client-elixir/lists"}