{"id":14955599,"url":"https://github.com/hosopy/actioncable-client-kotlin","last_synced_at":"2025-10-25T09:10:31.403Z","repository":{"id":137921670,"uuid":"103382377","full_name":"hosopy/actioncable-client-kotlin","owner":"hosopy","description":"Actioncable client library for Kotlin","archived":false,"fork":false,"pushed_at":"2019-09-26T14:46:03.000Z","size":70,"stargazers_count":13,"open_issues_count":6,"forks_count":12,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-05T03:41:26.584Z","etag":null,"topics":["actioncable","kotlin","rails5"],"latest_commit_sha":null,"homepage":"","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/hosopy.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-09-13T09:47:00.000Z","updated_at":"2022-01-03T15:23:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"8af4357c-8068-4e07-813a-fe0733d460e1","html_url":"https://github.com/hosopy/actioncable-client-kotlin","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/hosopy/actioncable-client-kotlin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-kotlin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-kotlin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-kotlin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-kotlin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hosopy","download_url":"https://codeload.github.com/hosopy/actioncable-client-kotlin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-kotlin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270796220,"owners_count":24647319,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["actioncable","kotlin","rails5"],"created_at":"2024-09-24T13:11:25.894Z","updated_at":"2025-10-25T09:10:31.328Z","avatar_url":"https://github.com/hosopy.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# actioncable-client-kotlin\n\n[![Build Status](https://travis-ci.org/hosopy/actioncable-client-kotlin.svg?branch=master)](https://travis-ci.org/hosopy/actioncable-client-kotlin)\n[![Release](https://jitpack.io/v/hosopy/actioncable-client-kotlin.svg)](https://jitpack.io/#hosopy/actioncable-client-kotlin)\n\nThis is the actioncable client library for Kotlin.\nPlease see [Action Cable Overview](http://guides.rubyonrails.org/action_cable_overview.html) to understand actioncable itself.\n\n# Usage\n\n## Requirements\n\n* Kotlin 1.1.4-3 or later\n* [kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines) (experimental in Kotlin 1.1)\n\n## Gradle\n\n```groovy\nrepositories {\n    jcenter()\n    maven { url \"https://jitpack.io\" }\n}\n\ndependencies {\n    compile 'com.github.hosopy:actioncable-client-kotlin:0.0.3'\n}\n```\n\n## Basic\n\n```kotlin\n// 1. Setup\nval uri = URI(\"ws://cable.example.com\")\nval consumer = ActionCable.createConsumer(uri)\n\n// 2. Create subscription\nval appearanceChannel = Channel(\"AppearanceChannel\")\nval subscription = consumer.subscriptions.create(appearanceChannel)\n\nsubscription.onConnected = {\n    // Called when the subscription has been successfully completed\n}\n\nsubscription.onRejected = {\n    // Called when the subscription is rejected by the server\n}\n\nsubscription.onReceived = { data: Any? -\u003e\n    // Called when the subscription receives data from the server\n    // Possible types...\n    when (data) {\n        is Int -\u003e { }\n        is Long -\u003e { }\n        is BigInteger -\u003e { }\n        is String -\u003e { }\n        is Double -\u003e { }\n        is Boolean -\u003e { }\n        is JsonObject -\u003e { }\n        is JsonArray\u003c*\u003e -\u003e { }\n    }\n}\n\nsubscription.onDisconnected = {\n    // Called when the subscription has been closed\n}\n\nsubscription.onFailed = { error -\u003e\n    // Called when the subscription encounters any error\n}\n\n// 3. Establish connection\nconsumer.connect()\n\n// 4. Perform any action\nsubscription.perform(\"away\")\n\n// 5. Perform any action with params\nsubscription.perform(\"hello\", mapOf(\"name\" to \"world\"))\n```\n\n## Passing Parameters to Channel\n\n```kotlin\nval chatChannel = Channel(\"ChatChannel\", mapOf(\"room_id\" to 1))\n```\n\nThe parameter container is `Map\u003cString, Any?\u003e` and is converted to `JsonObject(Klaxon)` internally.\nTo know what type of value can be passed, please read [Klaxon user guide](https://github.com/cbeust/klaxon).\n\n## Passing Parameters to Subscription#perform\n\n```kotlin\nsubscription.perform(\"send\", mapOf(\n    \"comment\" to mapOf(\n        \"text\" to \"This is string.\",\n        \"private\" to true,\n        \"images\" to arrayOf(\n            \"http://example.com/image1.jpg\",\n            \"http://example.com/image2.jpg\"\n        )\n    )\n))\n```\n\nThe parameter container is `Map\u003cString, Any?\u003e` and is converted to `JsonObject(Klaxon)` internally.\nTo know what type of value can be passed, please read [Klaxon user guide](https://github.com/cbeust/klaxon).\n\n## Options\n\n```kotlin\nval uri = URI(\"ws://cable.example.com\")\nval options = Consumer.Options()\noptions.connection.reconnection = true\n\nval consumer = ActionCable.createConsumer(uri, options)\n```\n\nBelow is a list of available options.\n\n* sslContext\n    \n    ```kotlin\n    options.connection.sslContext = yourSSLContextInstance\n    ```\n    \n* hostnameVerifier\n    \n    ```kotlin\n    options.connection.hostnameVerifier = yourHostnameVerifier\n    ```\n    \n* cookieHandler\n    \n    ```kotlin\n    options.connection.cookieHandler = yourCookieManagerInstance\n    ```\n    \n* query\n    \n    ```kotlin\n    options.connection.query = mapOf(\"user_id\" to \"1\")\n    ```\n    \n* headers\n    \n    ```kotlin\n    options.connection.headers = mapOf(\"X-Foo\" to \"Bar\")\n    ```\n    \n* reconnection\n    * If reconnection is true, the client attempts to reconnect to the server when underlying connection is stale.\n    * Default is `false`.\n    \n    ```kotlin\n    options.connection.reconnection = false\n    ```\n    \n* reconnectionMaxAttempts\n    * The maximum number of attempts to reconnect.\n    * Default is `30`.\n    \n    ```kotlin\n    options.connection.reconnectionMaxAttempts = 30\n    ```\n\n* okHttpClientFactory\n    * Factory instance to create your own OkHttpClient.\n    * If `okHttpClientFactory` is not set, just create OkHttpClient by `OkHttpClient()`.\n    \n    ```kotlin\n    options.connection.okHttpClientFactory = {\n        OkHttpClient().also {\n            it.networkInterceptors().add(StethoInterceptor())\n        }\n    }\n    ```\n\n## Authentication\n\nHow to authenticate a request depends on the architecture you choose.\n\n### Authenticate by HTTP Header\n\n```kotlin\nval options = Consumer.Options()\noptions.connection.headers = mapOf(\"Authorization\" to \"Bearer xxxxxxxxxxx\")\n\nval consumer = ActionCable.createConsumer(uri, options)\n```\n\n### Authenticate by Query Params\n\n```kotlin\nval options = Consumer.Options()\noptions.connection.query = mapOf(\"access_token\" to \"xxxxxxxxxxx\")\n\nval consumer = ActionCable.createConsumer(uri, options)\n```\n\n### Authenticate by Cookie\n\n```kotlin\nval cookieManager = CookieManager()\n// Some setup\n...\noptions.connection.cookieHandler = cookieManager\n\nval consumer = ActionCable.createConsumer(uri, options)\n```\n\n# License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosopy%2Factioncable-client-kotlin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhosopy%2Factioncable-client-kotlin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosopy%2Factioncable-client-kotlin/lists"}