{"id":17775019,"url":"https://github.com/dsrees/javaphoenixclient","last_synced_at":"2025-09-01T19:31:54.164Z","repository":{"id":33414407,"uuid":"140852184","full_name":"dsrees/JavaPhoenixClient","owner":"dsrees","description":"Phoenix client for the JVM built with Kotlin","archived":false,"fork":false,"pushed_at":"2024-06-25T12:49:22.000Z","size":743,"stargazers_count":64,"open_issues_count":5,"forks_count":34,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-12-22T06:07:46.232Z","etag":null,"topics":["android","kotlin-library","phoenix","phoenix-channels","phoenix-framework","websockets"],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dsrees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-13T13:46:11.000Z","updated_at":"2024-12-04T15:25:55.000Z","dependencies_parsed_at":"2023-11-24T17:26:26.315Z","dependency_job_id":"964141c0-2ef2-4046-8da7-9569ce871895","html_url":"https://github.com/dsrees/JavaPhoenixClient","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsrees%2FJavaPhoenixClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsrees%2FJavaPhoenixClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsrees%2FJavaPhoenixClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dsrees%2FJavaPhoenixClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dsrees","download_url":"https://codeload.github.com/dsrees/JavaPhoenixClient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231708694,"owners_count":18414531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["android","kotlin-library","phoenix","phoenix-channels","phoenix-framework","websockets"],"created_at":"2024-10-26T21:54:28.521Z","updated_at":"2024-12-29T07:10:01.723Z","avatar_url":"https://github.com/dsrees.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JavaPhoenixClient\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.github.dsrees/JavaPhoenixClient.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.github.dsrees%22%20AND%20a:%22JavaPhoenixClient%22)\n[![Build Status](https://travis-ci.com/dsrees/JavaPhoenixClient.svg?branch=master)](https://travis-ci.com/dsrees/JavaPhoenixClient)\n[![codecov](https://codecov.io/gh/dsrees/JavaPhoenixClient/branch/master/graph/badge.svg)](https://codecov.io/gh/dsrees/JavaPhoenixClient)\n\n\nJavaPhoenixClient is a Kotlin implementation of the [phoenix.js](https://hexdocs.pm/phoenix/js/) client used to manage Phoenix channels.\n\n\n### Basic Usage\n\n```kotlin\n\nfun connectToChatRoom() {\n\n    // Create the Socket\n    val params = hashMapOf(\"token\" to \"abc123\")\n    val socket = Socket(\"http://localhost:4000/socket/websocket\", params)\n\n    // Listen to events on the Socket\n    socket.logger = { Log.d(\"TAG\", it) }\n    socket.onOpen { Log.d(\"TAG\", \"Socket Opened\") }\n    socket.onClose { Log.d(\"TAG\", \"Socket Closed\") }\n    socket.onError { throwable, response -\u003e Log.d(throwable, \"TAG\", \"Socket Error ${response?.code}\") }\n\n    socket.connect()\n\n    // Join channels and listen to events\n    val chatroom = socket.channel(\"chatroom:general\")\n    chatroom.on(\"new_message\") { message -\u003e\n        val payload = message.payload\n        ...\n    }\n\n    chatroom.join()\n            .receive(\"ok\") { /* Joined the chatroom */ }\n            .receive(\"error\") { /* failed to join the chatroom */ }\n}\n```\n\n\nIf you need to provide dynamic parameters that can change between calls to `connect()`, then you can  pass a closure to the constructor\n\n```kotlin\n\n// Create the Socket\nvar authToken = \"abc\"\nval socket = Socket(\"http://localhost:4000/socket/websocket\", { mapOf(\"token\" to authToken) })\n\n// Connect with query parameters \"?token=abc\"\nsocket.connect()\n\n\n// later in time, connect with query parameters \"?token=xyz\"\nauthToken = \"xyz\"\nsocket.connect() // or internal reconnect logic kicks in\n```\n\n\nYou can also inject your own OkHttp Client into the Socket to provide your own configuration\n```kotlin\n// Configure your own OkHttp Client\nval client = OkHttpClient.Builder()\n    .connectTimeout(1000, TimeUnit.MILLISECONDS)\n    .build()\n\n// Create Socket with your custom instances\nval params = hashMapOf(\"token\" to \"abc123\")\nval socket = Socket(\"http://localhost:4000/socket/websocket\",\n    params,\n    client)\n```\n\nBy default, the client use GSON to encode and decode JSON. If you prefer to manage this yourself, you\ncan provide custom encode/decode functions in the `Socket` constructor.\n\n```kotlin\n\n// Configure your own GSON instance\nval gson = Gson.Builder().create()\nval encoder: EncodeClosure = {\n    // Encode a Map into JSON using your custom GSON instance or another JSON library\n    // of your choice (Moshi, etc)\n}\nval decoder: DecodeClosure = {\n    // Decode a JSON String into a `Message` object using your custom JSON library \n}\n\n// Create Socket with your custom instances\nval params = hashMapOf(\"token\" to \"abc123\")\nval socket = Socket(\"http://localhost:4000/socket/websocket\",\n    params,\n    encoder,\n    decoder)\n```\n\n\n\n\n\n### Installation\n\nJavaPhoenixClient is hosted on MavenCentral. You'll need to make sure you declare `mavenCentral()` as one of your repositories\n\n```\nrepositories {\n    mavenCentral()\n}\n```\n\nand then add the library. See [releases](https://github.com/dsrees/JavaPhoenixClient/releases) for the latest version\n```$xslt\ndependencies {\n    implementation 'com.github.dsrees:JavaPhoenixClient:1.3.1'\n}\n```\n\n\n### Feedback\nPlease submit in issue if you have any problems or questions! PRs are also welcome.\n\n\nThis library is built to mirror the [phoenix.js](https://hexdocs.pm/phoenix/js/) and [SwiftPhoenixClient](https://github.com/davidstump/SwiftPhoenixClient) libraries.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsrees%2Fjavaphoenixclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdsrees%2Fjavaphoenixclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdsrees%2Fjavaphoenixclient/lists"}